Path: news.mathworks.com!not-for-mail
From: "Bruno Luong" <b.luong@fogale.findmycountry>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Segmentation violation due to MEX code
Date: Tue, 7 Jul 2009 15:09:01 +0000 (UTC)
Organization: FOGALE nanotech
Lines: 18
Message-ID: <h2voed$p7t$1@fred.mathworks.com>
References: <h2tkfd$l84$1@fred.mathworks.com> <5b6d0b68-60e9-41be-a22f-ea755e2db20d@r33g2000yqn.googlegroups.com> <52a78667-52f6-4603-bfca-4cb04888b75a@i6g2000yqj.googlegroups.com> <h2vhoq$oot$1@fred.mathworks.com>
Reply-To: "Bruno Luong" <b.luong@fogale.findmycountry>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1246979341 25853 172.30.248.37 (7 Jul 2009 15:09:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 7 Jul 2009 15:09:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 390839
Xref: news.mathworks.com comp.soft-sys.matlab:553436


"Jose Antonio " <juriguen@gmail.com> wrote in message <h2vhoq$oot$1@fred.mathworks.com>...

> 
> I still have to check why I get 1 value less with the second approach, but I am doing a complete different thing today!
> 

Probably because your image (y) never reach the value 255. Force the output size ACCUMARRAY. Also use BSXFUN (available from 2007A) is better than REPMAT.

function S = calculate_I(exposures, x, y)

exposuresMat = reshape(exposures, 1, []);
xMat = reshape(x, [], 1);
v = bsxfun(@times, xMat, exposuresMat);
yp1 = y(:)+1;
S = accumarray(yp1,v(:),[256 1]) ./ accumarray(yp1,1,[256 1]);
S(isnan(S)) = 0;

Bruno