Luke
Luke

Reputation: 2400

How to rotate axes object in Matlab

I'm looking for a way to rotate my image in axes in Matlab. I have tried to achieve this using rotate and imrotate but both functions don't work for me. Do anyone has an idea how to solve my problem?

imshow(imread('theImage.png'),'Parent',handles.axes3);

imrotate(handles.axes3, 45); %simply doesn't work
set(handles.axes3,'Rotation',45); %no 'Rotation' in axes
%I don't even know how to use just rotate()

Upvotes: 0

Views: 321

Answers (1)

Hoki
Hoki

Reputation: 11792

Just to be clear, there is no way to rotate an axes object. But you can rotate the image data then display them again in their rotated state.

The function imrotate does rotate the "image data" you supply in input and return a matrix representing the rotated image data. So in your case, do not display directly after reading the file. Get the image data in a variable, rotate that with imrotate, then display the rotated image (or do what you need with it)

As an example:

img = imread('peppers.png') ; %// get the image data into the variable "img"
img2 = imrotate(img,90) ;     %// get the "rotated" image data into the variable "img2"

%// display both "img" and "img2"
subplot(1,2,1) ; imshow( img ) 
subplot(1,2,2) ; imshow( img2 ) 

will produce: rotated

Upvotes: 2

Related Questions