Professional Documents
Culture Documents
All All '2.jpg': For For For End
All All '2.jpg': For For For End
All All '2.jpg': For For For End
CSE 3018
FALL 19-20
ASSESSMENT 4
1. Enhance the input image using power law transformation and apply a clustering algorithm
to segment the region of interest. Extract the shape based features from the segmented region.
Display the area, Centroid and orientation of the shape.
Procedure:-
Importing image in Workspace RGB to
gray
In double format
computing size m,n
Computing s = c * (r ^ gamma) where r and gamma are positive constants
Gamma Correction Array
Find area and centroids and mark it. Also find gradient to find directionality (by
setting a threshold value for highly and weak directionality using histogram).
CODE:
clear all
close all
RGB=imread('2.jpg');
I=rgb2gray(RGB);
I=im2double(I);
[m n] = size(I);
c = 2;
g =[0.5 1 1.5];% Gamma Correction Array
for r=1:length(g)
for p = 1 : m
for q = 1 : n
I3(p, q) = c * I(p, q).^ g(r);
end
end
figure, imshow(I3);title('Power-law
transformation');xlabel('Gamma='),xlabel(g(r));
[x y] = size(I3);
numPixels=x*y;
numPixels = numel(I3);
foregroundArea = sum(I3(:));
backgroundArea = numel(I3) - foregroundArea;
disp(foregroundArea);
disp(backgroundArea);
s = regionprops(I3, 'centroid');
centroids = cat(1, s.Centroid);
imshow(I3)
disp(centroids);
hold on
plot(centroids(:,1), centroids(:,2), 'r*')
hold off
end
Note: Same way we can calculate the gradient nd find the directionality. Syntax used for this will
be:
[Gmag,Gdir] = imgradient(I)
[Gmag,Gdir] = imgradient(I,method)
[Gmag,Gdir] = imgradient(Gx,Gy)
OUTPUT:
cbir_16bce0454
1.6265e+06 (Foreground area) For gamma 0.5
--------------------------------------------------------------------
--------------------------------------------------------------------
IMAGE USED:
FOR GAMMA =0.5 (we get a lighter image) (The centroid is also marked)
FOR GAMMA =1 (we get a darker image) (The centroid is also marked)
FOR GAMMA =1.5 (we get a much darker image) (The centroid is also marked)
Note: As the gamma value increases we see that image gets darker and darker.
Overall Screenshot:
Ans: Procedure : apply the lbp formula and display the resultant image.
Code:
I2=imread('bricks.png');
m=size(I2,1);
n=size(I2,2);
for i=2:m-1
for j=2:n-1
c=I2(i,j);
I3(i-1,j-1)=I2(i-1,j-1)>c;
I3(i-1,j)=I2(i-1,j)>c;
I3(i-1,j+1)=I2(i-1,j+1)>c;
I3(i,j+1)=I2(i,j+1)>c;
I3(i+1,j+1)=I2(i+1,j+1)>c;
I3(i+1,j)=I2(i+1,j)>c;
I3(i+1,j-1)=I2(i+1,j-1)>c;
I3(i,j-1)=I2(i,j-1)>c;
LBP(i,j)=I3(i-1,j-1)*2^7+I3(i-1,j)*2^6+I3(i-1,j+1)*2^5+I3(i,j+1)*2^4+I3(i+1,j+1)*2^3+I3(i+1,j)*2^2+I3(i+1,j-
1)*2^1+I3(i,j-1)*2^0;
end
end
figure();
imshow(I2);
title('Original Image')
figure();
imshow(LBP);
title('LBP feature vector image')
OUTPUT: