What is this called? Polygon/Vertices/XY Points Related - c#

I am looking for the right term for this procedure:
Creating polygons with each point (x,y) generated through the application.
Example if I have this picture with this shape (white background is transparent)
the procedure or the application will create XY points in a way that it will define the points for example in the image where this shape can be extracted.
The shape is in final x,y points polygon shape (if points were to be connected it will look like):
I have tried googling different term but nothing was of help.

You might be after the Convex hull. I.e. a convex polygon that fully contain your shape. There are some libraries for creating this on nuget, or ask on https://softwarerecs.stackexchange.com/
You could perhaps also use Marching Squares if you need to extract the outline. But you could probably also just use the pixel coordinate of the border pixels if you do not need sub pixel precision.

Related

Compare two sets of XY Coordinates and align them

I have two sets of X,Y co-ordinates as separate lists. Both represent the same irregular polygonal shape, but in different orientations and sizes/scale.
Need to write a program in C#, to compare both the points set, rotate any one of the shape such that it aligns with the another, so that they are in same orientation.
Tried searching for solution, and got to know using concave hull with angles difference can help, but could not find a good C# implementation for the same.
Can some one help me, if there is a minimal way to achieve this?
Edit: The two points-set might not be the same. One may contain more points than other.
I have contour co-ordinates of a shape and a PNG which is of same shape, but orientation is different. I want to read the PNG, calculate the angle to turn it to the fit the Contour.
Calculate image moments for point cloud
Evaluate orientation of both clouds with Theta angle.
Rotate one cloud by theta difference.
Use other moments (centroid etc) to find translation and scale

c# detect points of polygon in black/white image

I have to detect all the points of a white polygon on a black background in c#. Here is an image of several examples. I wouldn't think it is too difficult, but I am unable to detect this properly with all the variations. My code is too much to post here, but basically I went through each side and look for when it changes from black and white. Should I use Open CV? I was hoping for a simple algorithm I could implement in C#. Any suggestions? Thank you.
In your case I would do this:
pre process image
so remove noise in color if present (like JPG distortion etc) and binarize image.
select circumference pixels
simply loop through all pixels and set each white pixel that has at least one black neighbor to distinct color that will represent your circumference ROI mask or add the pixel position to some list of points instead.
apply connected components analysis
so you need to find out the order of the points (how are connected together). The easiest way to do this is use flood filing of the ROI from first found pixel until all ROI is filled and remember the order of filled points (similar to A*). There should be 2 distinct paths at some point and both should join at last. So identify these 2 points and construct the circumference point order (by reversing one half and handling the shared part if present).
find vertexes
if you compute the angle change between all consequent pixels then on straight lines the angle change should be near zero and near vertexes much bigger. So threshold that and you got your vertexes. To make this robust you need to compute slope angle from a bit more distant pixels then the closest pixels. Also thresholding this angle change against sliding average often provides more stable results.
So find out how far the pixels should be to compute angle so you got not too big noise and vertexes has still big peaks and also find out the threshold value that is safe above any noise.
This can be done also by hough transform and or find contours functions that are present in many CV libs. Another option is also regress/fit the lines in the point list directly and compute intersections which can provide sub pixel precision.
For more info see related QAs:
Backtracking in A star
Finding holes in 2d point sets
growth fill

Procedural urban modeling - polygon subdivision (maybe better ideas?)

Question: How to "divide polygon" to create quads adjacent to the each segment.
My 1st idea: Divide each segment of polygon. Move each newly created point - perpendicular to divided segment. Now we get points for quads. At the end - remove overlapped quads. Questions: How to check if each (new) point of quad is inside polygon? Because the newly created points can go beyond the polygon - specifically on corners. Also how to check overlapped quads?
My 2nd idea: Inset polygon. Divide segments then connect points. But how about more complex polygons where some segments after inset can intersect?
I know this is more a math problem but I'm looking for ready-made solutions for above problems - like simple 2d collision detection of rectangles (but not only one axis aligned).
Maybe someone have better ideas how to create procedural urban parcels?
Do they have to be quads? That is a pretty serious restriction, especially when dealing with arbitrary geometries like in your picture.
For something like this, I would try using Voronoi diagram to partition the space. A Voronoi diagram algorithm takes a set of points as inputs and partitions the space so that each input point is associated with a region of space where all the points inside that region are closest to that input point. For your inputs you could put two sets of points on the interior of your polygon, one set closest to the edge which contains the regions you will use, and the second set of points will be that interior area that you will discard.
Have a look at the Fortune Voronoi implementation in C#.

Finding a chequered board in an image, and identifying the angle and distance

What I want to do is take a source image which will contain a black-and-white chequered board of a known physical size and a known number of squares, and identify the boundaries of said board, as well as the angle from which it is being observed (assuming its perfectly flat) and from what distance.
If I can reliably identify the 4 corners of the board then I know how to calculate the angle and distance, so the task is more about identifying the chess board.
What I've tried so far is greyscaling the image and increasing the contrast so I end up with a stark black-and-white image (which to the eye contains blackness with just the white squares) - and while I can identify the boundaries of the board fine from a top-down perspective by measuring the frequency of changes from black->white->black, I'm not sure how to go about doing this for any angle.
Nominally I'm doing this with C#, but as far as actual answers go I'm happy for any code examples with a c-like syntax - more interested in the math and methodology for this one though.
Finding a general 2d object inside a 3d world is often done with SIFT or SURF.
There are 2 steps:
find a manageable number of local features in the image (such as strong corners)
find a correlation between those points in your image and your search pattern
OpenCV has an implementation for that:
Features2D + Homography to find a known object
The Wikipedia article on surf also points out another c# implementation.
Also see this Stackoverflow answer:
Now this is a pretty general method, and I do not know how well it will work with your checkerboard.
But there are specific approaches for chessboard patterns: such as the openCV function cvFindChessboardCorners (tutorial)
I never used it, but I found this description of the algorithm: (Source is in the file cvcalibinit.cpp )
Image binarization by thresholding to segment black and white squares
Find corners of the black squares:
Find contours of the boundaries of the black regions
Select contours of suitable shape
Approximate these contours with 4-vertex polygons
Among these select the quadrangles resembling calibration pattern squares
Extract corners of the selected quads, having at least one corner in vicinity
Group the corners of the selected quadrangles in lines according to calibration object size

Outer Bounding Points of Image/Shape using C#

I have some images that I'd like to draw a polyon around the outer edges. The images themselves are on transparent backgrounds and I've created an array of the pixels in the images which contain a point and are not transparent (or white).
Now, my question is: how do I draw an accurate polygon around the outer edge points? I've used a Graham Scan algorithm that I read about to create a convex hull around the edges but this doesn't seem to work for objects with concavities. For example:
http://i48.tinypic.com/4s0lna.png
The image on the left gets filled in using this method with the one on the right. As you can see, it's 'filling in' a little too much.
I assume there must be some other algorithm or approach that can be used to solve this, but I'm not sure of where to look or what it might be called. Could anyone point me in the right direction? I'm using C#/.net and hopefully there might be something that already exists which could work along these lines.
I think the 2D "Alpha shapes" algorithm would the right choice for you.
http://www.cgal.org/Manual/latest/doc_html/cgal_manual/Alpha_shapes_2/Chapter_main.html
Alpha shapes can be considered as a generalization for the "convex Hull" algorithm that allows for generation of more general shapes.
By using alpha shapes you will be having control over the level of details to be captured by the resultant shape by changing the alpha parameter value.
You can try the java applet here : http://cgm.cs.mcgill.ca/~godfried/teaching/projects97/belair/alpha.html
to have better understanding about does this algorithm do.
You can start on a pixel by pixel level, using a flood-fill approach.
Start in the corner, checking that it does have zero alpha.
Check the neighbours for zero alpha and iterate until we have no unchecked neighhours.
This gives you a mask for the image which will consist of two simply connected regions, the interior and exterior.
The set you seek then consists of:
all the points in the exterior which are on the boundary of the interior.
You can then turn that into a polygon by:
Take an initial polygon that consists of all the points in the edge set
Remove redundant vertices that lie along straight edges.

Categories

Resources