How to create a polygon using edges?

4 ビュー (過去 30 日間)
sss sss
sss sss 2015 年 9 月 2 日
コメント済み: Image Analyst 2015 年 9 月 2 日
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.

採用された回答

Image Analyst
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 件のコメント
sss sss
sss sss 2015 年 9 月 2 日
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 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
Walter Roberson 2015 年 9 月 2 日
There are other implementations of the same kind of routine; look in the File Exchange
  4 件のコメント
sss sss
sss sss 2015 年 9 月 2 日
I edited my question with other pictures. Please help!
Walter Roberson
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.

サインインしてコメントする。

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by