imrotate in Matlab App Desinger

Hello,
Is it possible to rotate an image in Matlab app designer?
I input an image using the following code:
% Code that executes after component creation
function startupFcn(app)
imag = imread('cameraman.tif');
handles.I = imresize(imag,0.75);
imshow(handles.I,'Parent',app.UIAxes)
end
How to now rotate the image using a slider.
Under the slider code, I have tried the following but could not get it to work:
% Value changing function: SteeringSlider
function SteeringSliderValueChanging(app, event)
changingValue = event.Value;
angle = round(event.Value);
imshow( imrotate(app.UIAxes,angle,'bilinear','crop') );
end
Can you tell me how to rotate an image in Matlab App Designer? Thanks.

Answers (2)

You're calling imshow on the uiaxes not the image. I would manage this like this:
app.UIAxes = uiaxes; % You won't need this in app designer since it's already there
im = imread('cameraman.tif');
imh = imshow(im, 'Parent', app.UIAxes);
for angle = 0:10:360
imh.CData = imrotate(im,angle,'bilinear','crop');
pause(0.25)
end
Store imh and im as properties of your app.

3 Comments

I tried your suggestion but still did not get the image to rotate.
Here is my code from App Designer:
properties (Access = public)
imageData = imread('cameraman.tif'); % Description
im
imh
end
methods (Access = private)
% Code that executes after component creation
function startupFcn(app)
%imshow(app.imageData,'Parent',app.UIAxes);
%im = imread('cameraman.tif');
imh = imshow(app.imageData, 'Parent', app.UIAxes);
end
% Callback function
function SteeringSliderValueChanged(app, event)
end
% Value changed function: Steer_ValueEditField
function Steer_ValueEditFieldValueChanged(app, event)
%value = app.Steer_ValueEditField.Value;
changingValue = app.SteeringSlider.Value;
end
% Value changing function: SteeringSlider
function SteeringSliderValueChanging(app, event)
changingValue = event.Value;
angle = round(changingValue);
app.imh.CData = imrotate(app.imageData, angle, 'bilinear', 'crop');
drawnow limitrate
% Set numeric display to latest slider value
app.Steer_ValueEditField.Value = changingValue;
end
app.imh.CData = imrotate(app.imageData, ...)
drawnow limitrate
You're rotating the handle not the image data and also need to reference app. Also
I edited the code as per your suggestion (see updated code above) but the image is still not rotating when I move the slider.

Sign in to comment.

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Asked:

on 13 Oct 2017

Commented:

on 24 Oct 2017

Community Treasure Hunt

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

Start Hunting!