Skip to content

Morphological Algorithm

Aim:- Morphological Algorithm
MSc Computer Science Image Processing Practical No. 7
Index of all Practicals ~ Click Here

Code:- Morpho_algo.m

clc;clear all;close all;

% original image

x = imread(‘rice.png’);
imshow(x)
title(‘Input Image’)

% color map

figure;
imshow(x);
colormap jet;
title(‘Jet color map’);

% background estimation (non uniform illumination)

bg = imopen(x,strel(‘disk’,10));
figure;
imshow(bg);
colormap jet;
title Background;

% background removal (flatten background level)

y = imsubtract(x,bg);
figure;
imshow(y);
title Flattened;

%segment grains from background

bw = im2bw(y,graythresh(y));
figure
imshow(bw)
title GrayThreshed

%label connected regions

L = bwlabel(bw);
figure
imshow(L,[])
colormap jet
pixval
title(‘Connected Regions’)

%feature extraction – size distribution (area, pixels)

stats = regionprops(L);
A = [stats.Area];
figure
hist(A)
xlabel(‘Area (pixels)’)
ylabel Popularity
title(‘Size Distribution’)

%statistical measurements

mean(A)
std(A)
median(A)

Output:-
 On Command Window:-

ans =
  177.1500

ans =
   69.0883

ans =
  189.5000

Leave a Reply

Your email address will not be published. Required fields are marked *

error: Content is protected !!