2015-10-13 329 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;