MATLAB GUI: How do I pass image matrix into function

조회 수: 3 (최근 30일)
William Pang
William Pang 2020년 5월 28일
댓글: Tommy 2020년 5월 29일
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
Rik
Rik 2020년 5월 28일
Did you make sure I is a property before trying app.I=?
William Pang
William Pang 2020년 5월 28일
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.

댓글을 달려면 로그인하십시오.

채택된 답변

Tommy
Tommy 2020년 5월 29일
편집: Tommy 2020년 5월 29일
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
William Pang
William Pang 2020년 5월 29일
Yup, I get a different error.
Using just "app.ValueEditField":
It's weird because I am definitely getting a numerical value in the command window (so I know the function is working and something is passing through it) but doesn't seem to talk with the App Designer.
Tommy
Tommy 2020년 5월 29일
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?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Explore and Edit Images with Image Viewer App에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by