1 / 20

A MATLAB Tour of Morphological Filtering

A MATLAB Tour of Morphological Filtering. Dilation. mask B. X. >X=zeros(6,7);X(2:3,4:6)=1;X(4:5,3:5)=1; >se=[0 1;1 1]; >Y=imdilate(X,se);. _. _. Y=X B. Y=X B. Erosion. Erosion. mask B. X. >X=zeros(6,7);X(2:3,4:6)=1;X(4:5,3:5)=1; >se=[0 1;1 1]; >Y=imerode(X,se);.

gallagher
Download Presentation

A MATLAB Tour of Morphological Filtering

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. A MATLAB Tour of Morphological Filtering EE465: Introduction to Digital Image Processing

  2. Dilation mask B X >X=zeros(6,7);X(2:3,4:6)=1;X(4:5,3:5)=1; >se=[0 1;1 1]; >Y=imdilate(X,se); EE465: Introduction to Digital Image Processing

  3. _ _ Y=X B Y=X B Erosion Erosion mask B X >X=zeros(6,7);X(2:3,4:6)=1;X(4:5,3:5)=1; >se=[0 1;1 1]; >Y=imerode(X,se); EE465: Introduction to Digital Image Processing

  4. Relationship Between Dilation and Erosion _ ^ =XcB (X B)c >se1=[0 1;1 1]; >se2=fliplr(flipud(se1)); >X1=imdilate((1-X),se2) >X2=1-imerode(X,se1) EE465: Introduction to Digital Image Processing

  5. _ + Opening (X B) B X >X=zeros(6,9);X(3:5,2:4)=1; >X(3:5,6:8)=1;X(5,5)=1;X(2,7)=1 >se=strel('square',3); >Y=imdilate(imerode(X,se),se); %Y=bwmorph(X,’open’); mask B EE465: Introduction to Digital Image Processing

  6. _ + Closing (X B) B X >X=zeros(6,9);X(3:5,2:4)=1; >X(3:5,6:8)=1;X(5,5)=1;X(2,7)=1 >se=strel('square',3); >Y=imerode(imdilate(X,se),se); %Y=bwmorph(X,’close’); mask B EE465: Introduction to Digital Image Processing

  7. Relationship Between Opening and Closing >se=strel('line',10,45); >se2=fliplr(flipud(se)); >X1=~imopen(X,se); >X2=imclose(~X, se2); >isequal(X1,X2) >X1=~imclose(X,se); >X2=imopen(~X, se2); >isequal(X1,X2) EE465: Introduction to Digital Image Processing

  8. _ _ Hit-Miss Operator X B= (X B1)(Xc B2) * >bw = [0 0 0 0 0 0; 0 0 1 1 0 0; 0 1 1 1 1 0; 0 1 1 1 1 0; 0 0 1 1 0 0; 0 0 1 0 0 0] >se = [0 -1 -1; 1 1 -1; 0 1 0]; >bw2 = bwhitmiss(bw,se) X X B * origin mask B1 mask B2 EE465: Introduction to Digital Image Processing

  9. _ Boundary Extraction X=X-(X B) X X • >X=zeros(8,11);X(2:4,4:8)=1;X(5:7,2:10)=1; • > se=strel('square',3); • Y=X-imerode(X,se); %Y=imdilate(X,se)-X; EE465: Introduction to Digital Image Processing

  10. Image Example X X EE465: Introduction to Digital Image Processing

  11. Region Filling Iterations: Pseudo Codes of Region Filling expansion stop at the boundary Y0=P Yk=(Yk-1B)Xc, k=1,2,3… Terminate when Yk=Yk-1,output YkX MATLAB Codes of Region Filling EE465: Introduction to Digital Image Processing

  12. Image Example Y Z >se=strel('square',3); >r=round(size(Y,1)/2); > c=round(size(Y,2)/2); >Z=region_fill(Y,[r,c],se); EE465: Introduction to Digital Image Processing

  13. * Thinning x x x x x x x x x x x x x x x x B5 B6 B7 B8 B4 B1 B2 B3 X0=X Xk=(…( (Xk-1 B1)  B2 …  B8) where X B=X – X B Stop the iteration when Xk=Xk-1 Question unanswered on the blackboard: For B2,,…,B8, do they operate on Xk-1B1 or Xk-1? EE465: Introduction to Digital Image Processing

  14. MATLAB Implementation function y=thinning(x,iter) se{1}=[-1 -1 -1;0 1 0;1 1 1]; se{2}=[0 -1 -1;1 1 -1;1 1 0]; se{3}=fliplr(rot90(se{1})); se{4}=flipud(se{2}); se{5}=flipud(se{1}); se{6}=fliplr(se{4}); se{7}=fliplr(se{3}); se{8}=fliplr(se{2}); y=x;z=x; for i=1:iter for k=1:8 %y=y&~bwhitmiss(y,se{k}); y=y&~bwhitmiss(z,se{k}); end z=y; end Scheme A Scheme B EE465: Introduction to Digital Image Processing

  15. Which One is Right? Scheme B Original image Scheme A EE465: Introduction to Digital Image Processing

  16. Result by Using BWMORPH Scheme A Scheme B > y=bwmorph(x,’thin’,inf); EE465: Introduction to Digital Image Processing

  17. Summary of Morphological Filtering MATLAB codes circshift(A,z) fliplr(flipud(B)) ~A or 1-A A &~B imdilate(A,B) imerode(A,B) imopen(A,B) imclose(A,B) EE465: Introduction to Digital Image Processing

  18. Summary (Con’d) bwhitmiss(A,B) A&~(imerode(A,B)) region_fill.m bwmorph(A,’thin’); EE465: Introduction to Digital Image Processing

  19. MATLAB Programming Tip #1 • Use functions provided by MATLAB • Although we can implement any function from the scratch, the ones offered by MATLAB are optimized in terms of efficiency and robustness. • If you write your own function, it is safer to use a different name from the prioritized MATLAB function (>which -all) EE465: Introduction to Digital Image Processing

  20. MATLAB Programming Tip #2 • Use as few loops as possible • Example: implementation of histogram calculation • Scheme 1: loop over every position in the image, i.e., i=1-M, j=1-N • Scheme 2: loop over every intensity value, i.e., 0-255 EE465: Introduction to Digital Image Processing

More Related