Circle coordinates to cover larger circle in python - python

I am using Google Places API to find all cafes in a single area. Since the API maxes out at 60 results, I would need to apply some sort of grid search to cover the entire desired area.
I am looking for a python code where I could insert the objective coordinate (center of NY), desired large radius (5km), and small radius (0.5km). The algorithm would try identify the center coordinates of the smaller circles to cover the larger one completely. Output of the code would be list of coordinates of the smaller circles.
It doesn’t matter if the circles overlap each other or overflow the outer boundaries. This site had good visualizations of how the smaller circles could fill out the larger one https://math.stackexchange.com/questions/898247/the-minimum-number-of-circles-in-order-to-obtain-a-cover-of-a-specific-square

Related

Python - Segmenting an ROI with many smaller objects inside

I am working with an image containing a lot of small objects formed of hexagons, which are roughly inside a rectangular figure.
See image here:
There are also areas of noise outside this rectangle with the same pixel intensity, which I want to disregard with future functions. I have 2 questions regarding this:
How can I create a segmentation/ROI to only consider the objects/shapes inside that rectangular figure? I tried using Canny and contouring, as well as methods to try and create bounding boxes, but in each of them I always segment the individual objects directly in the entire image, and I can't eliminate the outside noise as a preliminary step.
How can I identify the number of white hexagons inside the larger rectangle? My original idea was to find the area of each of the individual objects I would obtain inside the rectangle (using contouring), sort from smallest to lowest (so the smallest area would correspond to a single hexagon), and then divide all the areas by the hexagonal area to get the number, which I could sum together. Is there an easier way to do this?

Creating Voronoi polygons diagram that are limited to a bounding box

I want to get a Voronoi polygon diagram for a set of points within 50 X 50 domain. That os all the voronoi ridges should be clipped at edges of bounding box, and voronoi vertices should lie on edges or within the bounding box.However this i the image I am getting by using scipy.spatial.Voronoi
The simplest way to cut off at the box boundaries all those cells that would extend beyond it is to do the following:
Reflect your original data set (your "Voronoi seeds") across each edge of your box, creating, in this case, 4 new data sets, each one being a mirror image of your original set of points across one of the edges.
Regard your original data set and these four new data sets as all one set of points, and run your Voronoi algorithm to create a Voronoi partition with this new, enlarged set. Those points in the original set whose cells would extend beyond the boundary now will be met by their mirror images, and their cells will be cut off exactly at the boundaries as you wish.
Now simply ignore the extra points generated in step 1, and you have a Voronoi partition of the original bounding box using only your original set of points, with the cells near the edge neatly cut off by the boundary of the box.
The reflection step is not hard; I can elaborate if necessary.
This method does multiply your number of points by 5, which increases the time to complete the Voronoi computation, obviously. Depending on your number of points, this could become an issue. One can speed things up by reflecting only those points whose cells actually extend beyond the box; that takes a bit more logic but is do-able.

How to select the minimal set of circles that covers another circle?

I'm looking for some solutions that, given a set S of circles with 2D-center points and radii, returns a minimal sub-set M in S that covers entirely a specific circle with 2d-center point and radius. This last circle is not in S.
I've chosen circles, but it doesn't matter if we change them to squares, hexagons, etc.
You have two distinct problems: you need to turn the geometric problem into a combinatoric problem, and then you need to solve the combinatoric problem. For the latter, you are looking at a minimum set cover problem, and there should be plenty of literature on that. Personally I like Knuth's Dancing Links approach to enumerate all solutions of a set cover, but I guess for a single minimal solution you can do better. A CPLEX formulation (to match your tag) would use a binary variable for each row, and a ≥1 constraint for each column.
So now about turning geometry into combinatorics. All the lines of all your circles divide the plane into a bunch of areas. The areas are delimited by lines. Of particular relevance are the points where two or more circles meet. The exact shape of the line between these points is less relevant, and you might imagine pulling those arcs straight to come up with a more classical planar graph representation. So compute all the pair-wise intersections between all your circles. Order all intersections of a single circle by angle and connect them with graph edges in that order. Do so for all circles. Then you can do a kind of bucket fill to determine for each circle which graph faces are within and which are outside.
Now you have your matrix for the set cover: every graph face which is inside the big circle is a column you need to cover. Every circle is a row and covers some of these faces, and you know which.

Align scanned documents based on a reference point, using openCV

I'm currently trying to write a program that can automatically extract data from some graphs in multiple scanned documents. Mainly by using opencv I would like to detect some features of the graphs in order to convert them into usable data. In the left graph I'm looking for the height of the circle sectors and in the right graph the distance from the center to the points where the dotted lines intersect with the gray area. In both cases I would like to convert these values into numeric data for further usage.
What follows is a step by step plan of how I think my algorithm will work:
Align the image based on the big dotted lines. This way I can ensure that the graphs in all the scanned images will have the exact same positions. After all, it is possible that some images will be slightly tilted or moved in comparison with other images, due to the manual scanning process. Basically I want the coordinate of a pixel in one image to correspond to the exact same pixel in another image.
We now know that the coordinates of the graph centers and the angles for the circle sectors are identical for all images now. For each circle sector, filter the darker pixels from the lighter ones. This is done using the openCV inRange function.
Search for the best fitting segment over the darker pixels in the left graph and search for the best fitting triangle in the right graph. This is done by global optimization.
Return the radius of the optimal segment and return the edge lengths of the optimal triangle. Now we have values that we can use as data.
I have more or less figured out how to do every step, except the first one. I have no clue on how I would go about aligning my images. Does someone might have an idea or a strategy on how to achieve this alignment?
Step 1: canny, it give you perfect long edge. If this is the only part you dont understand, here is the answer. You can adjust the parameter to get the best result. The first will be idea for both line and pie circle. But if you only keen to find pie. change the parameter accordingly to get my 2nd image
The red denotes the doted line. sample from opencv directly
Step 2: local area enhancement/segmentation to find both circles (from image 1 parameter with houghcircle param2 set to 110)
Step 3: Segment the pie out(all the way to the edge of image) and find the median line
Step 4: OCR on the test image pies and find the distance of none-background color along the median line.
Step 5: generate list out and send to csv or sth

How to create a random array of circles in Python, without overlapping?

I would like to know how to create some circles without overlapping in Python.
Let me share a part of my script
In lines 55,56 and 57 I print the coordinates, witnessing overlapping. Inside each for statement I thought I avoided the overlapping doing something like bisection method (root finding method).
The source code works good for 5 or 6 voids but when increasing the number of voids I get overlapping.
Your maximum radius is B=10. So assuming you want points separated by maximum radius, you could sample such points using Poisson disk algorithm.
Then, having sampled centers, draw random radius around each center, and they wont overlap because all radii are smaller than your max.

Categories