arrays - Rotation of 3D data in XY plane (Matlab) -
i have 3d array contains probability values function of spatial position (x , y coordinates). when plot array using imagesc or surf, elliptic profile maximum. rotate data around point of maximum probability in xy plane such y axis becomes parallel major axis of ellipse (which computed using regionprops). don't want rotate image or surface using imrotate or geometric object rotation, since need array containing rotated data. how achieve if know angle of rotation around z axis (obtained regionprops)?
edit: here code used rotate matrix around centroïd. however, when plot result using surf, weirdest result...
% translation , anti-translation matrix translate = [1 0 0 -centroide(1); 0 1 0 -centroide(2); 0 0 1 0; 0 0 0 1]; anti_translate = [1 0 0 centroide(1); 0 1 0 centroide(2); 0 0 1 0; 0 0 0 1]; % rotation matrix rotate = [cosd(-orientation) -sind(-orientation) 0 0; sind(-orientation) cosd(-orientation) 0 0; 0 0 1 0; 0 0 0 1]; % temporary cell array data transformation data_vector = cell(size(rcb,1),size(rcb,2),size(rcb,3)); % cell array transformed data storage transformed_data = cell(size(rcb,3),1); = 1:(size(rcb,3)) transformed_data{i} = zeros(3, size(rcb,1)*size(rcb,2)); end = 1:size(rcb,3) % temporal dimension j = 1:size(rcb,2) % x dimension k = 1:size(rcb,1) % y dimension % [x y z] vector data_vector{k,j,i} = [j,k,rcb(k,j,i),1]'; % translation data_vector{k,j,i} = translate*data_vector{k,j,i}; % rotation data_vector{k,j,i} = rotate*data_vector{k,j,i}; % anti-translation data_vector{k,j,i} = anti_translate*data_vector{k,j,i}; data_vector{k,j,i} = data_vector{k,j,i}(1:3); transformed_data{i}(:,((j-1)*size(rcb,1)+k)) = data_vector{k,j,i}; end end end %%%% test %%%% : image @ 100 ms figure, imagesc(transformed_data{100}(2,:),transformed_data{100}(1,:),transformed_data{100}(3,:));
i image:
what doing wrong?
have tried rotz
rotation matrix rotations around z-axis , check documentation here.
othewise, can multiply matrix following matrix r
rotation angle γ :
be careful, function cos
, sin
in matlab radian based. can use degree cosd
.
Comments
Post a Comment