Path: news.mathworks.com!not-for-mail
From: "Ahmad " <ahmad.humyn@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Presence of logical ones around a pixel in a certain direction and distance
Date: Mon, 12 May 2008 16:39:04 +0000 (UTC)
Organization: University of Lahore
Lines: 63
Message-ID: <g09rr8$207$1@fred.mathworks.com>
References: <g09hms$lev$1@fred.mathworks.com> <g09ont$rtu$1@fred.mathworks.com>
Reply-To: "Ahmad " <ahmad.humyn@gmail.com>
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 1210610344 2055 172.30.248.37 (12 May 2008 16:39:04 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 12 May 2008 16:39:04 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 687196
Xref: news.mathworks.com comp.soft-sys.matlab:467943


Thanks a lot :)

These tips look extremely helpful. Please do tell, if you
find a faster way :)

Regards,

"helper " <spamless@nospam.com> wrote in message
<g09ont$rtu$1@fred.mathworks.com>...
> "Ahmad " <ahmad.humyn@gmail.com> wrote in message 
> <g09hms$lev$1@fred.mathworks.com>...
> > Hi there,
> > 
> > Lets say I have binary image. Given a pixel I want to find
> > the number of non-zero values around it in a certain 
> radius,
> > in a certain direction. Lets say I have divided the region
> > around the pixel into 30deg regions (starting from north,
> > 0-30 deg, 30-60deg ... 330-360 deg) upto a distance of x
> > pixels, so that it makes a radial region around the pixel
> > concerned, with spokes at every 30 degrees. I want to find
> > all logical 1 pixels in each region. What would be the
> > fastest way to perform this?
> > 
> > Eventually I want to do binning of the number of non-zero
> > values around a certain pixel. (According to my example
> > there will be 360/30 = 12 bins). Looking for an extremely
> > fast way...since I'll be doing this for many pixels
> > 
> > 
> > Regards,
> 
> Until someone comes up with a better way, here's one.
> 
> First, you can initially compute the rows and columns of 
> each non-zero point:
> 
> [i j] = find(A);
> 
> 
> Then, for each point p where p = [row col] that you want to 
> perform your histogram and for a maximum distance of 
> maxDist, use:
> 
> p = [20 33];
> maxDist = 12;
> 
> closePts = hypot(p(1)-i,p(2)-j)<=maxDist;
> allAngles = mod(ceil(atan2(p(2)-j(closePts),...
>   p(1)-i(closePts))/pi*6),12)+1;
> nPer = hist(allAngles,1:12);
> 
> 
> where nPer is 1-by-12 and the first element is # of 
> nonzeros in the range [0 30) deg, second from [30 60), etc.
> 
> I can see a few improvements you can make for performance 
> depending on your application.  One might be to use:
> 
> closePts = (p(1)-i).'*(p(2)-j))<=maxDist^2;
> 
> Good luck