Load image in App Designer
16 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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'.

0 commentaires
Réponses (1)
Pratyush Swain
le 10 Oct 2023
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.
0 commentaires
Voir également
Catégories
En savoir plus sur Convert Image Type dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!