自适应阈值二值化:用于移除鬼对象的后处理 [英] Adaptive threshold binarization: post-processing for removing ghost objects

查看:138
本文介绍了自适应阈值二值化:用于移除鬼对象的后处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道后处理算法从二值化图像中删除鬼对象吗?问题:
当我使用例如niblack方法或bernsen二值化图像时,
会产生很多噪音。我关于二值化的红皮书或互联网文章,他们都说Niblack和其他的二值化方法需要后处理步骤,
但他们没有说它是什么,后处理操作。所以,如果有人知道,请打电话给我。
编辑:
原始图片:

Does anybody knows about post-processing algorithms to remove ghost objects from binarized image? The problem: When I binarize image using for example niblack method or bernsen, it produces many noise. I red book or internet articles about binarization, and they all say that the post-processing step is needed in Niblack and other's binarization method, But they don't say what is it, post-processing operation. So please, if someone knows, tel me. Original image:

alt text http://i.piccy.info/i4/20/63/b970ab2ca66e997f421e969a1657.bmp

伯恩森门槛获胜31,对比差15:

Bernsen threshold winsize 31, contrast difference 15:

alt text http://i.piccy.info/i4/32/55/2f1e0293311119986bd49529e579.bmp

Bernsen阈值获胜31 ,对比差异31:

Bernsen threshold winsize 31, contrast difference 31:

alt text http://i.piccy.info/i4/2a/13/774508890030b93201458986bbd2.bmp

Niblack方法窗口大小-15,k_value 0.2:

Niblack method window size-15, k_value 0.2:

alt文本http://i.piccy.info/i4/12/4f/fa6fc09bcba7a7e3245d670cbfa5.bmp

Niblack方法窗口大小-31,k_value 0.2:

Niblack method window size-31, k_value 0.2:

alt text http://i.piccy.info/i4/c0/fd/1f190077abba2aeea89398358fc0.bmp

EDIT2:
如您所见,Niblack阈值会产生很多噪音。
如果我减小窗口尺寸,黑色方块会变成一个白色的内部。
Bernsen更好 - 噪音更少,但即使我让对比度差异更大,
但是有一个问题,我现在无法生成图像,用文字说,问题:
如果图像包含一些颜色接近白色的对象,背景为白色,
所以如果有一个黑色区域(对于检查线),则此方法忽略对象,结果是错误的。
那是因为Bernsen方法使用这个公式:每个像素的
计算对比度差异
diff = maximum_grayscale_value - minimum_grayscale_value
然后差异用于计算阈值,
但是在我上面写的情况下,我们的最大值为255
,最小值为0.
因此阈值将为128,
但实际物体颜色高于128(接近白色)。

As you see, the Niblack threshold is making many noise. And if I make the window size less, the black squares became a little white inside. The Bernsen is better - less noise, but even if I make the contrast difference bigger, but there is one problem, I just can't produce image right now, in words, the problem: if image contains some objects with color close to white color, and the background is white, so if there is a region (for examle line) with black color, then this method ignores the objects and result is wrong. That is because Bernsen method use this formula: at each pixel calculate the contrast difference diff = maximum_grayscale_value - minimum_grayscale_value and then the diff is used to calculate threshold value, but in the case that I wrote above, we have maximum value of 255 and minimum value of 0. So threshold will be 128, But actual object color is above the 128 (near white color).

所以我需要使用一些后处理操作来正确地进行二值化。
有什么想法吗?

So I need to use some post-processing operations to make binarization correctly. Any thoughts?

推荐答案

使用K-means完成Python程序,这是一种用于寻找最佳量化间隔的工具: / p>

Complete Python program using K-means, a tool meant for finding optimal quantization intervals:

from scipy.misc import imread, imsave
def kmeans(file_in, file_out, maxiter):
    X = imread(file_in)
    thresh = X.mean()
    for iter in range(maxiter):
        thresh = (X[X<thresh].mean() + X[X>=thresh].mean())/2.0
    X[X<thresh] = 0
    X[X>=thresh] = 255
    imsave(file_out, X)
    return X, thresh

在每次迭代期间,K-means计算每个集群的中心,然后重新分配元素基于重新计算的中心的集群。在每个元素(即像素)是一维的简单情况下,只需要两个聚类,阈值就是两个聚类中心的平均值。

During each iteration, K-means computes the center of each "cluster" then reassigns elements to clusters based upon the recomputed centers. In the simple case where each element (i.e., pixel) is one-dimensional, and only two clusters are required, the threshold is simply the average of the two cluster centers.

我应该补充说,此方法适用于您发布的示例图像,但可能不适用于其他人(例如您在其他问题中发布的图像)。但是没有进一步的信息,我认为这个解决方案有效。

I should add that this method works for the example image you posted, but may not for others (such as the one you posted in another question). But without further information, I think that this solution works.

输出:

binary.bmp http://up.stevetjoa.com/binary.bmp

这篇关于自适应阈值二值化:用于移除鬼对象的后处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆