Path: news.mathworks.com!newsfeed-00.mathworks.com!newscon02.news.prodigy.net!prodigy.net!news.glorb.com!postnews.google.com!z72g2000hsb.googlegroups.com!not-for-mail
From: ImageAnalyst <imageanalyst@mailinator.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Presence of logical ones around a pixel in a certain direction 
Date: Mon, 12 May 2008 18:02:15 -0700 (PDT)
Organization: http://groups.google.com
Lines: 46
Message-ID: <53cbec78-0244-40af-b912-cee1c2dbf07b@z72g2000hsb.googlegroups.com>
References: <g09hms$lev$1@fred.mathworks.com>
NNTP-Posting-Host: 75.186.67.199
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
X-Trace: posting.google.com 1210640535 17770 127.0.0.1 (13 May 2008 01:02:15 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Tue, 13 May 2008 01:02:15 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: z72g2000hsb.googlegroups.com; posting-host=75.186.67.199; 
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 
Xref: news.mathworks.com comp.soft-sys.matlab:468042


On May 12, 9:46=A0am, "Ahmad " <ahmad.hu...@gmail.com> wrote:
> 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 =3D 12 bins). Looking for an extremely
> fast way...since I'll be doing this for many pixels
>
> Regards,

--------------------------------------------------
Ahmad:
Simple - I'd just do 12 convolutions.  Make up a convolution kernel,
well 12 of them actually with 1's placed in the sector you want to
look at and 0's in the other sectors.  Then simply call the conv2
function once for each kernel.  The pixel value in the resulting 12
images will tell you how many pixels were in the sector (pie-slice
shape) centered on that pixel for that particular sector orientation.
Look up the documentation for the convolution filter and you'll see
why it does exactly what you asked for.  It's in the image processing
toolbox, but I think there's a version of it in base MATLAB.

As far as timing, you would just have to try it versus the other
methods suggested.  You could probably do all 12 for ordinary sized
images in just a second or two, in which case the time is probably not
all that much of a concern.  How big are your images?  How many do you
have to process (hundreds or thousands)?  That is, don't knock
yourself out trying to shave the time down from 0.53 seconds to 0.37
seconds - your users will never notice.  Today I read in and processed
in about 2 minutes a single 3D image that was 1.2 GB in size (yes
gigabytes, so no wonder I laugh when I see people talk about a "large"
array that is a few hundred thousand elements).  I remember years ago
when we had images of 512x512 (256 KB), we thought a minute or so per
image was reasonable.  How times have changed.
Regards,
ImageAnalyst