After uploading an image, rotate the image from GUI pushbutton?
Show older comments
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 Comment
Jan
on 1 May 2016
Please post the relevant code and explain the issues you have with any details. How could we suggest an improvement otherwise?
Answers (2)
Walter Roberson
on 1 May 2016
[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);
Image Analyst
on 2 May 2016
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.
Categories
Find more on Convert Image Type in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!