我試圖解決沒有圖像處理工具箱的問題。很多關於3D空間旋轉的信息可以在here找到。
我用這個頁面的一些東西來旋轉圖像。然後,我只設置圖的視圖屬性,以便模擬在XY平面上的投影。
這裏是原始和旋轉圖像:
下面是代碼:
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');
謝謝你,你是生命的保護,這是工作完美......但仍然不明白爲什麼3D旋轉矩陣不能與圖像處理工具箱一起工作...... – user3288977