0% found this document useful (0 votes)
89 views6 pages

Features Extraction May 22

This document discusses how to calculate morphological features of images such as area, perimeter, centroid, equivalent diameter, roundness, and bounding box without using MATLAB's regionprops function. It provides the mathematical equations for each feature and describes how to calculate them using pixel positions and distances. Code is presented that reads an image, calculates its binary representation, and measures these features for one labeled component by iterating through pixel positions and applying the appropriate equations.

Uploaded by

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

Features Extraction May 22

This document discusses how to calculate morphological features of images such as area, perimeter, centroid, equivalent diameter, roundness, and bounding box without using MATLAB's regionprops function. It provides the mathematical equations for each feature and describes how to calculate them using pixel positions and distances. Code is presented that reads an image, calculates its binary representation, and measures these features for one labeled component by iterating through pixel positions and applying the appropriate equations.

Uploaded by

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

Find Area, Perimeter, Centroid, Equivdiameter, Roundness

and Bounding Box without Using MATLAB Function


‘regionprops’
Table 1: Morphological Features and their Mathematics
Morphological Features Mathematical Equations Descriptions
Area (A) Total amount of Pixel of image The total Number of pixel in the
image
Perimeter (P) The amount of Pixel at the The total amount of pixel at the
boundary of the image boundary of an image which
differentiate the regular image
from irregular image
Maximum Radius (MAX_R) The maximum distance between To calculate maximum distance
center and boundary of an image. between center of an image to the
MAX(DISTANCE(C(x,y), boundary of an image
BOUNDARY(x,y)))
Minimum Radius(MIN_R) The minimum distance between To calculate minimum distance
center and boundary of an image. between center of an image to the
MIN(DISTANCE(C(x,y), boundary of an image. where x
BOUNDARY(x,y))) and y are points on the image
Eccentricity (ECT) 𝑀𝐼𝑁_𝑅 2 It is used for the lengthening of
√1 − ( ) an image
𝑀𝐴𝑋_𝑅
Equivdiameter (EQD) It is used to calculate diameter of
𝐴𝑟𝑒𝑎
√4 ∗ a circle which has same area as
𝜋 an image
Elongatedness(EN) 𝐴𝑟𝑒𝑎 Elogatendness of an image is
( )
(2 ∗ 𝑀𝐴𝑋_𝑅)2 ratio of length of an image to its
thickness square.
Entropy (ENTPY) 2 It is a statistical measure of
∑(𝑝 ∗ 𝑙𝑜𝑔2 (𝑝))
randomness which is used to
characterize the texture of the
image.
Circularity1 (C_1) It is used to show how an image
𝐴𝑟𝑒𝑎
√ is resemble as circle
𝜋 ∗ 𝑀𝐴𝑋_𝑅2
Circularity1 (C_2) It is used to show how an image
𝑀𝐼𝑁_𝑅
√ is resemble as ellipse
𝑀𝐴𝑋_𝑅
Compactness (CN) 2 ∗ √𝐴𝑟𝑒𝑎 ∗ 𝜋 It is used to calculate the degree
( ) of deviation of an image from a
𝑃𝑒𝑟𝑖𝑚𝑒𝑡𝑒𝑟
Perfect Circle
Dispersion (DP) 𝑀𝐴𝑋_𝑅 It is used to measure the
( )
𝐴𝑟𝑒𝑎 irregularity of an image

Thinness Ratio (TR) 4 ∗ 𝜋 ∗ 𝐴𝑟𝑒𝑎 It is used to differentiate the


( )
𝑝𝑒𝑟𝑖𝑚𝑒𝑡𝑒𝑟 2 circle and the line from other
image
Standard Deviation of Image 𝑛 It is used to measure the average
(SD) 1 contrast of an image
√ ∑(𝑥𝑖 − 𝑥̅ )2
𝑛
𝑖=1

Standard Deviation of 𝑚
It is used to measure the average
Edge (ESD) 1 contrast of an image Boundary
√ ∑(𝑦𝑖 − 𝑦̅)2
𝑚
𝑖=1
Shape Index (SI) 𝑃𝑒𝑟𝑖𝑚𝑒𝑡𝑒𝑟 It is relates to curved states of an
( )
2 ∗ 𝑀𝐴𝑋_𝑅 image

n is the number of pixel in the image


m is the number of pixel in image’s boundary
𝑥̅ is the mean of the image
𝑦̅ is the mean of the image’s boundary
p is the probability count

In MATLAB, the function ‘regionprops’ is used to measure the image


properties. Here are some basic properties computed without using the function.
Read an image and find the connected components using ‘bwlabel’
function.
Using the Labeled matrix as an input, the properties can be measured.
Example:
A=[1 0 0 1
1111
0 0 1 1]
To find Area:
• The total number of ‘ON’ pixels in the image.
The number of ones in the matrix is 8.

To find Centroid:
• Find the row and column having pixel value one.
Eg.[row,column]=find(label==1)
Row=[ 1 2 2 2 3 1 2 3]
Column=[ 1 1 2 3 3 4 4 4]

• Find the mean of the row and column having pixel value one.
Mean of Row=2 and mean of column= 2.75

To find the Bounding Box:


• We need 4 points, starting position(x,y) , length and breadth.
• Minimum value of row and column minus 0.5 gives starting position(x,y)
respectively
• Minimum value of row=1-0.5=0.5
• Minimum value of column=1-0.5=0.5
• Maximum value of column – minimum value of column+1 gives breadth of the
box
• Maximum value of column=4
• Max value-min value of column=3+1
• Maximum value of row- minimum value of row +1gives length of the box
• maximum value of row=3
• Max value – Min value=2+1
• Bounding Box value for the given example:0.5000 0.5000 4.0000 3.0000
• For more details on how to draw a rectangle check
here: http://angeljohnsy.blogspot.in/2011/06/how-to-draw-in-matlab.html

To find the Perimeter


• Find the boundary of the labeled component
Boundary pixels:
1 1
2 2
2 3
1 4
2 4
3 4
3 3
2 2
2 1
1 1
• Find the distance between the each adjoining pair of pixels around the border of
the region.

• Use the distance formula:

• For instance, calculate the distance between the two points (1,1) and (2,2).
distance=sqrt((2-1).^2+(2-1).^2)=1.41
• Similarly, the distance is computed for all the pixel positions.
• The perimeter for the given example is 10.2426

To find the Roundness:


• Roundness of an object can be determined using the formula:
Roundness=(4*Area*pi)/(Perimeter.^2)
If the Roundness is greater than 0.90 then, the object is circular in shape.
Result= (4*8*3.14)/10.2426.^2=0.9582

To find the Equivdiameter


• Formula: sqrt(4*Area/pi).
Equivdiameter for the given example:3.1915

MATLAB CODE:
%Measure Basic Image Properties without using 'regionprops' function
%Measure Area, Perimeter, Centroid , Equvidiameter, Roundness and Bounding Box
clc
%Read Original Image
I=imread('coins.png');
%Convert to Binary
B=im2bw(I);

%Fill the holes


C=imfill(B,'holes');

%Label the image


[Label,Total]=bwlabel(C,8);
%Object Number
num=4;
[row, col] = find(Label==num);

%To find Bounding Box

sx=min(col)-0.5;
sy=min(row)-0.5;
breadth=max(col)-min(col)+1;
len=max(row)-min(row)+1;
BBox=[sx sy breadth len];
display(BBox);
%Refer:http://angeljohnsy.blogspot.in/2011/06/how-to-draw-in-matlab.html
figure,imshow(I);
hold on;
x=zeros([1 5]);
y=zeros([1 5]);
x(:)=BBox(1);
y(:)=BBox(2);
x(2:3)=BBox(1)+BBox(3);
y(3:4)=BBox(2)+BBox(4);
plot(x,y);

%Find Area
Obj_area=numel(row);
display(Obj_area);
%Find Centroid
X=mean(col);
Y=mean(row);
Centroid=[X Y];
display(Centroid);
plot(X,Y,'ro','color','r');
hold off;

%Find Perimeter
BW=bwboundaries(Label==num);
c=cell2mat(BW(1));
Perimeter=0;
for i=1:size(c,1)-1
Perimeter=Perimeter+sqrt((c(i,1)-c(i+1,1)).^2+(c(i,2)-c(i+1,2)).^2);
end
display(Perimeter);

%Find Equivdiameter
EquivD=sqrt(4*(Obj_area)/pi);
display(EquivD);

%Find Roundness
Roundness=(4*Obj_area*pi)/Perimeter.^2;
display(Roundness);

%Calculation with 'regionprops'(For verification Purpose);


%Sdata=regionprops(Label,'all');
%Sdata(num).BoundingBox
%Sdata(num).Area
%Sdata(num).Centroid
%Sdata(num).Perimeter
%Sdata(num).EquivDiameter
Table 1: Texture features

S# Features Formulas Description


1 Contrast 𝑁−1 It is used to calculate the intensity contrast b/w a pixel and
∑ 𝑃𝑥,𝑦 (𝑥 − 𝑦)2 its neighbor one of the whole image
𝑥,𝑦=0
2 Correlation 𝑁−1 It is used to calculate the degree of correlation b/w pixel
(𝑥 − 𝜇𝑥 )(𝑦 − 𝜇𝑦 ) and its neighbor one of the whole image
∑ 𝑃𝑥,𝑦
𝑥,𝑦=0 √(𝜎𝑥2 )(𝜎𝑦2 )
[ ]
𝑁−1
3 Dissimilarity To calculate the difference in images
∑ 𝑃𝑥,𝑦 |𝑥 − 𝑦|
𝑥,𝑦=0
4 Energy 𝑁−1 It is used to calculate the uniformity of an image
2
∑ 𝑃𝑥,𝑦
𝑥,𝑦=0
𝑁−1
5 Entropy It is used to calculate the information encoded in the image
∑ 𝑃𝑥,𝑦 (−𝑙𝑛𝑃𝑥,𝑦 )
𝑥,𝑦=0
6 Homogeneity 𝑁−1 It is used to calculate the spatial closeness of the
𝑃𝑥,𝑦
∑ distribution of elements in G to the diagonal.
1 + (𝑥 − 𝑦)2
𝑥,𝑦=0
7 Mean 𝜇𝑥 = ∑𝑁−1
𝑥,𝑦=0 𝑥 (𝑃𝑥,𝑦 ) & 𝜇𝑦 = It is used to calculate the sum of all possible images and P
∑𝑁−1 is the probability mass function.
𝑥,𝑦=0 (𝑃𝑥,𝑦 )
𝑦
8 Variance 𝜎𝑥2 = ∑𝑁−1
𝑥,𝑦=0 𝑃𝑥,𝑦 (𝑥 − 𝜇𝑥 )
2
& It is used to calculate how far a set of (random) numbers
2 are spread out from their mean
𝜎𝑦2 = ∑𝑁−1
𝑥,𝑦=0 𝑃𝑥,𝑦 (𝑦 − 𝜇𝑦 )

9 Standard 𝜎𝑥 = √𝜎𝑥2 & 𝜎𝑦 = √𝜎𝑦2 It is used to calculate to quantify the amount of variation
Deviation or dispersion of a set of data values

You might also like