@@ -50,9 +50,9 @@ You can modify the pixel values the same way.
50
50
Numpy is a optimized library for fast array calculations. So simply accessing each and every pixel
51
51
values and modifying it will be very slow and it is discouraged.
52
52
53
- @note Above mentioned method is normally used for selecting a region of array, say first 5 rows and
54
- last 3 columns like that . For individual pixel access, Numpy array methods, array.item() and
55
- array.itemset() is considered to be better. But it always returns a scalar. So if you want to access
53
+ @note The above method is normally used for selecting a region of an array, say the first 5 rows
54
+ and last 3 columns. For individual pixel access, the Numpy array methods, array.item() and
55
+ array.itemset() are considered better, however they always return a scalar. If you want to access
56
56
all B,G,R values, you need to call array.item() separately for all.
57
57
58
58
Better pixel accessing and editing method :
@@ -73,15 +73,15 @@ Accessing Image Properties
73
73
Image properties include number of rows, columns and channels, type of image data, number of pixels
74
74
etc.
75
75
76
- Shape of image is accessed by img.shape. It returns a tuple of number of rows, columns and channels
76
+ The shape of an image is accessed by img.shape. It returns a tuple of number of rows, columns, and channels
77
77
(if image is color):
78
78
@code {.py}
79
79
>>> print( img.shape )
80
80
(342, 548, 3)
81
81
@endcode
82
82
83
- @note If image is grayscale, tuple returned contains only number of rows and columns. So it is a
84
- good method to check if loaded image is grayscale or color image .
83
+ @note If an image is grayscale, the tuple returned contains only the number of rows
84
+ and columns, so it is a good method to check whether the loaded image is grayscale or color.
85
85
86
86
Total number of pixels is accessed by ` img.size ` :
87
87
@code {.py}
@@ -101,9 +101,9 @@ Image ROI
101
101
---------
102
102
103
103
Sometimes, you will have to play with certain region of images. For eye detection in images, first
104
- face detection is done all over the image and when face is obtained, we select the face region alone
105
- and search for eyes inside it instead of searching whole image. It improves accuracy (because eyes
106
- are always on faces : D ) and performance (because we search for a small area)
104
+ face detection is done all over the image. When a face is obtained, we select the face region alone
105
+ and search for eyes inside it instead of searching the whole image. It improves accuracy (because eyes
106
+ are always on faces : D ) and performance (because we search in a small area).
107
107
108
108
ROI is again obtained using Numpy indexing. Here I am selecting the ball and copying it to another
109
109
region in the image:
@@ -118,9 +118,9 @@ Check the results below:
118
118
Splitting and Merging Image Channels
119
119
------------------------------------
120
120
121
- Sometimes you will need to work separately on B,G,R channels of image. Then you need to split the
122
- BGR images to single planes. Or another time , you may need to join these individual channels to BGR
123
- image. You can do it simply by:
121
+ Sometimes you will need to work separately on B,G,R channels of image. In this case, you need
122
+ to split the BGR images to single channels. In other cases , you may need to join these individual
123
+ channels to a BGR image. You can do it simply by:
124
124
@code {.py}
125
125
>>> b,g,r = cv2.split(img)
126
126
>>> img = cv2.merge((b,g,r))
129
129
@code
130
130
>>> b = img[ :,:,0]
131
131
@endcode
132
- Suppose, you want to make all the red pixels to zero, you need not split like this and put it equal
133
- to zero. You can simply use Numpy indexing, and that is faster.
132
+ Suppose you want to set all the red pixels to zero, you do not need to split the channels first.
133
+ Numpy indexing is faster:
134
134
@code {.py}
135
135
>>> img[ :,:,2] = 0
136
136
@endcode
137
137
138
- ** warning **
138
+ ** Warning **
139
139
140
140
cv2.split() is a costly operation (in terms of time). So do it only if you need it. Otherwise go
141
141
for Numpy indexing.
@@ -144,7 +144,7 @@ Making Borders for Images (Padding)
144
144
-----------------------------------
145
145
146
146
If you want to create a border around the image, something like a photo frame, you can use
147
- ** cv2.copyMakeBorder()** function . But it has more applications for convolution operation, zero
147
+ ** cv2.copyMakeBorder()** . But it has more applications for convolution operation, zero
148
148
padding etc. This function takes following arguments:
149
149
150
150
- ** src** - input image
@@ -190,7 +190,7 @@ plt.subplot(236),plt.imshow(constant,'gray'),plt.title('CONSTANT')
190
190
191
191
plt.show()
192
192
@endcode
193
- See the result below. (Image is displayed with matplotlib. So RED and BLUE planes will be
193
+ See the result below. (Image is displayed with matplotlib. So RED and BLUE channels will be
194
194
interchanged):
195
195
196
196
![ image] ( images/border.jpg )
0 commit comments