0

我有一个距离变换的图像,我必须返回一个图像,其中每个像素都使用 3x3 网格在邻域中分配了一个最高值。怎么做?

我不确定形态稀释是否做同样的工作。就我而言,它返回相同的图像。

# 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)
4

0 回答 0