Rotate image in Matlab app designer

6 次查看(过去 30 天)
Hello,
I was able to get an image rotated using Matlab GUI. I am now trying to implement the same effects using Matlab App Designer. Can you direct me as to how I can go about rotating the image using App designer with a slider.
Here is an extract of the code putting the image in the UIaxes:
% Code that executes after component creation
function startupFcn(app)
imshow('cameraman.tif','Parent',app.UIAxes)
end
% Value changing function: SteeringSlider
function SteeringSliderValueChanging(app, event)
changingValue = event.Value;
end
How to now rotate the image?
Thanks.

回答(2 个)

Rajesh Balagam
Rajesh Balagam 2017-10-16
编辑:Rajesh Balagam 2017-10-16
You need to store the image data in the app using a custom public property and access this data to rotate the image in the callback for slider.
Store the image data:
app.imageData = imread('cameraman.tif');
Rotate the image using imrotate function in slider callback:
rotatedImage = imrotate(app.imageData, changingValue);
Refer to this link ( https://www.mathworks.com/help/matlab/creating_guis/share-data-across-callbacks-in-app-designer.html) on how to share data between callbacks in appdesigner.
  1 个评论
monkey_matlab
monkey_matlab 2017-10-23
This solution does not work.
Also, the link is not valid.
This is what I have tried as per your suggestion but still not working:
properties (Access = public)
imageData = imread('cameraman.tif'); % Description
end
methods (Access = private)
% Code that executes after component creation
function startupFcn(app)
imshow(app.imageData,'Parent',app.UIAxes);
end
% Value changed function: Steer_ValueEditField
function Steer_ValueEditFieldValueChanged(app, event)
%value = app.Steer_ValueEditField.Value;
changingValue = app.SteeringSlider.Value;
rotatedImage = imrotate(app.imageData, changingValue);

请先登录,再进行评论。


Repon
Repon 2025-5-7
编辑:Walter Roberson 2025-5-7
Hello, if your image is in the same folder location of your program, the following codes should work to rotate an image.
Insert an Axes component and a slider component in your design window and then write folowing codes in the "SliderValueChanging" callback.
changingValue = event.Value;
img = imread('YourImage.png');
B = imrotate(img,changingValue);
imshow(B,'Parent',app.UIAxes);

产品

Community Treasure Hunt

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

Start Hunting!

Translated by