All All '2.jpg': For For For End

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

CONTENT BASED IMAGE AND VIDEO RETRIEVAL

CSE 3018
FALL 19-20
ASSESSMENT 4

NAME:- Rohan Rakesh Kumar Sharma REG.NO.:- 16BCE0454

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.

Power law transformation


in_img is the input image
img = c*(in_img).^gamma;
to make image dark take value of gamma > 1, to make image bright take value of gamma < 1
Apply a clustering process (use assessment 2 procedure)
From the segmented image extract the image moments
General equation

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

-6.2653e+05 (Background area)

471.3678 444.5290 (Centroid x and y coordinates)


507.0920 545.8009

--------------------------------------------------------------------

1.4687e+06 (Foreground area) For gamma 1

-4.6874e+05 (Background area)

481.3688 551.6275 (Centroid x and y coordinates)


507.0920 545.8009

--------------------------------------------------------------------

1.3984e+06 (Foreground area) For gamma 1.5

-3.9836e+05 (Background area)

485.9098 534.7848 (Centroid x and y coordinates)


507.0920 545.8009
Screenshots:

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:

You might also like