"Pablo" wrote in message <jjlcje$nlk$1@newscl01ah.mathworks.com>...
> Hi all,
> I have this problem and I’ts possible my fault… maybe, I forget to change a flag or something like that.
> I run this code in my PC (Windows 7 64 bits, Intel Core i7 CPU) using MATLAB R2009a (64bits)
> img=imread(‘sample.bmp’);
> img=rgb2gray(img) ;
> [u,v] = size(img);
> ii = double(zeros(u+1,v+1));
> s = [zeros(1,v+1) ; zeros(u,1) double(img)];
> tic
> for i=2:u+1,
> for j=2:v+1,
> s(i,j)=s(i,j1)+img(i1,j1);
> ii(i,j)=ii(i1,j)+s(i,j);
> end
> end
> toc
> % ii = integral image
>
> The result was:
> “Elapsed time is 0.508716 seconds.”
>
> In fact, It’s a lot of time for a 420x560 pixels picture…
> In the same PC, I installed the same MATLAB in 32 bits. This time the output was:
> “Elapsed time is 0.016215 seconds.”
>
> I couldn’t figure out what I’m doing wrong… I want to continue using MATLAB with 64 bits, but with this performance I can’t wait all the time for the integral image is calculated…
>
> Thanks for your help.
>
> Pablo
       
In the line
s(i,j)=s(i,j1)+img(i1,j1);
you are overwriting the copy of 'img' you originally place in 's' and one wonders why. More importantly each of the u*v times it is executed it has to convert img(i1,j1) to double. Perhaps that takes longer with a 64bit version. Why don't you use the already computed double version of 'img' in that line? It looks to me as though you originally intended to write that line as
s(i,j)=s(i,j1)+s(i,j);
which ought to produce the same result, given the 's' as you have set it up earlier.
Roger Stafford
