0

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.

Gina
  • 85
  • 10
  • Is it really a duplicate? It does talk about computing histograms but it's different directions. I can't really use that explanation to solve my problem. – Gina Mar 26 '15 at 19:49
  • I would say it's a duplicate. CBIR in this context is concerned with taking images and converting them into colour histograms. Then, given a query image, you would compute its colour histogram and compare this histogram with all of the histograms and retrieve the most similar images based on the histograms. It even talks about histogram intersection, which is what you're after. That is pretty much a duplicate to me. If this is not what you want, then please let me know and I will reopen. However, I consider the linked question as a duplicate because it essentially is doing what you're asking. – rayryeng Mar 26 '15 at 20:35
  • OK, thanks. I'll see what I can derive from there. – Gina Mar 26 '15 at 22:27

0 Answers0