Reputation: 15
I have found a particular contour in an image. I have created a mask with the entire image black except for the boundary points of the contour. The contour has been mapped perfectly. Clickhere for the picture of the contour created.
Now I want to go to my original image and get the average pixel intensity value of all points inside this contour of the original image. When I use the cv.mean() function, do I get the average value of only the points specified by the mask, i.e. just the boundary points or all the points inside the mask?
Upvotes: 1
Views: 5966
Reputation: 25914
The easiest way to do this is by picking out pixels in your image that correspond to places where the mask is white. If you want pixel on the boundary use the mask as you have shown it. If you want pixel in (and on) the boundary; draw it instead as a filled contour (thickness=-1)
. Here's an example:
img = cv2.imread('image.jpg')
mask = cv2.imread('mask.png', 0)
locs = np.where(mask == 255)
pixels = img[locs]
print(np.mean(pixels))
Upvotes: 3