うーん... 私はこのことについて 100% パーセントではありませんが、興味深い質問であり、私の仕事に関連していたので、試してみようと思いました.
編集:組み込みを使用せずにこれを一度試しました。それが私の最初の答えでした。それから、あなたのやり方でとても簡単にできることに気付きました:
あなたの質問に対する簡単な答えは、 z 軸について正しい回転行列を使用することです。
R = [cos(theta) -sin(theta) 0;
sin(theta) cos(theta) 0;
0 0 1];
これを行う別の方法があります(私の元の答え):
私がしたことを共有します。うまくいけば、これはあなたにとって役に立ちます。私は 2D でのみ実行しました (ただし、3D に拡張するのは簡単なはずです)。イメージを平面で回転させたい場合は、現在コーディングしている別の回転行列を使用する必要があることに注意してください。Z 軸を中心に回転する必要があります。
これらの matlab ビルトインは使用しませんでした。
情報については、 http://en.wikipedia.org/wiki/Rotation_matrixを参照しました。
im = double(imread('cameraman.tif')); % must be double for interpn
[x y] = ndgrid(1:size(im,1), 1:size(im,2));
rotation = 10;
theta = rotation*pi/180;
% calculate rotation matrix
R = [ cos(theta) -sin(theta);
sin(theta) cos(theta)]; % just 2D case
% calculate new positions of image indicies
tmp = R*[x(:)' ; y(:)']; % 2 by numel(im)
xi = reshape(tmp(1,:),size(x)); % new x-indicies
yi = reshape(tmp(2,:),size(y)); % new y-indicies
imrot = interpn(x,y,im,xi,yi); % interpolate from old->new indicies
imagesc(imrot);

私自身の質問は次のとおりです。「画像を回転させる原点をどのように変更しますか?明らかに、左上隅の (0,0) を中心に回転しています。
EDIT 2質問者のコメントに応えて、もう一度やり直しました。
今回はいくつか修正しました。元の質問と同じ変換行列 (約 x) を使用しています。画像の中心でs (0,0,0 を入れる) を
やり直すことで、画像の中心を中心に回転しました。ndgrid
また、画像の 3 つの平面を表示することにしました。これは元の質問にはありませんでした。中央の平面が関心のある平面です。中間面だけを取得するには、ゼロ パディングを省略し、3 番目のndgrid
オプションを1
の代わりに再定義します-1:1
。
im = double(imread('cameraman.tif')); % must be double for interpn
im = padarray(im, [0 0 1],'both');
[x y z] = ndgrid(-floor(size(im,1)/2):floor(size(im,1)/2)-1, ...
-floor(size(im,2)/2):floor(size(im,2)/2)-1,...
-1:1);
rotation = 1;
theta = rotation*pi/180;
% calculate rotation matrix
R = [ 1 0 0 ;
0 cos(theta) -sin(theta);
0 sin(theta) cos(theta)];
% calculate new positions of image indicies
tmp = R*[x(:)'; y(:)'; z(:)']; % 2 by numel(im)
xi = reshape(tmp(1,:),size(x)); % new x-indicies
yi = reshape(tmp(2,:),size(y)); % new y-indicies
zi = reshape(tmp(3,:),size(z));
imrot = interpn(x,y,z,im,xi,yi,zi); % interpolate from old->new indicies
figure;
subplot(3,1,1);imagesc(imrot(:,:,1)); axis image; axis off;
subplot(3,1,2);imagesc(imrot(:,:,2)); axis image; axis off;
subplot(3,1,3);imagesc(imrot(:,:,3)); axis image; axis off;
