Morphological Operations

Morphology is a broad set of image processing operations that process images based on shapes. Morphological operations apply a structuring element to an input image, creating an output image of the same size. In a morphological operation, the value of each pixel in the output image is based on a comparison of the corresponding pixel in the input image with its neighbors. By choosing the size and shape of the neighborhood, you can construct a morphological operation that is sensitive to specific shapes in the input image.

The most basic morphological operations are dilation and erosion. Dilation adds pixels to the boundaries of objects in an image, while erosion removes pixels on object boundaries. The number of pixels added or removed from the objects in an image depends on the size and shape of the structuring element used to process the image. In the morphological dilation and erosion operations, the state of any given pixel in the output image is determined by applying a rule to the corresponding pixel and its neighbors in the input image. ” [1]

Rules for Padding Images [1]

Operation Rule
Dilation Pixels beyond the image border are assigned the minimum value afforded by the data type.For binary images, these pixels are assumed to be set to 0. For grayscale images, the minimum value for uint8images is 0.
Erosion Pixels beyond the image border are assigned the maximum value afforded by the data type.For binary images, these pixels are assumed to be set to 1. For grayscale images, the maximum value for uint8images is 255.



Dilation and Erosion can be easily implemented in Scilab for an image given specific structuring elements (strels). Specifically, the commands are dilate(im,strel,[center]) and erode(im,strel,[center]).

The first part of the activity is predicting the resulting erosion and dilation of different images with different structuring elements.  The images used are:

1. A 5×5 square
2. A triangle, base = 4 boxes, height = 3 boxes
3. A hollow 10×10 square, 2 boxes thick
4. A plus sign, one box thick, 5 boxes along each line.
While the strels used are:
1. 2×2 ones
2. 2×1 ones
3. 1×2 ones
4. cross, 3 pixels long, one pixel thick.
5. A diagonal line, two boxes long, i.e. [0 1:1 0] .
The predictions are done manually in graphing papers and were scanned thereafter.  The predictions are shown below:

Figure 1. Predictions for the Dilation and Erosion of a Square with different structuring elements

Figure 2. Predictions for the Dilation and Erosion of a triangle with different structuring elements

Figure 3. Predictions for the Dilation and Erosion of a hollow square with different structuring elements

Figure 4. Predictions for the Dilation and Erosion of a plus with different structuring elements

After the predictions, the dilation and erosion are implemented in Scilab using the code below (see Index).  The results are shown below.  The original images are places at the upper portion whereas the strels are at the leftmost side. For the Dilation:

Figure 5. Results of Dilation of different shapes with different structuring elements

Figure 6. Results of Erosion of different shape with different structuring elements

Other morphological operations are also explored in this activity like thin and skel.  These two are easier to implement since they don’t need structuring elements unlike dilation and erosion.  The results are shown below.

Figure 7. Results of applying thin and skel on the shapes previously used

I would like to give myself a grade of 10 for doing all the required things and for following the instructions. :-)

References:

1.     Morphology Fundamentals:Dilation and Erosion.  <http://www.mathworks.com/help/toolbox>

2.     M. Soriano.  Morphological Operations. Applied Physics 186.2010

Index

Code Used:

chdir(‘C:\Users\Rob H. Entac\Documents\Acads\1st Semester 10-11\App Phy 186\Act 9′);

//Original Image

S=zeros(13,13);//Square

S(5:9,5:9)=1;

T=zeros(13,13);//Triangle

T(6:8,6)=1;

T(7:8,7)=1;

T(8,8)=1;

T(8,9)=1;

H=zeros(14,14);//Hollow

H(3:12,3:4)=1;

H(3:4,5:10)=1;

H(11:12,5:10)=1;

H(3:12,11:12)=1;

P=zeros(13,13);//Plus

P(7,5:6)=1;

P(5:9,7)=1;

P(7,8:9)=1;

//Structuring Elements

A=zeros(13,13);//2×2

A(6:7,6:7)=1;

B=zeros(13,13);//2×1

B(6:7,7)=1;

C=zeros(13,13);//1×2

C(7,6:7)=1;

cross=zeros(13,13);//cross

cross(7,6)=1;

cross(6:8,7)=1;

cross(7,8)=1;

diagonal=zeros(13,13);//diagonal

diagonal(6,8)=1;

diagonal(7,7)=1;

//Dilation

scf(1);

D = imread(‘Dilation.jpg’);

subplot(6,5,1);

imshow(D);

subplot(6,5,2);

imshow(S,[]);

subplot(6,5,3);

imshow(T,[]);

subplot(6,5,4);

imshow(H,[]);

subplot(6,5,5);

imshow(P,[]);

subplot(6,5,6);

imshow(A,[]);

subplot(6,5,7);

SdilA = dilate(S,A,[7,7]);

imshow(SdilA,[]);

subplot(6,5,8);

TdilA = dilate(T,A,[7,7]);

imshow(TdilA,[]);

subplot(6,5,9);

HdilA = dilate(H,A,[7,7]);

imshow(HdilA,[]);

subplot(6,5,10);

PdilA = dilate(P,A,[7,7]);

imshow(PdilA,[]);

subplot(6,5,11);

imshow(B,[]);

subplot(6,5,12);

SdilB = dilate(S,B,[7,7]);

imshow(SdilB,[]);

subplot(6,5,13);

TdilB = dilate(T,B,[7,7]);

imshow(TdilB,[]);

subplot(6,5,14);

HdilB = dilate(H,B,[7,7]);

imshow(HdilB,[]);

subplot(6,5,15);

PdilB = dilate(P,B,[7,7]);

imshow(PdilB,[]);

subplot(6,5,16);

imshow(C,[]);

subplot(6,5,17);

SdilC = dilate(S,C,[7,7]);

imshow(SdilC,[]);

subplot(6,5,18);

TdilC = dilate(T,C,[7,7]);

imshow(TdilC,[]);

subplot(6,5,19);

HdilC = dilate(H,C,[7,7]);

imshow(HdilC,[]);

subplot(6,5,20);

PdilC = dilate(P,C,[7,7]);

imshow(PdilC,[]);

subplot(6,5,21);

imshow(cross,[]);

subplot(6,5,22);

Sdilcross = dilate(S,cross,[7,7]);

imshow(Sdilcross,[]);

subplot(6,5,23);

Tdilcross = dilate(T,cross,[7,7]);

imshow(Tdilcross,[]);

subplot(6,5,24);

Hdilcross = dilate(H,cross,[7,7]);

imshow(Hdilcross,[]);

subplot(6,5,25);

Pdilcross = dilate(P,cross,[7,7]);

imshow(Pdilcross,[]);

subplot(6,5,26);

imshow(diagonal,[]);

subplot(6,5,27);

Sdildiagonal = dilate(S,diagonal,[7,7]);

imshow(Sdildiagonal,[]);

subplot(6,5,28);

Tdildiagonal = dilate(T,diagonal,[7,7]);

imshow(Tdildiagonal,[]);

subplot(6,5,29);

Hdildiagonal = dilate(H,diagonal,[7,7]);

imshow(Hdildiagonal,[]);

subplot(6,5,30);

Pdildiagonal = dilate(P,diagonal,[7,7]);

imshow(Pdildiagonal,[]);

//Erosion

scf(2);

E = imread(‘Erosion.jpg’);

subplot(6,5,1);

imshow(E);

subplot(6,5,2);

imshow(S,[]);

subplot(6,5,3);

imshow(T,[]);

subplot(6,5,4);

imshow(H,[]);

subplot(6,5,5);

imshow(P,[]);

subplot(6,5,6);

imshow(A,[]);

subplot(6,5,7);

SeroA = erode(S,A,[7,7]);

imshow(SeroA,[]);

subplot(6,5,8);

TeroA = erode(T,A,[7,7]);

imshow(TeroA,[]);

subplot(6,5,9);

HeroA = erode(H,A,[7,7]);

imshow(HeroA,[]);

subplot(6,5,10);

PeroA = erode(P,A,[7,7]);

imshow(PeroA);

subplot(6,5,11);

imshow(B,[]);

subplot(6,5,12);

SeroB = erode(S,B,[7,7]);

imshow(SeroB,[]);

subplot(6,5,13);

TeroB = erode(T,B,[7,7]);

imshow(TeroB,[]);

subplot(6,5,14);

HeroB = erode(H,B,[7,7]);

imshow(HeroB,[]);

subplot(6,5,15);

PeroB = erode(P,B,[7,7]);

imshow(PeroB,[]);

subplot(6,5,16);

imshow(C,[]);

subplot(6,5,17);

SeroC = erode(S,C,[7,7]);

imshow(SeroC,[]);

subplot(6,5,18);

TeroC = erode(T,C,[7,7]);

imshow(TeroC,[]);

subplot(6,5,19);

HeroC = erode(H,C,[7,7]);

imshow(HeroC,[]);

subplot(6,5,20);

PeroC = erode(P,C,[7,7]);

imshow(PeroC,[]);

subplot(6,5,21);

imshow(cross,[]);

subplot(6,5,22);

Serocross = erode(S,cross,[7,7]);

imshow(Serocross,[]);

subplot(6,5,23);

Terocross = erode(T,cross,[7,7]);

imshow(Terocross);

subplot(6,5,24);

Herocross = erode(H,cross,[7,7]);

imshow(Herocross,[]);

subplot(6,5,25);

Perocross = erode(P,cross,[7,7]);

imshow(Perocross,[]);

subplot(6,5,26);

imshow(diagonal,[]);

subplot(6,5,27);

Serodiagonal = erode(S,diagonal,[7,7]);

imshow(Serodiagonal,[]);

subplot(6,5,28);

Terodiagonal = erode(T,diagonal,[7,7]);

imshow(Terodiagonal,[]);

subplot(6,5,29);

Herodiagonal = erode(H,diagonal,[7,7]);

imshow(Herodiagonal,[]);

subplot(6,5,30);

Perodiagonal = erode(P,diagonal,[7,7]);

imshow(Perodiagonal,[]);

//Thin and Skel

scf(3);

Th = imread(‘Thin.jpg’);

Sk = imread(‘Skel.jpg’);

subplot(532);

imshow(Th);

subplot(533);

imshow(Sk);

subplot(534);

imshow(S,[]);

subplot(535);

ST = thin(S);

imshow(ST);

subplot(536);

SS = skel(S);

imshow(SS);

subplot(537);

imshow(T,[]);

subplot(538);

TT = thin(T);

imshow(TT);

subplot(539);

TS = skel(T);

imshow(TS);

subplot(5,3,10);

imshow(H,[]);

subplot(5,3,11);

HT = thin(H);

imshow(HT);

subplot(5,3,12);

HS = skel(H);

imshow(HS);

subplot(5,3,13);

imshow(P,[]);

subplot(5,3,14);

PT = thin(P);

imshow(PT);

subplot(5,3,15);

PS = skel(P);

imshow(PS);

About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: