1

I have a 3D matrix with the dimensions X:24, Y:24, and Z:61397. Z corresponds to the number of frames. when I plot each frame I get an image that is rotated 45 degree clockwise. enter image description here

I've been trying to rotate the matrix so that the pictures can be straight.(It needs to be rotated 45 degree anticlockwise).

I've tried multiplication by the following rotation matrix based on previous answers for similar question:

% rotation matrix 
theta = pi/4;
Rot = makehgtform('xrotate',theta);
Rot = Rot(1:3,1:3);

I got an error due to the difference in size. Do I need to extend the rotation matrix to 24by24? If yes, how?

lhcgeneva
  • 1,981
  • 2
  • 21
  • 29
Rajab
  • 21
  • 4
  • If you post your image somewhere on the web and add a link to your question, someone will add it in for you. Do you have the image processing toolbox? If so, then @lhcgeneva's answer is much easier than what you're trying to do. If not, please read the duplicate post and understand it. `makehgtform` is not the best choice for what you're trying to do and I think you want to rotate about the z-axis rather than x. – beaker Sep 18 '15 at 15:13
  • @beaker here's the image: https://www.dropbox.com/s/yelu7jgcup3m4do/frame100..jpg?dl=0 – Rajab Sep 25 '15 at 11:53
  • Actually, the rotation is not my main interest. The Image in the following link: https://www.dropbox.com/s/yelu7jgcup3m4do/frame100..jpg?dl=0 represents values of void fraction [0-1], the colors correspond to air and liquid. I need to count the number of pixel immersed in liquid to get the liquid level. That's why I need to rotate the image so the liquid level is parallel with X axis. The image is 24 by 24 pixels which correspond to the points of measurements. – Rajab Sep 25 '15 at 11:59
  • Why do you need to rotate the image to do that? Just count the number of non-black pixels. – beaker Sep 25 '15 at 14:49
  • By the way, @lhcgeneva's solutions works just fine for me on your image. – beaker Sep 25 '15 at 22:59
  • @beaker Sorry I forgot to explain the nature of the image.The image was generated from a sensor that consist of 2 perpendicular grids (24x24).Since the sensor was installed in a horizontal pipe with 45 degree angle to the liquid level, I need to get the measuring lines parallel to liquid level. I've the 3D matrix of the images and I need to apply the rotation to this matrix so when I plot the values I get straight images. – Rajab Sep 28 '15 at 11:42
  • @lhcgeneva's solution does work but changes the dimensions of the original matrix. In my case I don't want to loose the matrix size as it corresponds to my measuring points and hence the size of the pipe. – Rajab Sep 28 '15 at 11:42
  • "...but changes the dimensions of the original matrix." Of course it does. If you rotate a square 45 degrees, the height is now the length of the diagonal instead of the length of the side. If you read the documentation provided in the link, there's a way to stop it from doing this. – beaker Sep 28 '15 at 14:07

1 Answers1

1

If all you are doing is rotating an image by 45 degrees you can simply use imrotate.

imrotate(Stack, 45);

where Stack is your 3D matrix. In case you are looking for a solution which doesn't rely on the image processing toolbox have a look here.

Community
  • 1
  • 1
lhcgeneva
  • 1,981
  • 2
  • 21
  • 29