comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Efficient finding of locations where two 'on' pixels are next to one another
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: Efficient finding of locations where two 'on' pixels are next to one another [message #74359] Thu, 13 January 2011 10:21
Marc Buie is currently offline  Marc Buie
Messages: 12
Registered: December 2010
Junior Member
Robin -

I wrote a very similar routine some time ago. The name is collapse.pro and is in my library (www.boulder.swri.edu/~buie/idl). I worked really hard on this to speed it up and it's pretty good though you might not believe this to see the code. My program might be different from yours though. I use two images, one a bit image that is being processed but it is coupled to another "grey-scale" image from which the bit image is derived. I work with astronomical data and my images are of the sky (with stars and such) and the bit image records the positions of the stars.

I use boxm.pro which finds a local max in the image and uses that information to turn off the bits in the bit image that are too close to one another.

You might find some useful tricks in these two programs that could help you solve your problem.

Cheers,
Marc
Re: Efficient finding of locations where two 'on' pixels are next to one another [message #74360 is a reply to message #74359] Thu, 13 January 2011 09:56 Go to previous message
jeanh is currently offline  jeanh
Messages: 79
Registered: November 2009
Member
On 13/01/2011 12:28 PM, Robin Wilson wrote:
> Hi,
>
> I'm working with a binary image which is the output of another procedure
> I've run. I am trying to write a routine to post-process this image, and
> clean it up a bit. As part of this, I want to find the indices of pixels
> that are set to 1 (ie. 'on') that are next to other pixels that are set
> to 1, but only in the X direction. To make that a bit clearer, there is
> a diagram below:
>
>
> (0) . . . * * . .
> (1) . . . * . . .
> (2) . . * * * . .
> (3) . . . * . . .
> (4) . . . * . . .
>
> In this example I would want the indices of both 'on' pixels in Row 0,
> nothing in Row 1 (as the pixel is not touching anything in the X
> direction), all three in Row 2, and nothing in Rows 3 and 4.
>
> At the moment all I can think of some kind of ghastly FOR loop with
> loads of state-checking. I'm thinking that there must be a nicer (that
> is more efficient and cleaner code) way...is there?
>
> Cheers again,
>
> Robin

You can try using "shift"

pix = where(img eq 1 and shift(img,-1,0) eq 1)
pix = [pix,pix+1] ;include the index of all valid pixels
pix = pix[uniq(pix,sort(pix))] ; remove duplication caused by the
previous line

You handle the behavior at the edge

Jean
PS: untested, double check that I didn't got confused between +1 and -1
in the shift()
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Efficient finding of locations where two 'on' pixels are next to one another
Next Topic: Colorbar

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 15:15:47 PDT 2025

Total time taken to generate the page: 0.00554 seconds