Load image in App Designer
조회 수: 19 (최근 30일)
이전 댓글 표시
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
답변 (1개)
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.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Convert Image Type에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!