음 ... 나는이 물건에 100 % 퍼센트가 아니지만 흥미로운 질문이었고 내 작업과 관련이있어서 나는 놀아서 한 발을 내줄 것이라고 생각했습니다.
EDIT :이 기능은 내장형을 사용하지 않고 한 번 사용해 보았습니다. 그것은 나의 원래 대답이었다.
이
귀하의 질문에 쉽게 대답은 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), 왼쪽 상단 중심으로 회전하고있어, 분명히 이미지를 회전하는에 대한 원점을 변경합니까? .
편집 아스 커의 의견에 대응하여 2, 나는 다시 시도했습니다.
나는 몇 가지 고정이 시간을.이제 원래의 질문에서와 같은 변형 행렬 (x에 대해)을 사용하고 있습니다.
이미지의 중심에 ndgrid
(0,0,0 지정)을 반복하는 방식으로 이미지의 중심을 중심으로 회전했습니다. 나는 또한 이미지의 3면을 보여 주기로 결정했다. 이것은 원래의 질문에 있지 않았습니다. 중간면은 관심 비행기입니다. 중간 평면을 얻으려면 제로 패딩을 생략하고 -1:1
대신 1
이되도록 ndgrid
세 번째 옵션을 다시 정의하면됩니다.
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;
내 대답 도움이 경우에 당신은 대답으로 표시 줄래 :
새로운 설정은? 감사. – Frederick
@klurie'imagehomog' 함수를 사용하여 결과를 얻었습니까? –