I have a 3d point cloud as shown in the first figure. I want to detect and draw polygons around all the boundaires present in the point cloud, I mean main polygon that represents the outer boundaries of the point cloud and another polygons that defines the inner boundaries as shown in figure 2. I tried convex hull but it only gets points representing the outer boundaries. The idea is that I want polygons defining all the boundaries such that later on if I have any points lying inside the inner boundaries or outside the outer boundaries I can remove them. Any ideas how I can do that in python?
Related
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?
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.
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.
So I have a circle created in pygame as my main character, and I'm looking to find the shortest distance between its sides and the various surrounding obstacles. You can see what I mean in the picture. I have a left quadrant and a right quadrant, and I want to see what exists in these quadrants. Whatever is the closest obstacle pixel wise to the circle, that pixel count becomes the left and right values (ie. if in the right quadrant the closest obstacle was 40 pixels away, right = 40). I also have a front value, that will be scanning for things directly in front of the circle.
I've seen things for looking for collision with a circle (creating a circular field around the object as a whole) and I've also seen stuff that uses Pythagorean theorem to look for distances, but I'm not sure how to tackle it in a more "spotlight" scope, if that makes sense.
Any suggestions on how to go about this would be much appreciated! The overall goal is for the circle to move automatically around these obstacles by avoiding them, hence why I want it to scan in various areas to determine how to move about the space.
The entire space is enclosed with a wall, and all the obstacles are randomly placed squares within the wall.
The distance to a circle is the same as the distance to the center minus the radius.
Now, the distance from a rectangle to a point is found by considering the nine regions defined by the supporting lines of the sides.
Depending on the region, the shortest distance is axis-aligned (from a side to the point) or oblique (from a corner to the point) and the formulas are easy.
The discussion is even simpler for a rectangular hole or inner angle.
Dear Stackoverflow community,
I have contours of irregular polygons as unordered datapoints (like on the figure here: https://s16.postimg.org/pum4m0pn9/figure_4.png), and I am trying to order them (ie. to create a polygon).
I cannot use the convex hull envelope because of the non convex shape of the polygon. I cannot ase a minimum distance criterion because some points of other parts of the contour lie closer (example: point A has to be joined with B, but is closer to C). I cannot use a clockwise ordering because of the irregular shape of the contour.
Do anyone knos a way to implement (preferentially in Python) an algorithm that would reorder the datapoints from a starting point?
look here finding holes in 2D point set for some ideas on how to solve this
I would create point density map (similar to above linked answer)
create list of all lines
so add to it all possible combination of lines (between close points)
not intersecting empty area in map
remove all intersecting lines
apply closed loop / connectivity analysis on the lines
then handle the rest of unused points
by splitting nearest line by them ...
depending on you map grid size and point density you may need to blend/smooth the map to cover gaps
if grid size is too big then you can miss details like on the image between points A,C
if it is too small then significant gaps may occur near low density areas
But as said this has more then one solution so you need to tweak this a bit to make the wanted output perhaps some User input for shaking the solution a bit until wanted solution found...
[notes]
you can handle this as more covex polygons ...
add line only if winding rule met
stop when no more lines found
start again with unused points
and in the end try to connect found non closed polygons ...