As part of more complex algorithm I need following:
- let say I have a circle with radius R1 drawn on discrete grid (image) (green on image below)
- I want to draw circle that have radius R2 that is bigger then R1 with one pixel (red on image below).
- At each algorithm step to draw circles with increasing radius in a way that each time I have a filled circle.
How can I find the points to fil开发者_高级运维l at each step so at the end of each step I have fully filed circle?
I have thinking of some circle rasterization algorithm, but this will lead to some gaps in filling. Another way is to use some mathematical morphology operation like dilation but this seems to be computationally expensive to do.
I am generally looking for way to do this on arbitrary shape but initially circle algorithm will be enough.
Your best option is to draw and fill a slightly larger red circle, and then draw and fill the green circle. Then redo on next iteration.
To only draw the 1px border is quite tricky. Your sample image is not even quite consistent. At some places a white pixel occurs diagonally to a green pixel, and in other places that pixel is red.
Edit:
- borderPixels = emptySet
- For each green pixel, p
- For each neighbor n to p
- If n is white
- Add n to *borderPixels`
- If n is white
- For each neighbor n to p
- Do whatever you like with borderPixels (such as color them red)
My current solution for circle.
Based on well known Midpoint circle algorithm
- create set of points for 1 octant for R1 radius (light green pixels)
- create set of points for 1 octant for R2 radius (dark orange pixels)
- for each row in image compare X coordinate for orange and green pixels and get 0 or 1 (or whatever) number of pixels in-between (light orange).
- repeat for each octant (where for some octants columns instead of rows have to be compared)
This algorithm can be applied for other types of parametric shapes (Bezier curve based for example)
For non-parametric shapes (pixel based) image convolution (dilation) with kernel with central symmetry (circle). In other words for each pixel in shape looking for neighbors in circle with small radius and setting them to be part of the set. (expensive computation)
Another option is to draw a circle/shape with a 2pixel wide red border, and then draw a green filled circle/shape with NO border. Which should leave an approximately 1px wide edge. It depends on how whatever technique you use resolves lines to pixels.
Circle algorithms tend to be optimised for drawing circles.....See the link here
精彩评论