Jump to content
  • Advertisement
Sign in to follow this  
Marktheguy

Search in a circle method for closest pixel

This topic is 3256 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm working on a edge expansion filter. Now it searches for closest pixel found from a given X Y point in a square type pattern. This square search method results in weird results on some places. It's all correct when you think about how it searches but it doesnt look good in some places. What I would like to do is to search in a circle instead. So I get rid of the straight lines. Any ideas how do I create a function that searches pixels in a circle?

Share this post


Link to post
Share on other sites
Advertisement
Does it need to be fast?
I don't know if I understand correctly, but do you have a grid, starting at some point, and want to search for the pixel closest to the origin point that matches some criteria?
Keep a list of the next pixels to search, sorted by distance to the origin pixel. You start with the four pixels surrounding your origin pixel. Then when you search you take the first pixel in the list out, and if it's not the one you're looking for, add all its neighbors to the list. Keep it sorted by distance to the origin, and keep going, always with the first pixel in the list (the closest one to the origin), until you find the one you're looking for.

Share this post


Link to post
Share on other sites
The squared distance could be expressed as d2 = dx2 + dy2. It should be sufficient to sort by the squared distance (in order to avoid the sqrt() ).

Share this post


Link to post
Share on other sites
You could keep the distance stored at each pixel, and when adding neighbors you add the distance between the active pixel and the relevant neighbor to the stored distance, and use as the distance for the new pixel.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!