You are on page 1of 6

NAME: SATYANSH TEWARI

REG NO: 19BCE0520


COURSE CODE: CSE3018
SLOT: L55+L56
FACULTY: VIJAYARAJAN V

Content Based Image and Video Retrieval LAB DA-6

Lab-6 Question: Design a CBIR system, that reads 100 images dataset and load all
images into its database, get a query image from the user that is apart from the
database, find the similarity between the query image with database images using
the feature described on the question (Any one of your best resulted CBIR
Experiments uploaded - Exercises from 1 to 5 and apply at least 4 different
similarity measures for your evaluation of the chosen experiment), rank the
images according to the least similarity first and display top-10 outputs. The
measures that you can use to evaluate your retrieval may be: (Choose any four
from this) Accuracy, Precision, Recall, Misclassification Rate, True Positive Rate,
False Positive Rate, False negative Rate, Positive Predictive Value, Negative
Predictive Value, F-measure, Geometric Mean, Area Under ROC Curve,
Logarithmic Score, Brier Inacuracy, Divergence, KolmogorovSmirnov Statistics,
etc. Similarity Measures can be used: Minkowski-form distance, Quadratic form
distance (Euclidean distance), Mahalanobis distance, Kullback-Leibler (KL)
Divergence and Jeffrey-Divergence (JD), Manhattan Distance, Cityblock distance
etc. (any 4 can be used for your comparison)
MATLAB CODE:
%19BCE0520 SATYANSH TEWARI
function img=loadimg
% Reading images
D = '100_Images_Lab/';
S = dir(fullfile(D,'*.jpg')); % pattern to match filenames.
% Loading query image
query_image = imread('5.jpg');
% Extracting colour planes of query image
q_red = single(query_image(:,:,1));
q_green = single(query_image(:,:,2));
q_blue = single(query_image(:,:,3));
% Table for storing the information for the images
info_table = cell2table(cell(0, 17), 'VariableNames', {'file_name', 'red_mean', 'red_std',
'red_var', 'red_skewness', 'red_kurtosis', 'green_mean', 'green_std', 'green_var',
'green_skewness', 'green_kurtosis', 'blue_mean', 'blue_std', 'blue_var', 'blue_skewness',
'blue_kurtosis', 'euclidean_distance'});
% Looping through all the images in the directory
for k = 1:numel(S)
F = fullfile(D,S(k).name);
I = imread(F);
% Plotting the image with colour plane
subplot(2, 3, 2);
imagesc(I);
title('Original image');
subplot(2, 3, 4);
imagesc(I(:,:,1));
title('Red image');
subplot(2, 3, 5);
imagesc(I(:,:,2));
title('Green image');
subplot(2, 3, 6);
imagesc(I(:,:,3));
title('Blue image');
S(k).data = I; % optional, save data.
% Extracting the colour plane of the current image
red = single(I(:, : , 1));
green = single(I(:, :, 2));
blue = single(I(:, :, 3));
% Calculating the euclidean distance between the query image and the
% current image.
euclidean_distance = sqrt((mean(q_red(:)) - mean(red(:)))^2 + (std(q_red(:)) - std(red(:)))^2 +
(var(q_red(:)) - var(red(:)))^2 + ...
(skewness(q_red(:)) - skewness(red(:)))^2 + (kurtosis(q_red(:)) - kurtosis(red(:)))^2 +
(mean(q_green(:)) - mean(green(:)))^2 + ...
(std(q_green(:)) - std(green(:)))^2 + (var(q_green(:)) - var(green(:)))^2 + (skewness(q_green(:)) -
skewness(green(:)))^2 + ...
(kurtosis(q_green(:)) - kurtosis(green(:)))^2 + (mean(q_blue(:)) - mean(blue(:)))^2 +
(std(q_blue(:)) - std(blue(:)))^2 + ...
(var(q_blue(:)) - var(blue(:)))^2 + (skewness(q_blue(:)) - skewness(blue(:)))^2 +
(kurtosis(q_blue(:)) - kurtosis(blue(:)))^2);
% Creating the input of the current image
new_row = {S(k).name, mean(red(:)), std(red(:)), var(red(:)), skewness(red(:)), kurtosis(red(:)),
mean(green(:)), ...
std(green(:)), var(green(:)), skewness(green(:)), kurtosis(green(:)), mean(blue(:)), std(blue(:)),
var(blue(:)), ...
skewness(blue(:)), kurtosis(blue(:)), euclidean_distance};
% Appending the entry in the table
info_table = [info_table;new_row];
end
% Replacing the NaN with values in the previous cell and replacing the
% rows in the table in the ascending order of euclidean_distance
info_table = sortrows(fillmissing(info_table, 'previous'), 'euclidean_distance');
writetable(info_table, 'colour_plane_slicing.xls')
% Displaying the first 5 nearest image
subplot(1, 6, 1);
imagesc(query_image);
title('Query image');
file_names = info_table(:, 'file_name').file_name; % Extracting the filenames of the images
for i = 1:5
F = fullfile(D,char(file_names(i)));
I = imread(F);
subplot(1, 6, i+1);
imagesc(I);
title(char(file_names(i)));
end
OUTPUT SCREEN:
OUTPUT:
1)

2)
3)

You might also like