我有一个图像,我将其转换为多边形类,如何基于质心旋转它?代码:
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);
polyshape.rotate
接受可选的第三个参数refpoint
,该参数将成为旋转的原点:
% ...
b = B{k};
c = stat(k).Centroid;
pgon1 = polyshape(b(:,1), b(:,2));
poly1 = rotate(pgon1, 45, c);