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 17:28:02 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 23
Message-ID: <gn1m72$r6k$1@fred.mathworks.com>
References: <gn1h7l$qs0$1@fred.mathworks.com> <gn1hml$19n$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 1234459682 27860 172.30.248.35 (12 Feb 2009 17:28:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 12 Feb 2009 17:28:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1612112
Xref: news.mathworks.com comp.soft-sys.matlab:517912


> 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

% this generates the cell which contains the image
HSV = hsv2rgb(im);
ImageMatrix = cell(HSV_rows, HSV_cols);
for r=1:HSV_rows
    for c=1:HSV_cols
        ImageMatrix{r,c} = [HSV(r,c,1) HSV(r,c,2) HSV(r,c,3)];
    end
end
%this is the loop to compute the subtraction between a pixel and its mean
for r=1:HSV_rows
    for c=1:HSV_cols
        fl = double(cell2mat(ImageMatrix(r,c))); %pixel color components 1x3
        temp(r,c) = (fl - Ml); %Ml=mean vector 1x3
     end
end