Path: news.mathworks.com!not-for-mail
From: "Bruno Luong" <b.luong@fogale.findmycountry>
Newsgroups: comp.soft-sys.matlab
Subject: Re: The loop is very slow on 64-bits
Date: Tue, 13 Mar 2012 19:14:12 +0000 (UTC)
Organization: FOGALE nanotech
Lines: 29
Message-ID: <jjo6a4$ag0$1@newscl01ah.mathworks.com>
References: <jjlcje$nlk$1@newscl01ah.mathworks.com>
Reply-To: "Bruno Luong" <b.luong@fogale.findmycountry>
NNTP-Posting-Host: www-06-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1331666052 10752 172.30.248.38 (13 Mar 2012 19:14:12 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 13 Mar 2012 19:14:12 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 390839
Xref: news.mathworks.com comp.soft-sys.matlab:760838

"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,j-1)+img(i-1,j-1);
>         ii(i,j)=ii(i-1,j)+s(i,j);
>     end
> end
> toc
> % ii = integral image

Try:

tic
img = double(img);
[u,v] = size(img);
s =  [zeros(1,v+1) ; zeros(u,1) cumsum(img,2)];
ii =  [zeros(1,v+1) ; zeros(u,1) cumsum(img,1)];
toc

% Bruno