Re: how to calculate histogram using one for loop
- From: Rune Allnor <allnor@xxxxxxxxxxxx>
- Date: Sat, 17 Oct 2009 02:34:03 -0700 (PDT)
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
.
- Follow-Ups:
- Re: how to calculate histogram using one for loop
- From: Bruno Luong
- Re: how to calculate histogram using one for loop
- References:
- how to calculate histogram using one for loop
- From: Jamal Mohamed
- how to calculate histogram using one for loop
- Prev by Date: Re: how to calculate histogram using one for loop
- Next by Date: Re: how to calculate histogram using one for loop
- Previous by thread: Re: how to calculate histogram using one for loop
- Next by thread: Re: how to calculate histogram using one for loop
- Index(es):
Relevant Pages
|