Ross
Ross

Reputation: 2096

How to fill circle with increasing radius?

As part of more complex algorithm I need following:

enter image description here

How can I find the points to fill at each step so at the end of each step I have fully filled 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.

Upvotes: 3

Views: 2686

Answers (4)

Monday Fatigue
Monday Fatigue

Reputation: 321

Draw the circles with radii 1, 3, 5, 7, 9, ... and fill the space in between them as needed, or draw all radii 1, 2, 3, 4, 5, ... and fill the holes with proper timing proportional to distance to the center.

Both method need to draw the next radius circle early and use it in next step.

Upvotes: 0

Ross
Ross

Reputation: 2096

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)

enter image description here

Upvotes: 3

aioobe
aioobe

Reputation: 420951

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`
  • Do whatever you like with borderPixels (such as color them red)

Upvotes: 3

Mesh
Mesh

Reputation: 6422

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

Upvotes: 2

Related Questions