Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: 3D matrix operation speed up
Date: Tue, 17 Feb 2009 10:32:02 +0000 (UTC)
Organization: Erasmus MC
Lines: 28
Message-ID: <gne3n2$9dq$1@fred.mathworks.com>
References: <gn1h7l$qs0$1@fred.mathworks.com> <gn1hml$19n$1@fred.mathworks.com> <gn1m72$r6k$1@fred.mathworks.com> <gne06h$kid$1@fred.mathworks.com> <gne2n7$5f2$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 1234866722 9658 172.30.248.38 (17 Feb 2009 10:32:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 17 Feb 2009 10:32:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 870065
Xref: news.mathworks.com comp.soft-sys.matlab:518784


"francesco santi" <fpsanti@gmail.com> wrote in message <gne2n7$5f2$1@fred.mathworks.com>...
> Thanks again for the answer.
> Sorry, but I didn't want someone to do my job. :)
> I am quite new to Matlab and for me the Matlab help seems not so easy/clear.
> I tried the arrayfun solution and it works, but not as i would like to.
> It was my fault because I couldn't explain the problem very well!
> I'll try again.
> 
> I have a MxNx3 matrix which is an image.
> I have to compute the following formula for each pixel and store the result in a MxN matrix.
> Singleton(row,col) = (px(row,col)-m(class)) * invS(class) * (px(row,col)-m(class))';
> 
> px=RGB_matrix(row,col,:):
> px=reshape(px,1,3); %I have the 3 RGB color components of one pixel in one row
> m=[mean(R) mean(G) mean(B)]; %the mean vector contains the mean value of the color components
> invS %is the inverse of the covariance matrix
> 
> The mean vector and inverse matrix change depending on the class which the pixel belongs to. So I also wrote a for loop to compute all the m and invS belonging to each class.
> 
> I hope the problem is more clear now.
> I have to compute that formula over all the pixels trying to avoid for loops. More over I have to store the result in a new MxN matrix in the same position of the original pixel.
> Now I am using 3 for loops and for big images it is very slow, of course.

Did you look at the PROFILER to see the bottlenecks of your code?

help profile

Jos