MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   资料存档 (https://www.labfans.com/bbs/forumdisplay.php?f=72)
-   -   如何使用MATLAB插值矢量在图像上的坐标? (https://www.labfans.com/bbs/showthread.php?t=23167)

poster 2019-12-10 20:30

如何使用MATLAB插值矢量在图像上的坐标?
 
例如,如果我有一个描述矩形的向量

xy=[165 88; 401 88; 401 278; 165 278]; 在图像上。

我如何获得以下向量

[165 88; % increase X - hold y 166 88; 167 88; ... ; 399 88; 400 88; 401 88; % hold x - increase y 401 89; 401 90; 401 91; ... ; 401 276; 401 277; 401 278; % decrease X - hold y 400 278; 399 278; 398 278; ... ; 167 278; 166 278; 165 278; % hold x - decrease y 165 277; 165 276; ... ; 165 87]; 使用MATLAB内置函数还是我需要使用FOR LOOPS编写它?

该算法必须适用于具有n点和xy坐标的通用矢量。



[B]回答:[/B]

如果有图像处理工具箱,则可以通过创建多边形的图像,然后找到轮廓来实现:

xy=[165 88; 401 88; 401 278; 165 278]; %# create the image - check the help for impolygon for how to make sure that %# your line is inside the pixel img = poly2mask(xy(:,1),xy(:,2),max(xy(:,1))+3,max(xy(:,2))+3); figure,imshow(img) %# show the image %# extract the perimeter. Note that you have to inverse x and y, and that I had to %# add 1 to hit the rectangle - this shows one has to be careful with rectangular %# polygons boundary = bwtraceboundary(logical(img),xy(1,[2,1])+1,'n',8,inf,'clockwise'); %# overlay extracted boundary hold on, plot(boundary(:,2),boundary(:,1),'.r') 编辑以显示如何使用bwtraceboundary以及警告矩形的像素偏移。



[url=https://stackoverflow.com/questions/2358173]更多&回答...[/url]


所有时间均为北京时间。现在的时间是 02:17

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.