-
Notifications
You must be signed in to change notification settings - Fork 0
/
output.txt
46 lines (29 loc) · 1.38 KB
/
output.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
4-3 ACCESSING AND MANIPULATING PIXELS
On Line 14 we manipulate the top-left pixel in the im-
age, which is located at coordinate (0,0) and set it to have
a value of (0, 0, 255). If we were reading this pixel value
in RGB format, we would have a value of 0 for red, 0 for
green, and 255 for blue, thus making it a pure blue color.
However, as I mentioned above, we need to take special
care when working with OpenCV. Our pixels are actually
stored in BGR format, not RGB format.
We actually read this pixel as 255 for red, 0 for green, and
0 for blue, making it a red color, 7of a blue color.
After setting the top-left pixel to have a red color on Line
44, we then grab the pixel value and print it back to con-
sole on Lines 15 and 16, just to demonstrate that we have
indeed successfully changed the color of the pixel.
Accessing and setting a single pixel value is simple enough,
but what if we wanted to use NumPy’s array slicing capa-
bilities to access larger rectangular portions of the image?
‘The code below demonstrates how we can do this:
Se
a7 corner = image[o:100, 0:1001
18 cv2.imshou("Gorner", corner)
20 image[0:400, 0:100] = (o, 258, 0>
22 cv2.imeshow( Updated”, image)
23 ¢v2.waitKey (o>
On line 17 we grab a 100 x 100 pixel region of the image.
In fact, this is the top-left corner of the image! In order to
grab chunks of an image, NumPy expects we provide four
22