From: Naved Nouyed on
"Bruno Luong" <b.luong(a)fogale.findmycountry> wrote in message <hu1df0$1ur$1(a)fred.mathworks.com>...
> That's better. Now serious thing begin. Here is how you can compute the same thing with HISTC
>
> % Save this function in histogram1.m
> %
> function Hlocal = local_histogram1(lgbp, nregion, nbin)
> Hlocal = cellfun(@(img) lochist1(img, nregion, nbin), lgbp, 'unif', false);
> end % local_histogram1
>
> %%
> function h = lochist1(img, nregion, nbin)
> % h is dimension nbin x nregion
>
> [rows cols] = size(img);
> rsize = ( rows * cols ) / nregion;
> rrows = sqrt(rsize);
> rcols = sqrt(rsize);
>
> nrrow = rows/rrows;
> nrcol = cols/rcols;
> lgbp_r = reshape(img, [rrows nrrow rcols nrcol]);
> lgbp_r = permute(lgbp_r, [1 3 4 2]);
> lgbp_r = reshape(lgbp_r, [rrows*rcols nrrow nrcol]);
>
> h = histc(lgbp_r,1:nbin);
> h = reshape(h, [nbin nrrow*nrcol]);
>
> end % lochist1
>
> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
> %% Now, Do this on command window to check the results are identical
> %%
>
> % Example of Data
> lgbp=peaks(128);
> maximg = max(lgbp(:));
> minimg = min(lgbp(:));
> lgbp = floor(256*(lgbp-minimg)/(maximg-minimg));
>
> nregion=64;
> nbin=256;
> tic
> Hlocal1 = local_histogram1({lgbp}, nregion, nbin);
> toc
>
> tic
> Hlocal2 = local_histogram({lgbp}, 1, 1, nregion, nbin);
> toc
>
> clf
> v = 1;
> mu = 1;
> r = 18;
> plot(Hlocal1{v,mu}(:,r),'r.')
> hold on
> plot(Hlocal2{v,mu,r},'b')
>
> % Bruno

Thanks a lot. Yes, both graphs are identical, points plot along the line. I've also tried the following way, what do you think about the following code ? Thanks again.


for v = 1:nscale
for mu = 1:norient
for r = 1:nregion
for i = 1:nbin
z = lgbp_r{v,mu,r} - i;
Hlocal{v,mu,r}(i) = length(find(z == 0));
end
end
end
end
From: Bruno Luong on
"Naved Nouyed" <iqbalnaved(a)gmail.com> wrote in message <hu1f79$q2a$1(a)fred.mathworks.com>...

>
> Thanks a lot. Yes, both graphs are identical, points plot along the line. I've also tried the following way, what do you think about the following code ? Thanks again.
>
>
> for v = 1:nscale
> for mu = 1:norient
> for r = 1:nregion
> for i = 1:nbin
> z = lgbp_r{v,mu,r} - i;
> Hlocal{v,mu,r}(i) = length(find(z == 0));
> end
> end
> end
> end

That's fine, but
1. this is not suboptimal on the complexity side O(m*n), because HISTC has better complexity, of O(m*log(n), where m number of points and n number of bins
2. Use CELL in Matlab is always slow; rather prefer multi-dimensional arrays.
3. Vectorize your code: use Matlab built-in functions when you can. It's not evident for newcomer issued from other language to dis-intoxicate on for-loop. But if you can do that, you will benefit a lot from Matlab.

Bruno
From: Naved Nouyed on
Thanks for the tips. I'll try to follow your recommendations from now on. Could you please take a look at the following thread, I am also trying to vectorize the LGBP conversion but this is also seems a bit difficult. Thank you.

http://www.mathworks.fr/matlabcentral/newsreader/view_thread/283543
"Bruno Luong" <b.luong(a)fogale.findmycountry> wrote in message <hu1g7l$2s8$1(a)fred.mathworks.com>...
> "Naved Nouyed" <iqbalnaved(a)gmail.com> wrote in message <hu1f79$q2a$1(a)fred.mathworks.com>...
>
> >
> > Thanks a lot. Yes, both graphs are identical, points plot along the line. I've also tried the following way, what do you think about the following code ? Thanks again.
> >
> >
> > for v = 1:nscale
> > for mu = 1:norient
> > for r = 1:nregion
> > for i = 1:nbin
> > z = lgbp_r{v,mu,r} - i;
> > Hlocal{v,mu,r}(i) = length(find(z == 0));
> > end
> > end
> > end
> > end
>
> That's fine, but
> 1. this is not suboptimal on the complexity side O(m*n), because HISTC has better complexity, of O(m*log(n), where m number of points and n number of bins
> 2. Use CELL in Matlab is always slow; rather prefer multi-dimensional arrays.
> 3. Vectorize your code: use Matlab built-in functions when you can. It's not evident for newcomer issued from other language to dis-intoxicate on for-loop. But if you can do that, you will benefit a lot from Matlab.
>
> Bruno