【问题标题】:Adaptive Thresholding - Implementation of the Minimum Error Thresholding Method自适应阈值 - 最小误差阈值方法的实现
【发布时间】:2010-01-13 09:57:46
【问题描述】:

我正在尝试在 MATLAB 中实现以下 Minimum Error Thresholding(由 J. Kittler 和 J. Illingworth 编写)方法。

您可以查看 PDF:

我的代码是:

function [ Level ] = MET( IMG )
%Maximum Error Thresholding By Kittler
%   Finding the Min of a cost function J in any possible thresholding. The
%   function output is the Optimal Thresholding.

for t = 0:255 % Assuming 8 bit image
    I1 = IMG;
    I1 = I1(I1 <= t);
    q1 = sum(hist(I1, 256));

    I2 = IMG;
    I2 = I2(I2 > t);
    q2 = sum(hist(I2, 256));

    % J is proportional to the Overlapping Area of the 2 assumed Gaussians
    J(t + 1) = 1 + 2 * (q1 * log(std(I1, 1)) + q2 * log(std(I2, 1)))...
        -2 * (q1 * log(q1) + q2 * log(q2));
end

[~, Level] = min(J);

%Level = (IMG <= Level);

end

我在下面的图片上试过了:

Original size image.

目标是提取字母的二进制图像(Hebrew Letters)。 我将代码应用于图像的子块(40 x 40)。 然而我得到的结果不如K-Means Clustering method

我错过了什么吗? 谁有更好的主意?

谢谢。

附: 有人会在主题标签中添加“自适应阈值”吗(我不能,因为我是新手)。

【问题讨论】:

  • 您不能保证通过自适应聚类获得更好的结果,您是否使用您的算法尝试过其他图像?
  • 好吧,还有 3 个这样的。同样的结果,糟糕的结果。

标签: matlab image-processing adaptive-threshold


【解决方案1】:

阈值设置是一项相当棘手的工作。多年来,我一直在对图像进行阈值处理,但我没有找到一种始终表现良好的技术,而且我开始不相信 CS 期刊中普遍表现出色的说法。

最大误差阈值方法仅适用于很好的双峰直方图(但它适用于那些)。您的图像看起来像信号和背景可能没有足够清晰地分离,无法使用此阈值方法。

如果您想确保代码正常工作,您可以创建一个这样的测试程序,并检查您是否获得了良好的初始分段,以及代码在什么级别的“双峰”故障。

【讨论】:

  • 你会为这种图像推荐哪种方法?谢谢。
  • 诚实吗?我不知道。我从来没有使用过这种图像,因此我对这个问题几乎没有直觉。我已经查看了直方图,我注意到即使背景非常不均匀,前景大多
  • 第一个近似值可以让您很好地了解哪些像素属于背景。然后,您可以将背景分割成更亮和更暗的部分。在每个部分中,您可以进行滞后阈值处理以改进初始猜测,即确定一个局部阈值,以便低于该阈值并连接到初始猜测的任何像素的像素(您可能必须清理初始猜测一下)被保留,而达到阈值但未连接的像素被丢弃。
  • 显然,还有很多很多其他的方法可以分割这个图像。只需找到一个能够为您提供良好起点的方法,并提出一些预处理和后处理例程,让您可以应用您对正在分析的图像的先验知识。如果你想解决问题,而不是写一篇 CS 论文,你不应该过多地寻找完美的核心算法。你想编写一个程序来完成这项工作。
【解决方案2】:

我认为您的代码并不完全正确。您使用图像的绝对直方图而不是论文中使用的相对直方图。此外,您的代码效率相当低,因为它为每个可能的阈值计算两个直方图。我自己实现了算法。也许,有人可以利用它:

function [ optimalThreshold, J ] = kittlerMinimimErrorThresholding( img )
%KITTLERMINIMIMERRORTHRESHOLDING Compute an optimal image threshold.
%   Computes the Minimum Error Threshold as described in
%   
%   'J. Kittler and J. Illingworth, "Minimum Error Thresholding," Pattern
%   Recognition 19, 41-47 (1986)'.
%   
%   The image 'img' is expected to have integer values from 0 to 255.
%   'optimalThreshold' holds the found threshold. 'J' holds the values of
%   the criterion function.

%Initialize the criterion function
J = Inf * ones(255, 1);

%Compute the relative histogram
histogram = double(histc(img(:), 0:255)) / size(img(:), 1);

%Walk through every possible threshold. However, T is interpreted
%differently than in the paper. It is interpreted as the lower boundary of
%the second class of pixels rather than the upper boundary of the first
%class. That is, an intensity of value T is treated as being in the same
%class as higher intensities rather than lower intensities.
for T = 1:255

    %Split the hostogram at the threshold T.
    histogram1 = histogram(1:T);
    histogram2 = histogram((T+1):end);

    %Compute the number of pixels in the two classes.
    P1 = sum(histogram1);
    P2 = sum(histogram2);

    %Only continue if both classes contain at least one pixel.
    if (P1 > 0) && (P2 > 0)

        %Compute the standard deviations of the classes.
        mean1 = sum(histogram1 .* (1:T)') / P1;
        mean2 = sum(histogram2 .* (1:(256-T))') / P2;
        sigma1 = sqrt(sum(histogram1 .* (((1:T)' - mean1) .^2) ) / P1);
        sigma2 = sqrt(sum(histogram2 .* (((1:(256-T))' - mean2) .^2) ) / P2);

        %Only compute the criterion function if both classes contain at
        %least two intensity values.
        if (sigma1 > 0) && (sigma2 > 0)

            %Compute the criterion function.
            J(T) = 1 + 2 * (P1 * log(sigma1) + P2 * log(sigma2)) ...
                     - 2 * (P1 * log(P1) + P2 * log(P2));

        end
    end

end

%Find the minimum of J.
[~, optimalThreshold] = min(J);
optimalThreshold = optimalThreshold - 0.5;

【讨论】:

  • 我想将您的代码(kittler Minimim Error Thresholding)用于 CT 图像。典型的 Hounsfield 单位值介于 -1000 : >1000 之间。那么,如何设置阈值的范围(T)?
猜你喜欢
  • 1970-01-01
  • 2013-01-23
  • 1970-01-01
  • 2014-04-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-07-11
相关资源
最近更新 更多