⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 quyutianchong.m

📁 这里是我自己编的区域填充源程序
💻 M
字号:
clc;
clear;
AC=[0 0 0 0 0 0 0
    0 0 1 1 0 0 0
    0 1 0 0 1 0 0
    0 1 0 0 1 0 0
    0 0 1 0 1 0 0
    0 0 1 0 1 0 0
    0 1 0 0 0 1 0
    0 1 0 0 0 1 0
    0 1 1 1 1 0 0
    0 0 0 0 0 0 0];
figure,subplot(4,4,1),imshow(AC);
[width,height]=size(AC);
A=1-AC;
subplot(4,4,2),imshow(A);
B=[0 1 0;1 1 1;0 1 0];
sorigin=[2 2];
subplot(4,4,3),imshow(B);


resulttu= zeros(width,height);
resulttu(3,3) =1;
subplot(4,4,4),imshow(resulttu);
imtemp=zeros(width,height);
h=1;
k=2;
while h
    [sw,sh]=size(B);
    if isempty(find(B==1))
       return;    
    end
    for i=2:1:width-(sw-2)
        for j=2:1:height-(sh-2)
            if B(2,2)==resulttu(i,j)
               for Bi=1:1:sw
                   for Bj=1:1:sh
                       if B(Bi,Bj)==1
                          if resulttu(i-1+Bi,j-1+Bj)==0
                          imtemp(i-2+Bi,j-2+Bj)=1;
                          end
                       end
                   end
               end
            end
            
        end
    end
    
    
    
    for i=1:1:width
        for j=1:1:height
            if A(i,j)==imtemp(i,j)
               resulttu(i,j)=imtemp(i,j);  
            end
        end
    end
    bb(:,:,k-1)=resulttu;
    if bb(:,:,k)==bb(:,:,k-1)
    h=0;    
    end
    k=k+1;
end
subplot(4,4,5),imshow(bb(:,:,1));
subplot(4,4,6),imshow(bb(:,:,2));
subplot(4,4,7),imshow(bb(:,:,4));
subplot(4,4,8),imshow(bb(:,:,5));
subplot(4,4,9),imshow(bb(:,:,6));
    subplot(4,4,10),imshow(resulttu);
    aa=1-resulttu
    for i=1:1:width
        for j=1:1:height
            if A(i,j)==1&aa(i,j)==0
               A(i,j)=0;    
            end
        end
    end
subplot(4,4,11),imshow(A);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -