MATLAB GUI: How do I pass image matrix into function

9 views (last 30 days)
So I'm trying to read the image and then pass it through a function so that I can perform image analysis with some defined parameters.
For the "Load Image" button here's the code:
% Button pushed function: LoadImageButton
function LoadImageButtonPushed(app, event)
[FileName, FilePath]= uigetfile('.TIF');
I=imread([FilePath FileName]);
imshow(I, 'Parent' , app.UIAxes); %Displays selected image onto original image
I would then need to define some paratmers (Filter Size, Threshold, Cut Cells Regions) before running my external function. Once you input the paramters and press "Compute", I'm hoping that it would go into my function that I've written (called trialfunction here):
function ComputeButtonPushed(app, event)
filter_size = app.FilterSizeEditField; %Input parameter
S = app.ValueEditField;
The "trial function" is just a simple range filter that manipulates the image (stored in a 2D matrix):
I_bin_regions = rangefilt(I_M,ones(filter_size,filter_size));
However, I'm having trouble linking the data from I (2D matrix) into my function. How can I "connect" the "Load Image" function with the "Compute Button" function?
Thanks so much!
Note: I have tried adding app.I.ImageSource = imread (...) but that doesn't work. Error message says "
Unrecognized method, property, or field 'I' for class 'imageprocessing'.
William Pang
William Pang on 28 May 2020
I'm a bit new to the GUI interface, so apologies if I'm asking stupid questions, but how would you make I a property? I know that the image is reading properly (since I'm able to display it without adding the "app.I", just as "I") but would appreciate any pointers on how to make "app.I" a property.

Sign in to comment.

Accepted Answer

Tommy on 29 May 2020
Edited: Tommy on 29 May 2020
In appdesigner, first make sure you are in code view:
Then in the code browser on the left side, go to the tab labeled Properties and select the green plus sign. The property will be private by default. If you want the property to be public (accessible from outside the app), you can click the down arrow and choose Public Property.
(edit) If you are calling imshow and rangefilt on this I, then I would use
app.I = imread (...)
where app.I is an array, rather than
app.I.ImageSource = imread (...)
where app.I is a uiimage.
Tommy on 29 May 2020
Ah, there are two different types of edit fields in appdesigner, text and numeric. If you want to display numbers, your edit field needs to be numeric. Are you sure you chose the correct style when you created the user interface?

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!