Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Dilation not working

I have a distance transformed image and I have to return an image in which each pixel is assigned a highest value in the neighbourhood using a 3x3 grid. I am using morphological Dilation for that, but dilation doesn't seem to be working. It returns the same image.

# load the image, convert it to grayscale, and blur it slightly
image = cv2.imread(r'C:\Users\x\Desktop\sampleImg\ecu.tif')
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
blurred = cv2.GaussianBlur(gray, (3, 3), 0)

#apply Canny edge detection  
canny_img = cv2.Canny(blurred, 150, 200)

#apply Distance Transform
invert_canny= 255- canny_img  
dist_trans= cv2.distanceTransform(invert_canny, cv2.DIST_L2, 3)

#normalize to visualize dist-transformed img 
cv2.normalize(dist_trans, dist_trans, 0.0, 1.0, cv2.NORM_MINMAX)

# apply dilation
kernel=np.ones((3,3), np.uint8)
dilate=cv2.dilate(dist_trans,kernel, iterations=1)