필터 지우기
필터 지우기

how to rotate a matrix 5x4 by 45° around the origin (0,0) ?

조회 수: 10 (최근 30일)
Makrim
Makrim 2015년 5월 16일
댓글: Walter Roberson 2015년 5월 16일
Suppose I have a matrix M of 5x4 dimension (this is represent an image) :
M =[3 4 8 9;
1 6 7 3;
9 8 3 1;
1 2 2 0;
7 2 3 5];
I would like to rotate it around the origin (0,0) with an angle of 45°.
From what I have found on the net , I have to multiply M by Rotation Matrix R is as follow :
R = [ cosd(45) -sind(45);
sind(45) cosd(45)]
Now do I simply multiply M by R and get a rotated matrix ??? like this :
rotM = R*M
I think I will have a problem of dimensions ? please how to rotate a matrix 5x4 by 45° around the origin (0,0)?
PS: imrotate, rot90, flip* and rotate is not suitable here, thank you in advance.
  댓글 수: 2
David Young
David Young 2015년 5월 16일
편집: David Young 2015년 5월 16일
If you pre-multiply M by a rotation matrix R, that rotates each column of M, as a vector, in a space of 5 dimensions. Your rotation matrix must be 5x5, not 2x2 as you show, and you need to specify the rotation axis in 5-D space.
But I suspect that you don't mean that kind of rotation, because you say M represents an image. It's common to rotate the coordinates in which the image is represented - but the matrix multiplication is applied to the coordinates, not the image matrix itself, and interpolation is then needed to get the rotated image array. imrotate does this.
All of which comes to: If M represents an image, why is imrotate not suitable?
Image Analyst
Image Analyst 2015년 5월 16일
Where is your pivot point (center of rotation)? Which of those elements in your example, or where in between the elements or outside of them, do you call the (0,0) location?

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2015년 5월 16일
Use matrix multiplication, the * operator, not the .* operator.
Remember that in MATLAB, sin() and cos() take radians as the argument, not degrees. You can use sind() and cosd() for degrees.
  댓글 수: 2
Makrim
Makrim 2015년 5월 16일
When I use * I get this error :
Error using *
Inner matrix dimensions must agree.

댓글을 달려면 로그인하십시오.

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by