Professional Documents
Culture Documents
LAB ASSIGNMENT-3
Name : Asmit Gupta
Reg No : 18BCE0904
Lab Slot : L55+L56
Faculty : Prof. VIJAYARAJAN V
Code:-
function img=asmitlab3 % function definition
imagefolder='/MATLAB Drive/assignment1/'; %current folder location
fileextension='.jpg'; %file type
img=cell(1);% defining a cell to store images
foldercontent=dir([imagefolder,'*',fileextension]); %creating a folder variable
n=size(foldercontent,1);%size of the folder
[filename, path] = uigetfile(fullfile('./','.jpg')) ;
query_image = imread(fullfile(path, filename));
imshow(query_image);
as = imresize(query_image,[256, 256],'nearest');
% gray_query=rgb2gray(as);
% Red channel color moment
query_m1_R = mean2(as(:,:,1)); % mean
query_m2_R = std2(as(:,:,1)); % standard deviation
query_m3_R = skewness(im2double(as(:,:,1))); % Skewness
% Green channel color moment
query_m1_G = mean2(as(:,:,2));
query_m2_G = std2(as(:,:,2));
query_m3_G = skewness(im2double(as(:,:,2)));
% Blue channel color moment
query_m1_B = mean2(as(:,:,3));
query_m2_B = std2(as(:,:,3));
query_m3_B = skewness(im2double(as(:,:,3)));
query_color_moment = [query_m1_R, query_m2_R, query_m3_R, query_m1_G, query_m2_G,
query_m3_G, query_m1_B, query_m2_B, query_m3_B];
% color histogram
% convert images to type double (range from from 0 to 1 instead of from 0 to255)
Im1 = im2double(as);
hn1 = imhist(Im1)./numel(Im1); % Calculate the Normalized Histogram
for i=1:n
disp(i);%to display the image loading
string = [imagefolder,foldercontent(i,1).name];%get the complete path of each
image
image =imread(string); %image reading using imread()
img{i,1}=string; %curley braces used to store cell values created bycell in first
column
img{i,2}=image;%store all R,G,B images in to second column
img{i,3}=imresize(image,[256, 256],'nearest'); % img{i,4}=rgb2gray(img{i,3});
%store gray scale images in third column
% color histogram
Im2 = im2double(img{i,3});
hn2 = imhist(Im2)./numel(Im2); % Calculate the Normalized Histogram
img{i,5}=sum((hn1 - hn2).^2); % Calculate the histogram error