How to create a polygon using edges?

5 views (last 30 days)
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.

Accepted Answer

Image Analyst
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
sss sss
sss sss on 2 Sep 2015
Just ignore the black portions. I just used Paint in order to show my intended result. It must be white only, and later on that portion must be removed from the image.
What if the polygon are not always convex? Can I still use convhull()?
Image Analyst
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().

Sign in to comment.

More Answers (1)

Walter Roberson
Walter Roberson on 2 Sep 2015
There are other implementations of the same kind of routine; look in the File Exchange
  4 Comments
sss sss
sss sss on 2 Sep 2015
I edited my question with other pictures. Please help!
Walter Roberson
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.

Sign in to comment.

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!