circle#

Automatic search of the spinning disk’s circle

find(image: ndarray, center_search_ratio: float = 0.05, radius_ratio_min: float = 0.5, radius_ratio_max: float = 0.4, min_scaled_edge: int = 512) tuple[int, int, int][source]#

Finds the outside circle in the image.

Returns center coordinates x and y as well as radius r of the circle, all in pixels.

The radius is searched between radius_ratio_min and radius_ratio_max relative to the shorter edge of the input image. The circle center is searched in a region of relative edge length center_search_ratio relative to the image width or height.

To speed up the search, we use a pyramid of progressively down-scaled images. We stop down-scaling once the shorter edge (of width or height) get below min_scaled_edge.

draw(canvas: ndarray, x: float, y: float, r: float) ndarray[source]#

Draws the circle at (x, y) with radius r onto the image canvas.

This is meant for visual inspection.

write(file: Path, x: float, y: float, r: float)[source]#

Writes circle position (x, y) and radius r to given file.

read(file: Path) tuple[int, int, int][source]#

Reads circle position from given file.

Returns center coordinates x and y as well as radius r of the circle, all in pixels.

edge_density(x0: float, y0: float, r: float, image: ndarray) float[source]#

Measures the “color density” along the edge of a given circle.

This function helps in finding the circle by estimating how much contrast is visible along the edge for any given guess as to where and how large the circle might be. The circle is centered at (x0, y0) and has radius r.