1''*_*1'' 16 opencv image-processing threshold
我有一个相当模糊的数独谜题的432x432图像,其自适应阈值不好(取5x5像素的块大小,然后减去2):

正如你所看到的,数字略有扭曲,其中有很多破损,而且有5s融入6s和6s融入8s.此外,还有很多噪音.为了修复噪声,我必须使用高斯模糊使图像更加模糊.然而,即使是相当大的高斯内核和自适应阈值blockSize(21x21,减去2)也无法消除所有断点并将数字融合在一起甚至更多:

我还尝试在阈值处理后扩展图像,这与增加blockSize有类似的效果; 并且锐化图像,这在某种程度上没有太大作用.我还应该尝试什么?
1''*_*1'' 20
一个很好的解决方案是使用形态学闭合来使亮度均匀,然后使用常规(非自适应)Otsu阈值:
// Divide the image by its morphologically closed counterpart
Mat kernel = Imgproc.getStructuringElement(Imgproc.MORPH_ELLIPSE, new Size(19,19));
Mat closed = new Mat();
Imgproc.morphologyEx(image, closed, Imgproc.MORPH_CLOSE, kernel);
image.convertTo(image, CvType.CV_32F); // divide requires floating-point
Core.divide(image, closed, image, 1, CvType.CV_32F);
Core.normalize(image, image, 0, 255, Core.NORM_MINMAX);
image.convertTo(image, CvType.CV_8UC1); // convert back to unsigned int
// Threshold each block (3x3 grid) of the image separately to
// correct for minor differences in contrast across the image.
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
Mat block = image.rowRange(144*i, 144*(i+1)).colRange(144*j, 144*(j+1));
Imgproc.threshold(block, block, -1, 255, Imgproc.THRESH_BINARY_INV+Imgproc.THRESH_OTSU);
}
}
Run Code Online (Sandbox Code Playgroud)
结果:

看看Smoothing Images OpenCV教程.除高斯模糊也有medianBlur和bilateralFilter你也可以用它来降低噪声.我从你的源图像中获得了这张图片(右上角):

更新:删除小轮廓后我得到的图片如下:

更新:您也可以锐化图像(例如,使用Laplacian).看看这个讨论.