matlab - 为什么这个轮廓检测代码不能正常工作?

标签 matlab image-processing edge-detection

我根据this paper的第一部分写了一段代码(关于轮廓检测)。但是,我的代码生成的图像与论文中显示的图像不同。我是图像处理的新手,正因为如此,我认为可能有一些我不完全理解的东西。
我将写下论文中所说的以及我是如何实现的,以便您查看是否有任何误解。
论文说:

We propose to use the local method which examines illumination changes within the chosen window n * n . We usually use 3 * 3 window and we divided the image into many overlapping regions of that size. For each of those regions we calculated mean and standard deviation of the pixel intensity values in 8-pixel neighborhood.

对于这部分我写了:

e=imread('1.jpg');
p=rgb2gray(e);
p=im2double(p);
h=[1 1 1;
   1 1 1;
   1 1 1;]; 
h=h/9;
u=imfilter(p,h);% average filter
Size=size(e);
n=3;
e=[1 1 1;
   1 1 1;
   1 1 1;]; 
Di=stdfilt(p,e); % standard deviation

我这里有一个问题:8 像素邻域 是什么意思?是 (a) 我不应该使用每个 3*3 局部窗口的中心像素,还是 (b) 只是局部窗口的另一个术语?

现在算法的其余部分,来自论文:

Then we perform decision if the centre pixel of the examined region belongs to the line or to the background. For the maximum value of the pixel intensity Ihigh, and the minimum value of the pixel intensity in the region Ilow , we calculate the difference S(i,j) such as:
S(i,j)=Ihigh-Ilow
and we compare it to certain threshold value. We propose the usage of mean and standard deviation of pixel intensities in calculation of the threshold value T(i,j) used in contour detection. T=u-k*sd (sd=standard deviation) where k is a certain value.Then the rule for the contour detection is:
g(i,j)=1 if S(i,j)>=T(i,j) and 0 if S(i,j) < T(i,j) In result we obtain the binary image g(i,j) with the detected contours. Moreover, the constant k allows to adjust and change the sensitivity of the edge detection algorithm,"

我为这部分写了这段代码:

k=1;
Div=k*Di;
t=u-Div;
min=ordfilt2(p,1,ones(3,3));
max=ordfilt2(p,3*3,ones(3,3));
s=max-min;
g=zeros(Size(1),Size(2));
for I=1:Size(1)
    for J=1:Size(2)
        if(s(I,J) >= t(I, J))
            g(I, J) = 1;
        else
            g(I, J) = 0;
        end
    end
end
g=imadjust(g,[0 1],[1,0]);
imshow(g)

我不确定这两行:

 min=ordfilt2(p,1,ones(3,3));
 max=ordfilt2(p,3*3,ones(3,3);

根据论文所说,有什么我遗漏的吗?还是有什么误解?

这是论文中显示的示例:

example from paper

这就是我得到的:

own result

原图:

original

最佳答案

我认为您的结果看起来还不错。关于差异:

  • 您的噪点更多,但这可能是因为您的分辨率更高,可以在图像上显示更多细节。在找到轮廓之前,您可以尝试对图像运行高斯滤波器。
  • 您的图像中的灰度值可能比论文图像中的灰度值多得多。因此,更多细节可能会在该算法的轮廓中找到。
  • 可能只是因为 k 的值不同。

但是,我认为您应该将您耳朵的灰度值图像与结果进行比较。

8-pixel-neighborhood in 2d 意味着您不使用中间的像素,而是使用它周围的像素。与使用 9 像素相比,我无法估计它对结果的影响。

关于您的代码的评论:您可以替换

for I=1:Size(1)
    for J=1:Size(2)
        if(s(I,J) >= t(I, J))
            g(I, J) = 1;
        else
            g(I, J) = 0;
        end
    end
end

g=zeros(Size);
g(s>=t)=1;

关于matlab - 为什么这个轮廓检测代码不能正常工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24551126/

相关文章:

python-2.7 - 计算边线斜率的有效方法

python - 从边缘图像中提取成分并存储以进行进一步处理

matlab - Matlab 中的 Inf*0

Matlab:如何在 tf 系统上应用低通滤波器以在 simulink 中进行更快的评估

java - Matlab 结构和 Java LinkedList

c++ - 反向鱼眼畸变

Java BufferedImage getRGB 方法和 Color 类

matlab - 如何在轴中使用刻度而不指定刻度的最后一个值?

c++ - 如何计算立体图像的密集视差图?

python - Canny 运算符破坏图像边缘