How to create a polygon using edges?
7 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Image Analyst
2015-9-2
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 个评论
Image Analyst
2015-9-2
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().
更多回答(1 个)
Walter Roberson
2015-9-2
There are other implementations of the same kind of routine; look in the File Exchange
4 个评论
Walter Roberson
2015-9-2
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Elementary Polygons 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!