Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Image processing 可靠地查找对象中的孔数_Image Processing_Image Segmentation_Morphological Analysis - Fatal编程技术网

Image processing 可靠地查找对象中的孔数

Image processing 可靠地查找对象中的孔数,image-processing,image-segmentation,morphological-analysis,Image Processing,Image Segmentation,Morphological Analysis,我目前正在使用MATLAB的bweuler函数来查找对象中的“孔”数。我有困难,因为这些图像的分辨率相对较低,目前只有50%的成功率。以下是将失败的图像示例(为了测试方便而裁剪): 标准化和放大,以便您可以看到发生了什么: 这里的洞数应该是1,但我还没有找到一种可靠的方法来在保持周围环境完整的情况下将这个小区域划分出来 我当前的方法使用自适应阈值,但这是有问题的,因为正确的窗口大小并非在所有样本中都是恒定的。例如,此示例将在窗口大小为6的情况下工作,但其他示例将失败 以下是更多的故障案例供参

我目前正在使用MATLAB的
bweuler
函数来查找对象中的“孔”数。我有困难,因为这些图像的分辨率相对较低,目前只有50%的成功率。以下是将失败的图像示例(为了测试方便而裁剪):

标准化和放大,以便您可以看到发生了什么:

这里的洞数应该是1,但我还没有找到一种可靠的方法来在保持周围环境完整的情况下将这个小区域划分出来

我当前的方法使用自适应阈值,但这是有问题的,因为正确的窗口大小并非在所有样本中都是恒定的。例如,此示例将在窗口大小为6的情况下工作,但其他示例将失败

以下是更多的故障案例供参考:

N=1->

N=2->

我目前的方法可以处理一些情况:

N=6->

N=1->

N=1->

我还将发布我当前代码的一个简短版本,尽管正如我之前所说,我不相信自适应阈值方法会起作用。在此期间,我将使用其他一些形态学分割方法。只需阅读中的一个测试图像并调用
findholes(image)

函数N=findholes(I)
bw=imclearborder(自适应阈值(I,9));
N=abs(1-bweuler(bw2,4));
结束
函数bw=自适应阈值(IM、ws、C、tm)
%ADAPTIVETHRESHOLD是一种自适应阈值算法,用于分离
%前景来自照明不均匀的背景。
%bw=自适应阈值(IM、ws、C)输出具有本地
%图像IM的阈值均值-C或中值-C。
%ws是本地窗口大小。
%C是从最终输入图像减去im2bw(范围0…1)的恒定偏移量。
%tm为0或1,在平均值和中值之间切换。tm=0平均值(默认值);tm=1中位数。
%
%熊光磊撰稿(xgl99@mails.tsinghua.edu.cn)
%清华大学,北京,中国。
%
%有关更多信息,请参阅
%  http://homepages.inf.ed.ac.uk/rbf/HIPR2/adpthrsh.htm
if(nargin<2)
错误(“您必须提供IM和ws”);
结束

如果(纳金你如何从完整图像中定位这些斑点。你确定在对findholes的调用中只有一个对象吗?看看ImMin,它可能会给你一些想法。@Ashish:我现在有一个可靠的分割例程,所以我们可以假设,
findholes
将只需要处理一个对象。实际上我有玩
imregionalmax
(类似于
BW=imregionalmax(I);n=sum(BW(:);
),但它并没有被证明像我希望的那样可靠。也就是说,我在一段时间前就把这个解决方案抛在了脑后,通过对图像进行进一步的预处理来重新审视它可能会更好。Ed-Immin似乎“有时”会找到孔的中心,但也许通过调整和预处理,它会变得更好。我会看看我是否会对你的示例图像。@Ashish:在重新访问
imregionalmin
之后,使用了一些更好的预处理技术,它实际上做得相当好。如果你把它作为一个答案发布,我会接受的。Ed,很高兴它做得更好。如果你发布了如何让imregionalmin工作的消息,它可能对与你同舟共济的其他人来说是最好的(我相信接受你自己的答案是可以的)。
function N = findholes(I)    
    bw = imclearborder(adaptivethreshold(I, 9));      
    N = abs(1 - bweuler(bw2, 4));
end

function bw=adaptivethreshold(IM,ws,C,tm)
    %ADAPTIVETHRESHOLD An adaptive thresholding algorithm that seperates the
    %foreground from the background with nonuniform illumination.
    %  bw=adaptivethreshold(IM,ws,C) outputs a binary image bw with the local 
    %   threshold mean-C or median-C to the image IM.
    %  ws is the local window size.
    %  C is a constant offset subtracted from the final input image to im2bw (range 0...1).
    %  tm is 0 or 1, a switch between mean and median. tm=0 mean(default); tm=1 median.
    %
    %  Contributed by Guanglei Xiong (xgl99@mails.tsinghua.edu.cn)
    %  at Tsinghua University, Beijing, China.
    %
    %  For more information, please see
    %  http://homepages.inf.ed.ac.uk/rbf/HIPR2/adpthrsh.htm

    if (nargin < 2)
        error('You must provide IM and ws');
    end

    if (nargin<3)
        C = 0;
        tm = 0;
    end

    if (nargin==3)
        tm=0;
    elseif (tm~=0 && tm~=1)
        error('tm must be 0 or 1.');
    end

    IM=mat2gray(IM);

    if tm==0
        mIM=imfilter(IM,fspecial('average',ws),'replicate');
    else
        mIM=medfilt2(IM,[ws ws]);
    end
    sIM=mIM-IM-C;
    bw=im2bw(sIM,0);
    bw=imcomplement(bw);
end