MATLAB GUI: How do I pass image matrix into function
1 view (last 30 days)
Show older comments
Hi,
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
trialfunction(I_M,filter_size)
S = app.ValueEditField;
The "trial function" is just a simple range filter that manipulates the image (stored in a 2D matrix):
function[S]=trialfunction(I_M,filter_size);
I_bin_regions = rangefilt(I_M,ones(filter_size,filter_size));
S=sum(I_bin_regions,'all')
end
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'.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/304867/image.png)
2 Comments
Accepted Answer
Tommy
on 29 May 2020
Edited: Tommy
on 29 May 2020
In appdesigner, first make sure you are in code view:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/305047/image.png)
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/305051/image.png)
(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.
6 Comments
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?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/305487/image.png)
More Answers (0)
See Also
Categories
Find more on Explore and Edit Images with Image Viewer App in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!