Question

I have to make dilation on binary images My problem is adapting dilation operation on difference sizes of binary images.

I want to apply proportionally dilation operation to all images and prevent that a small image like a wheel become a white circle.

#image dilation
import cv2

path "pathimage"
gray = cv2.imread(path,0)
element = cv2.getStructuringElement(cv2.MORPH_CROSS,(6,6)) 
graydilate = cv2.erode(gray, element) #imgbnbin
graydilate = cv2.erode(graydilate, element)
#graydilate = cv2.erode(graydilate, element)

cv2.imshow('erode',graydilate)
cv2.waitKey()

ret,thresh = cv2.threshold(graydilate,127,255,cv2.THRESH_BINARY_INV) 
imgbnbin = thresh
print("shape imgbnbin")
print(imgbnbin.shape)
cv2.imshow('binaria',imgbnbin)
cv2.waitKey()

May I have to rescale images?

Was it helpful?

Solution

You can do either of the following:

  • Re-scale the images to the same size.

OR

  • If the object in the image is not directly proportional to the size of the image, then extract a bounding box for the object, and then determine the size of the structural element (currently always 6x6) relative to the size of the object's bounding box. That way you're sure that the morphology is proportional to the object size.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top