Wednesday, April 18, 2012

Morphological Operations

Morphological Operations: Part I

Morphological Operations

This program will demonstrate the various morphological operations used in image processing. For further information please read: Gonzalez, Rafael C, Digital image processing - 3rd ed. - New Delhi Pearson Education 2009

Contents

Start

clear all;
close all;
clc;

Read the image

im = imread('coins.png');
figure; imshow(im);title('original Image');

Thresholding

this step will convert the given gray cycle image into binary image
x = im>128;
figure;imshow(x); title('Binary Image');


Defining Structuring Element

In mathematical morphology, a structuring element (s.e.) is a shape, used to probe or interact with a given image, with the purpose of drawing conclusions on how this shape fits or misses the shapes in the image. It is typically used in morphological operations, such as dilation, erosion, opening, and closing, as well as the hit-or-miss transform. (Source: Wikipedia)
Smat1 = [0 1 0; 1 1 1; 0 1 0];
Smat2 = [1 1 1; 1 0 1; 1 1 1];
SE = strel(Smat1);
figure;
subplot 121;  imshow(Smat1); title('Element1');
subplot 122;  imshow(Smat2); title('Element2');


Image Dilation

The dilation operation usually uses a structuring element for probing and expanding the shapes contained in the input image.
xdilate = imdilate(x,SE);
figure;imshow(xdilate); title('Dilated Image');


Image Erosion

Visit here: http://homepages.inf.ed.ac.uk/rbf/HIPR2/erode.htm
xerode = imerode(x,SE);
figure;imshow(xerode); title('Eroded Image');


Closing Operation

Opening operation is same as close(A,B) = erode(dilate(A,B),B) It removes noise and irregularities inside the object
xclose = imerode(imdilate(x,SE),SE);
figure;imshow(xclose); title('Closed Image');


Opening Operation

Opening operation is same as open(A,B) = dilate(erode(A,B),B) It removes background noise as well as small objects from the scene
xopen = imdilate(imerode(x,SE),SE);
figure;imshow(xopen); title('Opened Image');


Region Filling

Visit below link for more information http://www.cis.rit.edu/class/simg782/lectures/lecture_04/lec782_05_04.pdf
B=[0,1,0;1,1,1;0,1,0];
maxit = 1000;
x = xclose;
sa=size(x);
X=zeros(sa(1),sa(2));
[m start] = min(min(x==1));
X(start)=1;
Y=zeros(sa(1),sa(2));
xc= ~x;
count = 1;
while ((min(X ~= Y) == 0) & (count < maxit))
    count=count+1;
    Y=X;
    X=imdilate(Y,B) & xc;
end
figure;imshow(X); title('Region Filling');

Boundary Detection

we can detect boundaries of the objects using this technique boundary = A - (A eroded by SE);
xhat = imerode(X,SE);
boundary = ~(X-xhat);
figure; imshow(boundary); title('Boundary Detection');


(Part II: Coming soon...)

No comments:

Post a Comment