Search in a circle method for closest pixel

Started by
4 comments, last by Marktheguy 14 years, 8 months ago
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?
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.
Thanks for your ideas

Any ideas how to get the distance in pixels when it's non linear?
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() ).
If I was helpful, feel free to rate me up ;)If I wasn't and you feel to rate me down, please let me know why!
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.
Doh :) my brain was all wrapped up in "pixels"
Thanks

This topic is closed to new replies.

Advertisement