0% found this document useful (0 votes)
42 views4 pages

All All 'Football - JPG': %morphological Operations

This document discusses image morphology operations using MATLAB. It loads an image of a football and converts it to binary. It then performs dilation, erosion, closing, and opening on the image using a 3x3 structuring element both with and without built-in functions. The results are displayed in subplots to show the effect of each morphological operation on the image.

Uploaded by

Sanket Patil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views4 pages

All All 'Football - JPG': %morphological Operations

This document discusses image morphology operations using MATLAB. It loads an image of a football and converts it to binary. It then performs dilation, erosion, closing, and opening on the image using a 3x3 structuring element both with and without built-in functions. The results are displayed in subplots to show the effect of each morphological operation on the image.

Uploaded by

Sanket Patil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

IMAGE MORPHOLOGY

%Morphological operations

clc;
clear all;
close all;
A=imread('football.jpg');
B=im2bw(A);
subplot(2,3,1);
imshow(B);
title('Original image');
SE=[1 1 1;1 1 1;1 1 1];
D=imdilate(B,SE);
subplot(2,3,2);
imshow(D);
title('Dilated image');

E=imerode(B,SE);
subplot(2,3,3);
imshow(E);
title('Eroded image');

C=imclose(B,SE);
subplot(2,3,4);
imshow(C);
title('Closed image');

O=imopen(B,SE);
subplot(2,3,5);
imshow(O);
title('Opened image');
figure;
IMAGE MORPHOLOGY

%Without inbuilt functions

A=imread('football.jpg');
B=im2bw(A);
subplot(2,3,1);
imshow(B);
title('Original image');
SE=[1 1 1;1 1 1;1 1 1];
[r c]=size(B);

P1=zeros(3,3);
P2=zeros(3,3);

for x=2:r-1
for y=2:c-1
P=[B(x-1,y-1)*SE(1) B(x,y-1)*SE(2) B(x+1,y-1)*SE(3)
B(x-1,y)*SE(4) B(x,y)*SE(5) B(x+1,y)*SE(6) B(x-1,y+1)*SE(7)
B(x,y+1)*SE(8) B(x+1,y+1)*SE(9)];
P1(x,y)=max(P);
P2(x,y)=min(P);
end
end
P3=zeros(3,3);
[r c]=size(P1);
IMAGE MORPHOLOGY

for x=2:r-1
for y=2:c-1
Pq=[P1(x-1,y-1)*SE(1) P1(x,y-1)*SE(2) P1(x+1,y-1)*SE(3) P1(x-
1,y)*SE(4) P1(x,y)*SE(5) P1(x+1,y)*SE(6) P1(x-1,y+1)*SE(7)
P1(x,y+1)*SE(8) P1(x+1,y+1)*SE(9)];
P3(x,y)=min(Pq);
end
end
P4=zeros(3,3);

[r c]=size(P2);
for x=2:r-1
for y=2:c-1
Pqq=[P2(x-1,y-1)*SE(1) P2(x,y-1)*SE(2) P2(x+1,y-1)*SE(3) P2(x-
1,y)*SE(4) P2(x,y)*SE(5) P2(x+1,y)*SE(6) P2(x-1,y+1)*SE(7)
P2(x,y+1)*SE(8) P2(x+1,y+1)*SE(9)];
P4(x,y)=max(Pqq);
end
end

subplot(2,3,2);
imshow(P1);
title('Dilated image');
subplot(2,3,3);
imshow(P2);
title('Eroded image');
subplot(2,3,4);
imshow(P3);
title('Closed image');
subplot(2,3,5);
imshow(P4);
title('Opened image');

Without inbuilt function

With inbuilt function


IMAGE MORPHOLOGY

You might also like