user238469
user238469

Reputation:

`rot90` not working as expected for image rotation in Matlab.

IMAGE1

enter image description here

IMAGE2

enter image description here

DESIRED IMAGE

enter image description here

I am using function flipud and rot90 to rotate IMAGE1 to look like IMAGE2 as following:

IMAGE2=rot90(flipud(IMAGE1));

However, somehow I do not get the desired result which is DESIRED IMAGE. Could anyone identify why? Please ignore the side legend cutout in DESIRED IMAGE.

Upvotes: 0

Views: 1004

Answers (1)

Jonas
Jonas

Reputation: 74940

Here's an example for a 2D array (see comments)

%# create a 2D array (3x3, but it'll work for 50x50 as well)
m = magic(3)
m =
     8     1     6
     3     5     7
     4     9     2

%# flip, then rotate, but rotate clockwise, hence the -1
rot90(flipud(m),-1)
ans =
     8     3     4
     1     5     9
     6     7     2

%# Note that this is the same as taking the transpose
m'
ans =
     8     3     4
     1     5     9
     6     7     2

Upvotes: 1

Related Questions