gpt4 book ai didi

image-processing - 模糊图像的自适应阈值

转载 作者:太空宇宙 更新时间:2023-11-03 20:38:51 24 4
gpt4 key购买 nike

我有一个相当模糊的 432x432 数独游戏图像,它不能很好地自适应阈值(取 5x5 像素 block 大小的平均值,然后减去 2):

enter image description here

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

enter image description here

我也试过在阈值处理后放大图像,这与增加 blockSize 有类似的效果;和 sharpening the image ,无论哪种方式都没有太大作用。我还应该尝试什么?

最佳答案

一个很好的解决方案是使用形态学闭合使亮度均匀,然后使用常规(非自适应)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);
}
}

结果:

enter image description here

关于image-processing - 模糊图像的自适应阈值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13391073/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com