Tuesday, August 13, 2013

Activity 10: Morphological Operations



So I've finally had the time to tackle this activity! I've finally posted the result of the Scilb images and code snippet. I will update the blog with my hand-drawn scans soon. Anyway on to the discussion:

Binary Images are just simply aggregates of 1's and 0's. This makes them easy to manipulate and extract information from them [1]. As such one can apply Set Theory. If you remember in Math 17, the first few topics are about sets, subsets, elements, etc, Well finally you can apply them here!

Now the table below is just a recall and basically a summary of Dr. Jing Soriano's review of Set Theory [1]:



With this, two morphological methods are used in processing binary matrices:
1.) Erosion - This essentially reduces the image to the shape of the STEL. (Structuring Element)

Mathematically, it can be represented as:

or visually:


2.) Dilation - This essentially expands/elongates the image to the shape of the STEL.

It can be mathematically represented as:
or visually:


Here is a video to further understand and visualize Dilation and Erosion [2,3] from: Smear lear's channel:










Dilation:


Erosion:



Scilab Code Snippet:
I generated the
//Square
Image1 = ones(8,8);
Image1(:,1)=0;
Image1(:,7)=0;
Image1(1,:)=0;
Image1(7,:)=0;
Image1(:,2)=0;
Image1(:,8)=0;
Image1(2,:)=0;
Image1(8,:)=0;
imwrite(Image1,'C:\Users\Phil\Desktop\Academic Folder\Academic Folder 13-14 First Sem\AP 186\Activity 10\5x5orig.bmp'); 

//Triangle
Image2 = zeros(7,7);
Image2(4,4)=1;
Image2(4,3)=1;
Image2(4,5)=1;
Image2(4,2)=1;
Image2(3,3)=1;
Image2(3,2)=1;
Image2(2,2)=1;
imwrite(Image2,'C:\Users\Phil\Desktop\Academic Folder\Academic Folder 13-14 First Sem\AP 186\Activity 10\triorig.bmp');


//Hollow Box
Image3 = zeros(12,12);
Image3(:,11) = 1;
Image3(:,2) = 1;
Image3(2,:) = 1;
Image3(11,:)= 1;
Image3(:,10) = 1;
Image3(:,3) = 1;
Image3(3,:) = 1;
Image3(10,:)= 1;
Image3(2,1)=0;
Image3(1,2)=0;
Image3(2,12)=0;
Image3(12,2)=0;
Image3(11,1)=0;
Image3(1,11)=0;
Image3(11,12)=0;
Image3(12,11)=0;
Image3(3,1)=0;
Image3(1,3)=0;
Image3(3,12)=0;
Image3(12,3)=0;
Image3(10,1)=0;
Image3(1,10)=0;
Image3(10,12)=0;
Image3(12,10)=0;
imwrite(Image3,'C:\Users\Phil\Desktop\Academic Folder\Academic Folder 13-14 First Sem\AP 186\Activity 10\hollorig.bmp');

//Cross 
Image4 = zeros(7,7);
Image4(:,4) =1;
Image4(4,:) = 1;
Image4(4,7)=0;
Image4(7,4)=0;
Image4(1,4)=0;
Image4(4,1)=0;
imwrite(Image4,'C:\Users\Phil\Desktop\Academic Folder\Academic Folder 13-14 First Sem\AP 186\Activity 10\crossorig.bmp');

MAT1 = [ %f %t %t;%f %t %t; %f %f %f];
MAT2 = [ %f %t %t;%f %f %f; %f %f %f];
MAT3 = [ %f %t %f;%f %t %f; %f %f %f];
MAT4 = [ %f %t %f;%t %t %t; %f %t %f];
MAT5 = [ %t %f %f;%f %t %f; %f %f %f];

imwrite(MAT1,'C:\Users\Phil\Desktop\Academic Folder\Academic Folder 13-14 First Sem\AP 186\Activity 10\2x2.bmp');
imwrite(MAT2,'C:\Users\Phil\Desktop\Academic Folder\Academic Folder 13-14 First Sem\AP 186\Activity 10\2x1.bmp');
imwrite(MAT3,'C:\Users\Phil\Desktop\Academic Folder\Academic Folder 13-14 First Sem\AP 186\Activity 10\1x2.bmp');
imwrite(MAT4,'C:\Users\Phil\Desktop\Academic Folder\Academic Folder 13-14 First Sem\AP 186\Activity 10\cross.bmp');
imwrite(MAT5,'C:\Users\Phil\Desktop\Academic Folder\Academic Folder 13-14 First Sem\AP 186\Activity 10\diag.bmp');

SE1 = CreateStructureElement('custom',[ %f %t %t;%f %t %t; %f %f %f]);
SE2 = CreateStructureElement('custom',[ %f %t %t;%f %f %f; %f %f %f]);
SE3 = CreateStructureElement('custom',[ %f %t %f;%f %t %f; %f %f %f]);
SE4 = CreateStructureElement('custom',[ %f %t %f;%t %t %t; %f %t %f]);
SE5 = CreateStructureElement('custom',[ %t %f %f;%f %t %f; %f %f %f]);
Rock = Image4
DI5x51 = DilateImage(Rock,SE1);
DI5x52 = DilateImage(Rock,SE2);
DI5x53 = DilateImage(Rock,SE3);
DI5x54 = DilateImage(Rock,SE4);
DI5x55 = DilateImage(Rock,SE5);
EI5x51 = ErodeImage(Rock,SE1);
EI5x52 = ErodeImage(Rock,SE2);
EI5x53 = ErodeImage(Rock,SE3);
EI5x54 = ErodeImage(Rock,SE4);
EI5x55 = ErodeImage(Rock,SE5);
imwrite(DI5x51,'C:\Users\Phil\Desktop\Academic Folder\Academic Folder 13-14 First Sem\AP 186\Activity 10\crossSE1.bmp');
imwrite(DI5x52,'C:\Users\Phil\Desktop\Academic Folder\Academic Folder 13-14 First Sem\AP 186\Activity 10\crossSE2.bmp');
imwrite(DI5x53,'C:\Users\Phil\Desktop\Academic Folder\Academic Folder 13-14 First Sem\AP 186\Activity 10\crossSE3.bmp');
imwrite(DI5x54,'C:\Users\Phil\Desktop\Academic Folder\Academic Folder 13-14 First Sem\AP 186\Activity 10\crossSE4.bmp');
imwrite(DI5x55,'C:\Users\Phil\Desktop\Academic Folder\Academic Folder 13-14 First Sem\AP 186\Activity 10\crossSE5.bmp');
imwrite(EI5x51,'C:\Users\Phil\Desktop\Academic Folder\Academic Folder 13-14 First Sem\AP 186\Activity 10\crossSE1Erode.bmp');
imwrite(EI5x52,'C:\Users\Phil\Desktop\Academic Folder\Academic Folder 13-14 First Sem\AP 186\Activity 10\crossSE2Erode.bmp');
imwrite(EI5x53,'C:\Users\Phil\Desktop\Academic Folder\Academic Folder 13-14 First Sem\AP 186\Activity 10\crossSE3Erode.bmp');
imwrite(EI5x54,'C:\Users\Phil\Desktop\Academic Folder\Academic Folder 13-14 First Sem\AP 186\Activity 10\crossSE4Erode.bmp');
imwrite(EI5x55,'C:\Users\Phil\Desktop\Academic Folder\Academic Folder 13-14 First Sem\AP 186\Activity 10\crossE5Erode.bmp');

UPDATE! Here are my hand-drawn scans. This was also good practice in preparation for the exams:


References:
[1]  Soriano, Ms. Jing, Activity 10 - Morphological Operations, 2013
[2] http://www.youtube.com/watch?v=fmyE7DiaIYQ
[3] http://www.youtube.com/watch?v=xO3ED27rMHs

No comments:

Post a Comment