After uploading an image, rotate the image from GUI pushbutton?

Having issues rotating an image in my GUI after it has been uploaded onto the GUI. I believe it has something to do with keeping global variables attached to the image after it has been selected. I am using 'imrotate' to rotate the image 90 degrees but I'm still having issues with rotating the image after it has been uploaded. Any suggestions?

1 comentario

Please post the relevant code and explain the issues you have with any details. How could we suggest an improvement otherwise?

Iniciar sesión para comentar.

Respuestas (2)

[filename, filedir] = uigetfile('*.tif');
fullname = fullfile(filedir, filename);
TheImage = imread(fullname);
RotImage = imrotate(TheImage, 90);
ax1 = subplot(1,2,1); imshow(TheImage, 'Parent', ax1); title('original');
ax2 = subplot(1,2,2); imshow(RotImage, 'Parent', ax2); title('rotated');
handles.TheImage = TheImage;
handles.RotImage = RotImage;
fig = ancestor(ax1, 'figure');
guidata(fig, handles);
If you want to rotate the image in a button callback, you can attach the image array to the handles structure like Walter did, or you can make the array global. Simply have the line
global TheImage;
in every function where you want to use TheImage, like the button that reads in TheImage and displays it, and the other button that rotates and displays it.

Preguntada:

el 1 de Mayo de 2016

Respondida:

el 2 de Mayo de 2016

Community Treasure Hunt

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

Start Hunting!

Translated by