1

I cannot figure out a way to create a histogram of each of the RGB colors separately without using any of the built in functions. I need to create a function called my_hist(image) that outputs three different figures each with the individual RGB value. Any amount of help will be greatly appreciated

Thanks in advance!

Rashid
  • 4,326
  • 2
  • 29
  • 54
  • by any built-in function you mean you can't use imhist, hist, bar or stem for instance? – Benoit_11 Oct 22 '14 at 15:40
  • Start by figuring out how to make a histogram (using whatever functions you are permitted) out of a matrix. Splitting an RGB image into three parts and running your personal `hist` function on each part ought to be the easy bit. – nkjt Oct 22 '14 at 15:51
  • i meant imhist or hist. – electricsurge31 Oct 22 '14 at 18:14

1 Answers1

1

If you can't use imhist, try this:

Im = imread('autumn.tif');
ImHistogram = zeros(3,256);
for jj = 1 : 3
    for ii = 0 : 255
        ImHistogram(jj,ii+1) = sum(sum(Im(:,:,jj) == ii));
    end
end

Each row shows the histogram of each RGB

However If you can use imhist you might do this:

Im = imread('autumn.tif');
ImHistogram = zeros(3,256);
for jj = 1 : 3
    ImHistogram(jj,:) = imhist(Im(:,:,jj));
end
Rashid
  • 4,326
  • 2
  • 29
  • 54
  • 2
    Here's another solution using `accumarray` that I wrote: http://stackoverflow.com/questions/25830225/content-based-image-retrieval-and-precision-recall-graphs-using-color-histograms/25830848#25830848. This computes a linear index for an RGB tuple should it fall between a certain range of colours, then uses `accumarray` to compute the histogram. It converts the histogram into a 1D array though, so you can use similarity measures in an easier way. – rayryeng Oct 22 '14 at 18:30
  • 1
    Nice answer @rayryeng. It's kind of a shame you received only 1 upvote for it. +1 for me! – Benoit_11 Oct 22 '14 at 18:55
  • 1
    @Benoit_11 merci beaucoup! I don't think it got a lot of exposure because the tag was CBIR. Still thank you for the vote :) – rayryeng Oct 22 '14 at 18:59
  • Ça fait plaisir! I guess you read my profile to know I speak french :) – Benoit_11 Oct 22 '14 at 19:04
  • @Benoit_11 - Bien sûr! Je sais que vous venez de Québec. Quelle belle province! – rayryeng Oct 22 '14 at 20:37
  • 1
    @rayryeng- Oui en effet! Très jolie et très froide avec l'hiver qui arrive! – Benoit_11 Oct 22 '14 at 20:41