What's wrong with this polyshape?
7 次查看(过去 30 天)
显示 更早的评论


The polyshape created has nothing to do with the original polygon: what am I doing wrong?
回答(1 个)
Ameer Hamza
2020-4-24
Try this code. As I mentioned in my comment to your question that the polygon is just 3 pixels wide. In this code, I scaled the coordinate to make it 50 pixels wide. Now it should be visible.
x = [106.2620, 107.2080, 106.5060, 104.6750, 105.7130];
y = [666.0000, 670.0000, 644.0000, 628.0000, 656.0000];
x = (x - min(x))./(max(x)-min(x))*50+100;
BW=poly2mask(x, y, 800, 800);
imshow(BW)
4 个评论
Ameer Hamza
2020-4-24
The polygon is not rotated, it is just drawn upside down because the imshow() function makes a y-axis, which increases in the downward direction, whereas plot() make y-axis increasing in the upward direction. Apart from appearance, the vertex coordinates are the same.
If you want to do this with regionprops, then you will need to apply some type scaling before making the poly2mask and then apply reverse scaling at the end. I recommend avoiding the image processing toolbox function because it is really a geometry problem, and there are other available tools to solve this problem efficiently. For example, check this FEX submission: https://www.mathworks.com/matlabcentral/fileexchange/3215-fit_ellipse. It fit an ellipse to a set of data points and directly outputs the major and minor axes.
另请参阅
类别
在 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!
