Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: 3D matrix operation speed up
Date: Thu, 12 Feb 2009 16:11:01 +0000 (UTC)
Organization: FZ-Juelich
Lines: 21
Message-ID: <gn1hml$19n$1@fred.mathworks.com>
References: <gn1h7l$qs0$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1234455061 1335 172.30.248.38 (12 Feb 2009 16:11:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 12 Feb 2009 16:11:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1088664
Xref: news.mathworks.com comp.soft-sys.matlab:517891


"francesco santi" <fpsanti@gmail.com> wrote in message <gn1h7l$qs0$1@fred.mathworks.com>...
> Hello, I have the following problem.
> I have a MxNx3 matrix (an image) and I would like to subtract to each pixel the mean value of each color component.
> I have a 1x3 vector which contains the mean value of the R G B components.
> I've done it with a for loop but it's very slow for big images (i.e. matrix) and I'm pretty sure there's a faster way to do it.
> I've tried also to put all the 3 RGB components in a cell, so I have in position r,c a vector of 3 color components. Then I am using a for loop and cell2mat to do the same operation as above. But again I need to replace the for loop for speed.
> Any help would be appreciated.
> Thanks in advance,
> Francesco

Hello Francesco,

is this the loop you used?

for n = 1:3
    im(:,:,n) = im(:,:,n)-vec(n);
end

then maybe you can accelerate it with imsubtract if you have the image processing toolbox
cheers
kinor