2

这是我的例子。左到右:

  1. 原始图像
  2. 灰度 + (3,3) 高斯模糊
  3. 大津阈值 + 反转像素

在此处输入图像描述

我想捕捉更多笔触的微弱部分。我知道 Otsu Thresholding 试图在像素强度直方图的两个峰值之间应用阈值点,但我想稍微偏一下,这样我就可以捕捉到一些较亮的像素。

有可能开箱即用吗?还是我需要手动做一些事情?

4

3 回答 3

5

I have an answer courtesy of the rubber duck phenomenon.

th, th_img = cv2.threshold(blur, 0, 255, cv2.THRESH_BINARY+cv2.THRESH_OTSU)

The 0th index of the returned tuple (th) is the threshold value that the Otsu Binarization algorithm chose. I can discard th_img and apply whatever bias I like to th before using it in regular binary thresholding.

desired_th = th*1.2
_, th_img = cv2.threshold(blur, desired_th, 255, cv2.THRESH_BINARY)

Here's what I get. By cleaning up the unwanted speckles that could appear on the outside, I'll get what I was looking for.

enter image description here

于 2020-01-16T16:30:21.387 回答
2

偏置 Otsu 阈值的替代方法是进行基于区域的阈值处理,如下所示:

thr = .8
blur_hor = cv2.filter2D(img[:, :, 0], cv2.CV_32F, kernel=np.ones((11,1,1), np.float32)/11.0, borderType=cv2.BORDER_CONSTANT)
blur_vert = cv2.filter2D(img[:, :, 0], cv2.CV_32F, kernel=np.ones((1,11,1), np.float32)/11.0, borderType=cv2.BORDER_CONSTANT)
output = ((img[:,:,0]<blur_hor*thr) | (img[:,:,0]<blur_vert*thr)).astype(np.uint8)*255
于 2020-01-17T03:54:28.263 回答
0

在 C++ 中,我经常“调出”(otsu)阈值函数返回的阈值,将其乘以一个因子并将其传递回(固定)阈值函数:

//get the threshold computed by otsu:
double otsuThresh = cv::threshold( inputImage, otsuBinary, 0, 255,cv::THRESH_OTSU );

//tune the threshold value:
otsuThresh = 0.5 * otsuThresh;

//threshold the input image with the new value:
cv::threshold( inputImage, binaryFixed, otsuThresh, 255, cv::THRESH_BINARY );
于 2020-01-17T01:04:00.980 回答