Image Segmentation
I m working on road detection, I am following an approach as mention in this paper, which is based on the concept of reference circles from a distance transformed image. This approach is good to identify road pixels but along with that it also detects non road pixel as shown in yellow circles in an image below. I want to get rid of these regions. I removed the vegetation using NDVI but I am not sure how to get rid of ground pixels. Can someone please suggest me the possible ways to get rid of ground pixels or how to segment out the road region?
image = cv2.imread(r"C:\Users\x\Desktop\sampleImg\aoi.tif")
gray = cv2.cvtColor(rgb_img, cv2.COLOR_BGR2GRAY)
blurred = cv2.GaussianBlur(gray, (5, 5), 0)
# Apply canny
canny_img = auto_canny(blurred)
invert_canny = 255 - canny_img
#Distance transformed image
dst_trans= cv2.distanceTransform(invrt_canny, cv2.DIST_L2, 3)
#Reference Circles
image_max= ndi.maximum_filter(dst_trans, (3,3), mode='constant')
comp= cv2.compare(dist_trans, image_max, cv2.CMP_EQ)
peaks= cv2.multiply(dist_trans, comp, 1/255.0, dtype=cv2.CV_8UC1)
#removing vegetaion
ndvi_map[ndvi_map > 0] = 0
ndvi_im= np.array(ndvi_map*255, dtype=np.uint8)
msk_peaks= cv2.bitwise_and(peaks,peaks, mask=ndvi_im)
#Hough transfomation
lines = cv2.HoughLinesP(image=peaks,rho=1,theta=np.pi/180, threshold=10,lines=np.array([]), minLineLength=5,maxLineGap=3)
a,b,c = lines.shape
for i in range(a):
cv2.line(image, (lines[i][0][0], lines[i][0][1]), (lines[i][0][2], lines[i][0][3]), (255, 0, 0), 2, cv2.LINE_AA)
orignal image based on Reference cirlces hough transformation
K-mean clustering (gpu version) is an option if you want to try it. If you already made road mask and vegetation mask just add both masks and use copyTo function to get only terrain pixels.
if you add the original image and the code you tried. you will help those people who want to help you.
@sturkmen i have edited the question.
@Ziri k-means clustters the road and ground pixels into same category as both regions are quite the same (here we have dirt roads).