MATLAB GUI: How do I pass image matrix into function
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
William Pang
el 28 de Mayo de 2020
Comentada: Tommy
el 29 de Mayo de 2020
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'.
2 comentarios
Respuesta aceptada
Tommy
el 29 de Mayo de 2020
Editada: Tommy
el 29 de Mayo de 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.
6 comentarios
Tommy
el 29 de Mayo de 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?
Más respuestas (0)
Ver también
Categorías
Más información sobre Explore and Edit Images with Image Viewer App en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!