Sign in to follow this  
Marktheguy

Search in a circle method for closest pixel

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
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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this