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:28:02 +0000 (UTC)
Organization: Universit&#228;tsSpital Z&#252;rich
Lines: 26
Message-ID: <gn1imi$b6f$1@fred.mathworks.com>
References: <gn1h7l$qs0$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1234456082 11471 172.30.248.35 (12 Feb 2009 16:28:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 12 Feb 2009 16:28:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 11
Xref: news.mathworks.com comp.soft-sys.matlab:517898


"francesco santi"
> I have a MxNx3 matrix (an image) and I would like to subtract to each pixel the mean value of each color component...

one of the many solutions

% the data
     m=ceil(10*rand(2,4,3));
     v=[10,100,1000];
% the engine
     r=arrayfun(@(x) m(:,:,x)-v(x),1:3,'uni',false);
     r=cat(3,r{:});
% the result
     disp(r);
%{
(:,:,1) =
    -7    -2    -9    -2
    -3    -2    -1    -1
(:,:,2) =
   -94   -92   -96   -97
   -97   -98   -90   -96
(:,:,3) =
  -991  -997  -990  -994
  -996  -994  -993  -992
%}

us