任意の点を中心として画像を回転する方法
21 ビュー (過去 30 日間)
古いコメントを表示
お世話になります。
I = readimage('images.jpg');
J = imrotate(I, 45, 'bilinear', 'crop');
figure
imshow(J)
title('Rotated Image')
のように、'imrotate'を使用して画像を回転できますが、画像の中心点を中心とした回転のみです。
任意の点を回転中心として、処理を行える方法があればご教授いただきたいです。
よろしくお願いいたします。
2 件のコメント
Atsushi Ueno
2022 年 10 月 15 日
画像サイズ'FollowOutput'のどこを切り出すかという視点で考えるとなんか難しいですね。
下記は直接の回答になってないのでコメントに残します。
変換行列の演算を自分で書くと自由にパラメータを動かす事が出来ます。(回転中心はcx,cy。0で画像左上が回転中心)
I = imread('onion.png'); sz = size(I)';
cx = sz(1)/2; cy = sz(2)/2; % cx,xyが回転中心、
th = pi / 10; % thは回転角度
c = [0, 0, cx; % 平行移動行列
0, 0, cy;
0, 0, 0];
rt = [cos(th), sin(th), 0; % 回転行列
-sin(th), cos(th), 0;
0, 0, 1];
tr = (eye(3) + c) * rt * (eye(3) - c); % 平行移動⇒回転⇒平行移動
for x = 1:sz(1)
for y = 1:sz(2)
org = round(tr * [x; y; 1]);
if any(org < [1; 1; 1] | org > sz)
J(x,y,:) = uint8([0 0 0]);
else
J(x,y,:) = I(org(1),org(2),:);
end
end
end
imshow(J);
回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で 幾何学的変換とイメージ レジストレーション についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
