How to create a polygon using edges?
5 views (last 30 days)
Show older comments
So I have the image as shown. The edges are of color yellow and red (just ignore the small yellow circle). How can I create a polygon using the edges? please help me! This is the image with edges.
This is the image with the polygon colored black.
This is the resulting image with the white part connoting the removed polygon.
0 Comments
Accepted Answer
Image Analyst
on 2 Sep 2015
Why is your "removed" region white with some black islands in it? And, if your polygons are always convex like that, just pass them into convhull() then pass the convex vertices into poly2mask()
[rows, columns, numColorChannels] = size(binaryImage);
vertexIndexes = convhull(x, y);
cx = x(vertexIndexes); % Extract the convex vertices only.
cy = y(vertexIndexes);
mask = poly2mask(cx, cy, rows, columns); % Create mask from convex hull
binaryImage(mask) = true; % Make all white.
2 Comments
Image Analyst
on 2 Sep 2015
If it's not convex but you still have an ordered list with no overlap (like figure eights) then you can skip the convhull part and just go directly to poly2mask. If you do have figure eights, or a non-ordered list, then you'll just have to see what the mask looks like. If some parts of the mask are negative/blank/not-filled, then you might have to call imfill().
More Answers (1)
Walter Roberson
on 2 Sep 2015
There are other implementations of the same kind of routine; look in the File Exchange
4 Comments
Walter Roberson
on 2 Sep 2015
Threshold on the color channels to find the boundaries of the color portion. Scribble a line in the binary image along the edge of the picture, between the two endpoints on the edge. imfill(). You now have a mask to use to set (or clear) the original image.
See Also
Categories
Find more on Elementary Polygons in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!