Given an image matrix, I want to find the pixel points coordinates of all points/pixels in the border of a given circle with center (x,y), where x and y are integers and radius r, where r is also an integer. Considering the border is 1 pixel thick. Ony this outer edge is what I need to find. I'm having trouble because I only have integers to work with. I tried Manhattan distance but it gives me a square rotated in 45 degrees. I don't really know how to move forward
CodePudding user response:
I saw your last question, and seems you need expanding circle.
Note that simple drawing of circumference pixels might produce small empty spaces. Example for drawing circles of radius 1,2,...,n:
But you can complete integer circle drawing algorithms like Bresenham's one.
Increase r value one-by-one. Generate sequence of pixel coordinates with Bresenham's algorithm in the first octant. Draw pixel if it is not filled yet (from another cell center), and check if lower pixel is filled - if not, draw it to remove empty space. Do the same for 7 symmetric pixels and their neighbors (bottom for the second octant and so on)
CodePudding user response:
you can use cos
to get the x components, and sin
to get the y components
center = [5,5]
r = 12
steps = 500
rads_of_circle = numpy.linspace(-2*numpy.pi,2*numpy.pi,steps)
xs = center[0] numpy.cos(rads_of_circle) * r
ys = center[1] numpy.sin(rads_of_circle) * r
border_points = zip(xs,ys)
this will give you floats... ... just use .round()
if you only want ints