我有一张要转换为多边形类的图像,如何基于质心点旋转它? 代码:
url='http://www.clker.com/cliparts/T/i/o/c/X/Q/airplane-md.png';
I = imread(url);
I = rgb2gray(I);
I = imcomplement(I);
imshow(I);
hold on;
BW = imbinarize(I);
[B,L] = bwboundaries(BW,'noholes');
k=1;
stat = regionprops(I,'Centroid');
b = B{k};
c = stat(k).Centroid;
yBoundary = b(:,2);
xBoundary = b(:,1);
cy = c(:,2);
cx = c(:,1);
pgon1 = polyshape(yBoundary, xBoundary);
plot(pgon1);
poly1 = rotate(pgon1,45);
plot(poly1);
答案 0 :(得分:2)
polyshape.rotate
接受可选的third argument refpoint
,它将作为旋转的原点:
% ...
b = B{k};
c = stat(k).Centroid;
pgon1 = polyshape(b(:,1), b(:,2));
poly1 = rotate(pgon1, 45, c);