令我心灰意冷的不是身边没有Lolita,而是欢笑声中没有她

边缘检测VS梯度图像

2008-03-20 15:19:37

图像的边缘检测可以通过梯度算子来实现,诸如,Roberts,sobel,prewitt,canny等,它的本质也就是对一幅图像求其梯度图像,那么在matlab中通过edge函数求得的边缘和我们直接使用梯度算子求得一幅图像的梯度图像会不会有区别呢?在matlab环境下,通过这样一个实验来看一下结果:

Step1: read an image into workspace.

rgb = imread(pears.png);

imshow(rgb);

I = rgb2gray(rgb);

figure,imshow(I)

step2:Detect the edge of the gray image,I,using edge() function.Here we use 'Sobel' as the parameter.

BW = edge(I,'sobel');

figure,imshow(BW),title('sobel edge detection')

step3:Now we calculate the gradient of the image through sobel method.

hy = fspecial('sobel');

hx = hy';

Iy = imfilter(double(I),hy,'replicate');

Ix = imfilter(double(I),hx,'replicate');

gradmag = sqrt(Ix.^2+Iy.^2);

figure,imshow(gradmag,[]),title('gradmag')

OK,so now,have u found what's the difference? 

很明显的一点是:edge()函数的输出为二值图像,而我们计算所的梯度图像仍为灰度图像。只是这一点区别吗?那edge函数又是怎么进行二值化的,即它的阈值是怎么确定的?


TAG:

删除 T 发布于2008-04-05 06:59:40
阈值可以通过直方图来选择
我来说两句

-5 -3 -1 - +1 +3 +5

Open Toolbar