Python+opencv

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Python+opencv

mark187
This post has NOT been accepted by the mailing list yet.
Hello, I have a few questions. I'm working on this image (original image is in the end of the post), which is thresholded binary.
How can I get the number of pixels in every 'white part' of the image (non-background), which are 12, I know that by ndimage.label.
Mainly I want to know which of that 12 parts is the biggest so that I can set all other parts to 'zero' -> background value.
 
import cv2
import numpy as np
import scipy
from scipy import ndimage


img = cv2.imread('100x100.png')
gray_image = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
cv2.imwrite('gray_image.jpg',gray_image)
cv2.imshow('color_image',img)
cv2.imshow('gray_image',gray_image)

threshold = 100
labeled, nr_objects = ndimage.label(img > threshold)
print "Number of objects is %d" %nr_objects

plt.imshow(labeled)
plt.show()
cv2.waitKey(0)
cv2.destroyAllWindows()