0

我有以下二进制图像: 在此处输入图像描述

我最终想要得到的是: 在此处输入图像描述 有没有人有解决它的想法?非常感谢!

4

1 回答 1

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
于 2013-10-27T05:58:41.053 回答