2015-10-13 327 views
0

我有一个项目来检测this图像中的轮廓线,但是当我使用Canny边缘检测算法运行我的代码时,图像中的一条线转换为两条线,这是因为两倍在该行之前和之后改变行的灰度值。MATLAB中的轮廓线边缘检测

i= imread('path'); 
imgG= rgb2gray(i); 

PSF = fspecial('gaussian',7,7); 
Blurred = imfilter(imgG,PSF,'symmetric','conv'); 
figure ,imshow(Blurred) 

edgeimg = edge(Blurred , 'canny'); 
figure ,imshow(edgeimg) 

我不知道解决这个问题,请帮助我。

回答

0

最好的答案取决于你想做的事与他们检测后的边缘,但是让我们假设你只是想生成,其中线是纯黑色和其他一切是纯白色的图像是什么...

最简单的方法是阈值图像,使灰度较浅的像素变成白色,较暗的灰色像素变成黑色。你也可以腐蚀图像尝试和减少线的粗细 - 虽然你会发现,这将摆脱你的示例图像中的精细轮廓。

这里是执行此操作的代码(假设您在工作文件夹中有图像G4.jpg)。

% load image and convert to double (0 to 1) as well as flip black and white 
imG4 = imread('G4.jpg'); 
imG4_gs = 1 - mean(double(imG4)/255,3); 

figure 
image(64*(1 - imG4_gs)) 
colormap('gray'); 
axis equal 

% image grayscale threshold 
img_thr = 0.25; 

% apply threshold to image 
imG4_thr = imG4_gs >= img_thr; 

figure 
image(64*(1 - imG4_thr)) 
colormap('gray'); 
axis equal 

% erode image (try "help imerode" in the MATLAB console) 
imG4_ero = imerode(imG4_thr,strel('disk',1)); 

figure 
image(64*(1 - imG4_ero)) 
colormap('gray'); 
axis equal;