Load image in App Designer

16 次查看(过去 30 天)
N
N 2023-10-10
Hi everyone, I have a code to reconstruct image MRI. First I want to create a Select Image Button to select image from my computer and I create RUN Button to run my code with the image i selected. But I don't know how to get the image I choosed in Select Image Button To RUN Button. When I run it can not recognized the image.
Unrecognized function or variable 'image1'.

回答(1 个)

Pratyush Swain
Pratyush Swain 2023-10-10
Hi N,
I understand you pass the image obtained in the 'SelectImageButtonPushed' function to the 'RUNButtonPushed' function in App Designer.
To acheive this you will need to setup a new property in a user defined properties block.Please refer to https://in.mathworks.com/matlabcentral/answers/1829948-passing-objects-from-app-designer-to-the-workspace#comment_2749059 to create a basic property.
Assuming you have a made a property named 'image' , you can refer to the implementation below:
function SelectImageButtonPushed(app, event)
% Open a file dialog to select an image file
[file, path] = uigetfile({'*.jpg;*.png;*.bmp', 'Image Files (*.jpg, *.png, *.bmp)'}, 'Select Image File');
% Read the selected image
image = imread(fullfile(path, file));
% Store the image in the app object as a property
app.image = image;
end
% Run Button Callback
function RUNButtonPushed(app, event)
% Check if an image is selected
if isempty(app.image)
% Display an error message if no image is selected
errordlg('No image selected.', 'Error', 'modal');
return;
end
% Perform operations on the selected image
% Access the image using app.image
% Example:
processedImage = imresize(app.image, 0.5);
% Display the processed image or perform any other desired operations
imshow(processedImage, 'Parent', app.UIAxes);
end
Hope this helps.

类别

Help CenterFile Exchange 中查找有关 Convert Image Type 的更多信息

产品


版本

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by