Re: how to calculate histogram using one for loop



On 17 Okt, 11:05, "Jamal Mohamed" <in.ja...@xxxxxxxxx> wrote:
hi everybody

already i calculated  histogram for a image like following code [ only calculation part]
[row, col] =size(I);
h = zeros(256, 1);
for i=1:row
for j=1:col
Z=I(i,j);           % I is image
h(Z+1)=h(Z+1)+1;
end
end

The above is the conceptually correct solution.

my question is how to calculate histogram using one for loop

You can exploit the fact that matlab stores the image
as a NxM continuous block of memory, and write something
like

II = I(:);

Now II is a N*M x 1 vector. But do note that there is
nothing to gain by this:

1) II has to be allocated in memoy
2) The data has to be transferred from I to II
3) II takes as much space as I

So this approach requires twice the memory footprint
and requires several times as much time the method you
already use. There is no reason why you would want to
do this as just one loop.

Rune
.



Relevant Pages

  • Re: Two envelopes and game theory
    ... >>> switching. ... One will gain 2^n ... >>other posters) the gain expectation from switching envelopes is 0. ... >>simply made a wrong conditional probability calculation. ...
    (sci.math)
  • Re: The GPS GR correction.
    ... opposed to the one that's in your head which doesn't. ... gain thus speed gain using the work energy theorem, ... I see you have no answer for the errors in your calculation, ...
    (sci.physics.relativity)
  • Re: Diff amp gain in AoE example
    ... I calculated the gain to be a tiny bit less than 210. ... Hint: that 1k ... Buy that man a beer, I took the case that the non-inverting side was ... Apart from the wrong calculation of the gain this design will IMHO suffer ...
    (sci.electronics.design)
  • Re: Sum a Column
    ... I've input my gain for July but because we are already beyond ... the calculation has moved on to the August period. ... I add a new figure to the bottom of the list. ... I've learned to reference the new figure using: ...
    (microsoft.public.excel)