I am trying to get the distance transform image, but I am getting a bad result.
Image:
Code:
import cv2
import imutils
import numpy as np
photo = 'dog.jpg'
img = cv2.imread(photo)
ybprc = cv2.cvtColor(img, cv2.COLOR_BGR2YCrCb)
inrangeHsv = cv2.inRange(ybprc, np.array([0, 135, 85]), np.array([255, 180, 135]))
retval, otsu = cv2.threshold(inrangeHsv, 150, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)
cnts = cv2.findContours(otsu.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cnts = imutils.grab_contours(cnts)
c = max(cnts, key=cv2.contourArea)
mask = cv2.drawContours(otsu, [c], -1, (0,255,0), 2)
out = cv2.distanceTransform(mask, distanceType=cv2.DIST_L2, maskSize=5)
cv2.imshow("distance_transform", out)
cv2.waitKey(0)
cv2.destroyAllWindows()
But the result should be more like:
How should I fix it?







