2012-08-03 25 views
0

我有以下的二值圖像: enter image description here獲得形狀的框架上的二進制圖像MATLAB

我試圖獲得最終是這樣的: enter image description here 沒有人有解決它的想法? 非常感謝!

+0

可以使用實驗的[ Canny邊緣檢測器](http://en.wikipedia.org/wiki/Canny_edge_detector)以及非最大抑制。這些[講義幻燈片](http://www.cs.illinois.edu/class/sp12/cs543/lectures/Lecture%2006%20-%20Edge%20Detection%20-%20Vision_Spring2012.pdf「Edge Detection,UIUC CS 543 「)也可能對你有用,從第29頁左右開始。 – cyang 2012-08-03 15:37:01

+0

matlab中的幾個'edge'探測器也是如此。只需查看「邊緣」功能即可。配合「bwmorph」,你應該能夠解決問題。否則,您可能需要創建自己的過濾器,並將「imdilate」和「imerode」與特別設計的結構元素結合使用。 – 2012-08-03 16:28:30

+0

考慮到圖像中的缺陷,我會專注於找出填充字符的可靠方法,然後使用邊緣檢測器或形態學操作來查找邊界。在損壞的圖像上應用邊緣檢測可能會拾取角色內部缺陷的邊緣,這是您不想要的。 – sfstewman 2012-08-03 21:40:36

回答

0

對於這個問題,我們假設字母在黑色背景(0)上是白色的(1)。 (即,圖像的外側是黑色)

以下MATLAB腳本使用腐蝕,膨脹的組合工作,填充和AND/OR/NOT邏輯運算:

 %This script assumes the input image is a binary bitmap image 
    %Otherwise use: 
    %BW = logical(BW); after loading grayscale image with BW = imread(filename); 

    BW = imread('img.bmp'); %read in the image 
    figure 
    imshow(BW) %show original image 

    %for the outside edges 
    BW2 = imfill(BW, 'holes'); %fill holes in letters 
    BW3 = imerode(BW2, strel('disk',1)); 
    BW4 = BW2 & (~BW3); %outside boundary of letters (8 connected) 
    figure 
    imshow(BW4) %show outside edges 

    %for the inside edges 
    BW2 = imerode(BW3, strel('disk',1)); %erode filled letters again 
    BW3 = ~(BW & BW2); %logical AND operation of original image and doubly eroded filled letter image 
    BW2 = ~imfill(BW3,1); %fill image with white (1), starting at 1,1 leaves 
    BW3 = imfill(BW2, 'holes'); %fill inner holes 
    BW2 = BW3 & (~BW2); %logical operation to isolate inner holes 
    BW3 = imdilate(BW2,strel('disk',1))-BW2; %boundary of inner edges 

    BW2 = BW3 | BW4; %logical OR operation to obtain inside and outside edges 
    figure 
    imshow(BW2) %final image