Matrix / image rotation
Mostrar comentarios más antiguos
Dear MATLAB community,
I am trying to rotate gridded data (x, y, z) each the size of 1401x1401.
It seems that during rotation the data is cut so that data gets lost. To circumvent that, I create larger matrices Mx, My, Mz.
load test.mat
Mx=nan(2000,2000);
My=nan(2000,2000);
Mz=nan(2000,2000);
Mx(400:1401+400-1,400:1401+400-1)=x;
My(400:1401+400-1,400:1401+400-1)=y;
Mz(400:1401+400-1,400:1401+400-1)=z;
Then, I rotate Mx, My, Mz by the angle phi:
phi = 77;
x_r = imrotate(Mx, -phi,'crop');
y_r = imrotate(My, -phi,'crop');
z_r = imrotate(Mz, -phi,'crop');
When I do imshow(x_r), imshow(y_r), imshow(z_r) it seems to look alright.
However, doing surf(x_r, y_r, z_r, 'FaceAlpha',0.5,'edgecolor','none') or mesh(x_r, y_r, z_r, 'FaceColor','flat','FaceAlpha','0.5','EdgeAlpha','0.5') it looks like that no rotation was performed.
Also, I noticed that data along x=0 and y=0 got removed.
I want to do the rotation to merge x_r, y_r, z_r with other data.
I tried a lot of different other things, e.g., ‘loose’ instead of ‘crop’, replacing zeros with NaNs but I am stuck here. I appreciate any hint or solution.
Best!
3 comentarios
Matt J
el 5 de Mayo de 2023
Your x,y data contains NaNs in the same places as your z data. It is unnecessary and creates headaches if you do this. To suppress particular (x,y,z) points from appearing in a surface plot, it is sufficient for NaNs to be placed in the z data only
PA
el 5 de Mayo de 2023
Matt J
el 5 de Mayo de 2023
I think I should not rotate z but only x and y. Does that make sense?
Rotating z only by phi or rotating x,y only by -phi should have the same effect if you use the myRotate function in my comment below. However, I discourage the latter. Life is always easier if you have a fixed domain space for your functions and surfaces.
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Surface and Mesh Plots en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
