From: Bruno Luong on 31 May 2010 09:32 "Naved Nouyed" <iqbalnaved(a)gmail.com> wrote in message <hu0d09$pei$1(a)fred.mathworks.com>... > > > is it this doable, if I perform LBP on the image then get the histogram of the total image and then separate the local histograms? I think so. But your description of the task is - sorry to say - sloppy, so it's hard be sure. Bruno
From: Naved Nouyed on 31 May 2010 10:36 "Bruno Luong" <b.luong(a)fogale.findmycountry> wrote in message <hu0dok$eka$1(a)fred.mathworks.com>... > "Naved Nouyed" <iqbalnaved(a)gmail.com> wrote in message <hu0d09$pei$1(a)fred.mathworks.com>... > > > > > > is it this doable, if I perform LBP on the image then get the histogram of the total image and then separate the local histograms? > > I think so. But your description of the task is - sorry to say - sloppy, so it's hard be sure. > > Bruno Thanks Bruno. Sorry about the vague description, let me try to elaborate my task, I am trying to encode Gabor filtered images through local binary patterns and local histograms. For a normalized face image, it is first convoluted with all the 40 Gabor filters ( 5 sclaes and 8 orientations ) and Gabor filtered images with the same size as the original face image is obtained. Then these images are further processed by LBP, which results in 40 LGBP images. Thereafter, LGBP images are divided spatially to multiple subwindows and histograms are estimated from them, to form the final representation of the input face image. Though I have been able to code the entire thing but it lacks efficiency at computing the local histograms because of all these for loops I believe. I am posting the total function here for your consideration. If you please write up a little bit of your ideas (in pseudocode or MATLAB ) specifically for this problem it will be very helpful for me. Thanks again. function Hlocal = local_histogram(lgbp, nscale, norient, nregion, nbin) %LGBP_Mag [rows cols] = size(lgbp{1,1}); % image size 128x128 rsize = ( rows * cols ) / nregion; % region size (128*128)/64=256 rrows = sqrt(rsize); % number of rows in each region sqrt(256)=16 rcols = sqrt(rsize); % number of cols in each region sqrt(256)=16 % the LGBP image is spatially partitioned into multiple nonoverlapping % regions with the same size lgbp_r = cell(nscale,norient,nregion); for v = 1:nscale for mu = 1:norient for r = 1:nregion lgbp_r{v,mu,r} = zeros(rrows,rcols); end end end tic for v = 1:nscale for mu = 1:norient for r = 1:nregion x=1; for i=1:(rows/rrows)-1 % rows is divided into 128/16=8 regions y=1; for j=1:(cols/rcols)-1 % cols is divided into 128/16=8 regions lgbp_r{v,mu,r}(1:rrows,1:rcols) = lgbp{v,mu}(x:x+rrows-1,y:y+rcols-1); y = y + rcols; end x = x + rrows; end end end end toc % histogram is extracted from each region, this method is called 'local % hisograms' Hlocal = cell(nscale,norient,nbin); for v = 1:nscale for mu = 1:norient for r = 1:nregion Hlocal{v,mu,r} = zeros(1,nbin); end end end tic for v = 1:nscale for mu = 1:norient for r = 1:nregion for i = 1:nbin for x = 1:rrows for y = 1:rcols Hlocal{v,mu,r}(i) = Hlocal{v,mu,r}(i) + delta(lgbp_r{v,mu,r}(x,y) - i); end end end end end end toc end function d = delta(z) if(z == 0) d = 1; else d = 0; end end
From: Bruno Luong on 31 May 2010 14:31 Your function is odd, I strongly suspect it has a bug: > for r = 1:nregion > x=1; > for i=1:(rows/rrows)-1 % rows is divided into 128/16=8 regions > y=1; > for j=1:(cols/rcols)-1 % cols is divided into 128/16=8 regions > lgbp_r{v,mu,r}(1:rrows,1:rcols) = lgbp{v,mu}(x:x+rrows-1,y:y+rcols-1); > y = y + rcols; > end > x = x + rrows; > end > end The loop i and j write over and over the a fixed 'r', and then you loop over r. They all contains the same last sub-array: lgbp{v,mu}(113:128,113:128) when finished. Bruno
From: Naved Nouyed on 31 May 2010 17:54 "Bruno Luong" <b.luong(a)fogale.findmycountry> wrote in message <hu0v98$shf$1(a)fred.mathworks.com>... > Your function is odd, I strongly suspect it has a bug: > > > for r = 1:nregion > > x=1; > > for i=1:(rows/rrows)-1 % rows is divided into 128/16=8 regions > > y=1; > > for j=1:(cols/rcols)-1 % cols is divided into 128/16=8 regions > > lgbp_r{v,mu,r}(1:rrows,1:rcols) = lgbp{v,mu}(x:x+rrows-1,y:y+rcols-1); > > y = y + rcols; > > end > > x = x + rrows; > > end > > end > > The loop i and j write over and over the a fixed 'r', and then you loop over r. They all contains the same last sub-array: lgbp{v,mu}(113:128,113:128) when finished. > > Bruno Yes, you are right about it and modified it as below. I hope this is corrected now. Requesting comments on the histogram part. Thank you. for v = 1:nscale for mu = 1:norient x = 1; y = 1; for r = 1:nregion lgbp_r{v,mu,r}(1:rrows,1:rcols) = lgbp{v,mu}(x:x+rrows-1,y:y+rcols-1); y = y + rcols; if(mod(r,cols/rcols)==0) %128/16=8 x = x + rrows; y = 1; end end end end
From: Bruno Luong on 31 May 2010 18:33 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
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 Prev: Dicomwrite Next: Calculation of temperature amplitudes each day and per station |