0

I have an image. i am calculating I,u,v components for it.

I = (R+G+B)/3

u = R-G

v= G-B;

Now , I want to find two-dimensional histograms over the chromatic information (u; v).

Thanks in advance.

mg9893
  • 11
  • 1
  • 5
  • What have you tried and where are you stuck? If I Google the title of your question there are quite a few promising looking results that I would try in the same situation. Have you done that? – YXD Nov 17 '13 at 12:52
  • basically they are passing only one paramater in hist and the other parameter is the size of the bin, whereas I want to pass two parameter when creating histogram – mg9893 Nov 17 '13 at 13:10
  • basically they are passing only one paramater in hist and the other parameter is the size of the bin, whereas I want to pass two parameter when creating histogram i.e u and v. I want to know the co occurence of (u,v) pair. secondly i have modified the code given in the link for I, u,v space but that's not giving the right solution. http://www.mathworks.in/matlabcentral/newsreader/view_thread/264526 – mg9893 Nov 17 '13 at 13:16
  • 1
    In that case you should add your modified code to the question. It would also be great if you added some example input data to work with too (you can just type in some values representing a tiny image). Say what result you expect and what you are getting instead, (or where the script is crashing and what error message you are getting). That way people trying to answer your question can see what the problem is. – YXD Nov 17 '13 at 13:37
  • Look into `hist3` if you have the right toolbox. – nkjt Nov 17 '13 at 14:07
  • This answer may be useful: http://stackoverflow.com/questions/18639518/generate-and-plot-the-empirical-joint-pdf-and-cdf-in-matlab – Luis Mendo Nov 17 '13 at 16:02
  • 1
    2d-histograms are also discussed here: http://stackoverflow.com/q/19745917/2056067 – A. Donda Nov 17 '13 at 16:46

1 Answers1

0

You can use sparse to creatre a sparse 2D matrix that counts the u-v entries.
Note that you'll have to adjust the indices in the u-v dimension to be in range 1...|u| and 1...|v| (and not negative or fractional).

[uu ui] = unique( round(u(:)) ); % adjust u index using unique command
[vv vi] = unique( round(v(:)) );
twoDhist = sparse( ui, vi, 1, numel(uu), numel(vv) );
twoDhist = spfun( @(x) x/numel(ui), twoDhist ); % normalize hist to sum to 1

figure;
imagesc( vv, uu, twoDhist ); colormap jet; colorbar; axis image 
Shai
  • 111,146
  • 38
  • 238
  • 371