简体   繁体   English

最佳图像阈值技术将返回高/低阈值?

[英]Best image thresholding technique that will return a high/low threshold?

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. 到目前为止,我已经尝试了一个固定的阈值,该阈值显然不起作用,并且otsu的方法返回了一个中间值,这意味着某些像素未正确转换。

original image - https://imgur.com/DqaUYfW 原始图片-https://imgur.com/DqaUYfW

otsu's method - https://imgur.com/a/V5t6rqZ 大津算法- https://imgur.com/a/V5t6rqZ

desired output - https://imgur.com/a/yvXuAqC 所需的输出-https://imgur.com/a/yvXuAqC

Sorry, I don't have java so I just try out some methods in python and can get the desired output that you want. 抱歉,我没有Java,所以我只需尝试使用python中的一些方法即可获得所需的所需输出。 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 大津法

在此处输入图片说明

  • Fixed binary threshold 固定二进制阈值

在此处输入图片说明

  • Adaptive threshold 自适应阈值

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM