0

I'm finding it difficult to find an adaptive image thresholding technique for mazes that will return either a high or low value to make sure that all the paths are the same color.

So far I have tried a fixed threshold which obviously didn't work and otsu's method which return a value around the middle which meant that some pixels were not converted properly.

original image - https://i.stack.imgur.com/RwQld.jpg

otsu's method - https://i.stack.imgur.com/Q9Jh8.jpg

desired output - https://i.stack.imgur.com/6cmgR.jpg

1 Answers1

0

Sorry, I don't have java so I just try out some methods in python and can get the desired output that you want. Hope it will help you.

import cv2
import numpy as np

image = cv2.imread("1.png")

gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

_,thresh = cv2.threshold(gray,100,255,cv2.THRESH_BINARY)
cv2.imshow("thresh",thresh)

blur = cv2.GaussianBlur(gray,(5,5),0)
ret3,otsu = cv2.threshold(blur,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)
cv2.imshow("otsu",otsu)

adaptive_thresh = cv2.adaptiveThreshold(gray, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, 29, 30)
cv2.imshow("adaptive_thresh",adaptive_thresh)

cv2.imshow("img",image)
cv2.waitKey(0)
cv2.destroyAllWindows()
  • Otsu method

enter image description here

  • Fixed binary threshold

enter image description here

  • Adaptive threshold

enter image description here

Ha Bom
  • 2,787
  • 3
  • 15
  • 29