I am working on a task to detect patches on road. However, in pre-processing, I am unable to figure out what technique should I use to take out patches using thresholding.
I have used several thresholding techniques out of which Otsu's Multi-level thresholding Algorithm gave the best result among them.
The thresholding method works on this image, however it does not work well with images with different surfaces like the one below.
I am looking is for a more general approach to this problem that would use thresholding or any other technique to take out patch areas in different surfaces of road and apply further analysis onto it.
Here's my code:
import cv2
import numpy as np
import os
from skimage.filters import threshold_multiotsu
def threshold(image):
thresh = threshold_multiotsu(img, 3)
ret, thresh1 = cv2.threshold(img, thresh[0], 255, cv2.THRESH_BINARY)
ret, thresh2 = cv2.threshold(img, thresh[1], 255, cv2.THRESH_BINARY_INV)
thresh3 = cv2.bitwise_and(thresh1, thresh2)
return thresh3
if __name__ == "__main__":
path = './Images/Set 124/images/GX010122_frame_1399.jpg'
image = cv2.imread(path)
gray_image = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
blur_image = cv2.medianBlur(gray_image, 11)
equalize_image = cv2.equalizeHist(blur_image)
multi_otsu = threshold(equalize_image)
cv2.imshow('Threshold Result', multi_otsu)
cv2.waitKey(0)