I'm trying to calculate the histogram of images in a directory, this is what I've done:
function d = calcHist(img)
% %Compute histograms for entire collection
% % Query by example
fileName2 = 'a/b/*.png';
file2 = dir(fullfile(pwd,fileName2));
for j = 1:size(file2)
d = imread(file2(j).name);
% figure('Name','RGB Image')
% imagesc(d)
% axis image
[IND,map] = rgb2ind(d,32);
% figure('Name','Indexed image with 32 colours')
% imagesc(IND)
colormap colorcube(map)
% axis image
imhist(IND,map)
------------------------------------
%% calculate histogram for a query image
s = imread(img);
[A,cmap] = rgb2ind(s,32);
figure ('Name', 'imge')
imagesc(s)
colormap colorcube(cmap)
axis image
imhist(A,cmap)
end
Basically, what I'm trying to achieve from this function is to convert the image to histogram colours and compare two histograms(the directory image histograms and the query image histogram) which shouuld output different values from the comparison.
The first part outputs the images and their histogram and the second part outputs the histogram for the query image. I'm trying to calculate the histograms for each image in the folder/directory so I can compare them to the query image using a function which takes 2 histograms as its inputs.
I have a compare(h1,h2)
function which takes the histograms from the directory and the query image to get their intersection. The problem now is I'm not sure how to get h1 and h2 from the above code. I tried assigning a value to imhist(IND,map)
but it doesn't work. I apologise if I'm not clear enough.
Also, is it possible to use hist instead of hist? I'm not really good in MATLAb as I just started learning it sp padorn me for any mistake.