2015-12-23 34 views
1

有一個圖像,我想旋轉它的3D方式,我用3D旋轉矩陣定義:R= Rx*Ry*Rz與:Rx (Ry,Rz)是旋轉矩陣與角度約爲x (y,z)軸。所以作爲輸入,我只給出3個角度,並且作爲輸出我得到變形的圖像。在MATLAB代碼:模擬3D旋轉

Rx = [1 0 0; 0 cos(theta) -sin(theta); 0 sin(theta) cos(theta)]; 
Ry = [cos(beta) 0 sin(beta); 0 1 0; -sin(beta) 0 cos(beta)]; 
Rz = [ cos(phi) -sin(phi) 0; sin(phi) cos(phi) 0; 0 0 1]; 
R = Rx * Ry * Rz; 
T = projective2d(R); 
I_deformed = imwarp(I,T); 

莫名其妙地繞x軸和y軸的角度不給我的預測結果,我做錯了什麼,但我不知道它是什麼,請幫助我。

回答

1

我試圖解決沒有圖像處理工具箱的問題。很多關於3D空間旋轉的信息可以在here找到。

我用這個頁面的一些東西來旋轉圖像。然後,我只設置圖的視圖屬性,以便模擬在XY平面上的投影。

這裏是原始和旋轉圖像:

enter image description here

下面是代碼:

path = 'https://www.petfinder.com/wp-content/uploads/2012/11/140272627-grooming-needs-senior-cat-632x475.jpg'; 
[I, map]=imread(path,'jpg'); 

x_size = size(I, 2); 
y_size = size(I, 1); 

[X,Y] = meshgrid(1:x_size, 1:y_size); 
x_coord = X(:);y_coord = Y(:); 

red = reshape(I(:,:,1), [], 1); 
green = reshape(I(:,:,2), [], 1); 
blue = reshape(I(:,:,3), [], 1); 

%Set the rotation angles 
theta = pi/3; beta = pi/4; phi = pi/6; 

%Define the rotation matrices 
Rx = [1 0 0; 0 cos(theta) -sin(theta); 0 sin(theta) cos(theta)]; 
Ry = [cos(beta) 0 sin(beta); 0 1 0; -sin(beta) 0 cos(beta)]; 
Rz = [ cos(phi) -sin(phi) 0; sin(phi) cos(phi) 0; 0 0 1]; 
R = Rx * Ry * Rz; 

%Apply the rotation 
Pout = R*[x_coord.'; y_coord.'; zeros(1,numel(x_coord))]; 
scatter3(Pout(1,:), Pout(2,:), Pout(3,:), 2, double([red green blue])/255); 

%change the direction of the Y-axis 
axis ij; 
%set the axes to the same scale 
axis equal; 

%Add axes-labels if needed 
%xlabel('X'); ylabel('Y'); zlabel('Z'); 

%Simulate the 2D-Projection on the XY-plane by setting the view 
view(0,90); 

%Turn off the grid and the background 
grid off; 
set(gca,'visible','off'); 
+0

謝謝你,你是生命的保護,這是工作完美......但仍然不明白爲什麼3D旋轉矩陣不能與圖像處理工具箱一起工作...... – user3288977