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

📄 stackmor.m

📁 是一本教科书的各个章节的源程序代码,适合初学数字图像的人
💻 M
字号:
% 读取原图像
a0=imread('ic.tif');
figure(1)
imshow(a0); %如图6-11所示

%加入高斯噪声
a1=imnoise(a0,'salt & pepper', 0.02);
figure(2)
imshow(a1); %如图6-12所示

%直接进行秩排序膨胀操作
a2=ordfilt2(a1,9, ones(3));
figure(3)
imshow(a2); %如图6-13所示

c0=zeros(256);
c1=zeros(256);
c2=zeros(256);
c3=zeros(256);
c4=zeros(256);
c5=zeros(256);
c6=zeros(256);
c7=zeros(256);


%按照阈值为1进行阈值分解, 进行层叠膨胀
for j=1:255 
   b=a1;
   for i=1:65536
     if b(i)>=j
        b(i)=1;
     else 
      b(i)=0;
     end   
  end
  c0=c0+ im2double(ordfilt2(b,9, ones(3)));
end
c0=im2uint8(c0);
figure(4)
imshow(c0); %如图6-14所示

%按照阈值为2进行阈值分解, 进行层叠膨胀
for j=1:2:255
   b=a1;
   for i=1:65536
     if b(i)>=j
        b(i)=1;
     else 
      b(i)=0;
     end   
  end
   c1=c1+ im2double(ordfilt2(b,9, ones(3)));
end
c1=im2uint8(c1);
figure(5)
imshow(c1); %如图6-15所示

%直接进行秩统计排序腐蚀操作
a3= ordfilt2(a1,1, ones(3));
figure(6)
imshow(a3); %如图6-16所示

%按照阈值为1进行阈值分解, 进行层叠腐蚀
for j=1:255
   b=a1;
   for i=1:65536
     if b(i)>=j
        b(i)=1;
     else 
      b(i)=0;
     end   
  end
  c2=c2+ im2double(ordfilt2(b,1, ones(3)));
end
c2=im2uint8(c2);
figure(7)
imshow(c2); %如图6-17所示

%按照阈值为2进行阈值分解, 进行层叠腐蚀
for j=1:2:255
   b=a1;
   for i=1:65536
     if b(i)>=j
        b(i)=1;
     else 
      b(i)=0;
     end   
  end
 c3=c3+ im2double(ordfilt2(b,1, ones(3)));
end
c3=im2uint8(c3);
figure(8)
imshow(c3); %如图6-18所示

%直接进行开操作
a4= ordfilt2(a3,9, ones(3))
figure(9)
imshow(a4); %如图6-19所示

%按照阈值为1进行阈值分解, 进行层叠开操作
for j=1:255
   b=c2;
   for i=1:65536
     if b(i)>=j
        b(i)=1;
     else 
      b(i)=0;
     end   
  end
  c4=c4+ im2double(ordfilt2(b,9, ones(3)));
end
c4=im2uint8(c4);
figure(10)
imshow(c4); %如图6-20所示

%按照阈值为2进行阈值分解, 进行层叠开操作
for j=1:2:255
   b=c3;
   for i=1:65536
     if b(i)>=j
        b(i)=1;
     else 
      b(i)=0;
     end   
  end
  c5=c5+ im2double(ordfilt2(b,9, ones(3)));
end
c5=im2uint8(c5);
figure(11)
imshow(c5); %如图6-21所示

%直接进行闭操作
a5= ordfilt2(a2, 1, ones(3));
figure(12)
imshow(a5); %如图6-22所示

%按照阈值为1进行阈值分解, 进行层叠闭操作
for j=1:255
   b=c0;
   for i=1:65536
     if b(i)>=j
        b(i)=1;
     else 
      b(i)=0;
     end   
  end
  c6=c6+ im2double(ordfilt2(b,1, ones(3)));
end
c6=im2uint8(c6);
figure(13)
imshow(c6); %如图6-23所示

%按照阈值为2进行阈值分解, 进行层叠闭操作
for j=1:2:255
   b=c1;
   for i=1:65536
     if b(i)>=j
        b(i)=1;
     else 
      b(i)=0;
     end   
  end
  c7=c7+ im2double(ordfilt2(b,1, ones(3)));
end
c7=im2uint8(c7);
figure(14)
imshow(c7); %如图6-24所示

⌨️ 快捷键说明

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