How to connect GUI sliders to image analysis

조회 수: 1 (최근 30일)
DIMITRIOS THEODOROPOULOS
DIMITRIOS THEODOROPOULOS 2018년 12월 20일
댓글: DIMITRIOS THEODOROPOULOS 2018년 12월 22일
I want to instantiate this GUI
The project is the analysis of bee pollen.I first load the image by the left pushbutton.There is a warnig msg imcrop which croppes the image to the desired ROI.ANd then there is a Statistic Analysis.Because of the trash there is a second take by which you can select the Threshold (slider on the top) and also select which sizes aroud the mean Area to select(slider 2&3 below).Then by pushbutton(new Analysis )there is a retake with new Statistic analysis..My problem is i dont know how to connect the sliders and the new Analysis with the retake procedure.This is my GUI code.
EDIT: I've attached your code to your post rather than display it all here

채택된 답변

Cris LaPierre
Cris LaPierre 2018년 12월 20일
편집: Cris LaPierre 2018년 12월 20일
This is how I would modify your gui to get the image erodeII and slider values into pushbutton3_Callback
...
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
...
handles.erodedII = imerode(erodedI,se);
axes(handles.axes2)%%%%%%%%%
imshow(handles.erodedII);
...
L=bwlabel(handles.erodedII);
% Update handles structure
guidata(hObject, handles);
...
% --- Executes on slider movement.
function slider1_Callback(hObject, eventdata, handles)
...
handles.slide_thresh=get(hObject,'value');
% Update handles structure
guidata(hObject, handles);
...
% --- Executes on slider movement.
function slider2_Callback(hObject, eventdata, handles)
...
handles.slide_min=get(hObject,'value');
% Update handles structure
guidata(hObject, handles);
...
% --- Executes on slider movement.
function slider3_Callback(hObject, eventdata, handles)
...
handles.slide_max=get(hObject,'value');
% Update handles structure
guidata(hObject, handles);
...
...
% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
img = handles.erodedII;
thresh = handles.slide_thresh;
slide_min = handles.slide_min;
slide_max = handles.slide_max;
In pushbutton3, you do not have to assign fields on the handles structure to a variable in order to use them. I just did that to demonstrate how to access them.

추가 답변 (3개)

Cris LaPierre
Cris LaPierre 2018년 12월 20일
Sorry but it's not clear to me what you mean by "retake".
From what I understand, I would recommend moving your statistics code to a new function (you can create your own functions, in addition to callbacks). At the end of your callback function that loads the image (pushbutton1?) you can call the statistics function.
The benefit is that any other callback can also call the statistics function. So in your New Analysis callback (pushbutton2?), you would also just call the statistics function.
Any variables you need could be added to the handles structure to make them available.
  댓글 수: 3
Cris LaPierre
Cris LaPierre 2018년 12월 20일
Connect to what? What should they be doing that they are not?
I see that changing the sliders 1-3 updates the string in edit10, edit11 and edit12 (though I can only guess which slider/edit box each one is). You know how to set the value of a slider from other callbacks.
set(handles.slider1,'value',string2num(edit));
Use a 'get' instead to access the slider value when needed in your new analysis
slide_thresh=get(handles.slider1,'value');
The other option is to add your slider values to the handles structure. Just be sure to update the handles structure so the changes are saved.
handles.slide_thresh=get(hObject,'value');
set(handles.edit10,'string',num2str(slide_thresh));
% Update handles structure
guidata(hObject.handles);
Image Analyst
Image Analyst 2018년 12월 20일
Like Cris say, you can create a custom function, like "PerformStatistics" or something:
function results = PerformStatistics(handles)
% Now do stats and make results
You only need handles if you want to use it in the function, for example to read the value of a slider, to get what files the user clicked on in a listbox, to check if the user checked a checkbox, etc. You could also pass in the values if you want, for example:
function results = PerformStatistics(sliderValue, computeResiduals, showPlot)
Then, in the callback function of the slider, or a button, or a checkbox, or wherever you want, you can just call the function, for example:
sliderValue = handles.slide_thresh.Value;
computeResiduals = handles.chkResiduals.Value;
results = PerformStatistics(sliderValue, slide_thresh, handles.chkShowPlot.Value);
So in your slider callback, you might simply set up the text label for it (assuming you have one)
handles.txtSliderLabel.String = sprintf('Threshold = %.2f', handles.slide_thresh.Value);
and then call PerformStatistics. If you have a table (uigrid) control on your GUI then you can load your results into that if you want. Or you could call xlswrite() or whatever you want to do with the results. You don't even have to pass any results back to the calling routine if you take care of everything inside PerformStatistics(). I hope that explains things a little more for you.

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


DIMITRIOS THEODOROPOULOS
DIMITRIOS THEODOROPOULOS 2018년 12월 20일
Ι am still very confused...I start with some default values and crop the image.I get an analyzed image.Now i use the slider to get new values and then i pushbutton "new Analysis".
I dont want a new function with another new ROI i want to use the same ROI as in the beginning .But pushbutton3 doent recognize the cropped image(erodedII)..
how can i pass erodedII to pushbutton 3,, get new values from sliders 1-3 and reanalyse..
Forgive me, i am new in matlab and i apologise for this,,,,You guys give me the best advice but i still dont get it...
  댓글 수: 1
Cris LaPierre
Cris LaPierre 2018년 12월 20일
Do you realize there is no code in pushbutton3's callback?
Let's forget the gui for a second.
Can you provide a script that starts with the cropped image and runs the new analysis and statistics on it? If you can provide working code, it will be much easier for us to show you how to adapt that to a gui.
Also, as I said before, we have no idea what components go to what callbacks. Some we can guess, but you also need to provide that info.

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


DIMITRIOS THEODOROPOULOS
DIMITRIOS THEODOROPOULOS 2018년 12월 21일
편집: Cris LaPierre 2018년 12월 21일
Cris i copied your code and get the following error
i modified the code bit in order to see the values from sliders in edit texts..But it does work either..
here is the complete code
EDIT: I've attached your updated code to your post rather than display it all here
  댓글 수: 7
DIMITRIOS THEODOROPOULOS
DIMITRIOS THEODOROPOULOS 2018년 12월 21일
following the second advise i just copy/paste the 3 lines...but i get this :ice_screenshot_20181221-172353.png
DIMITRIOS THEODOROPOULOS
DIMITRIOS THEODOROPOULOS 2018년 12월 22일
i solved it by using in pushbutton3 area:
if isfield (slide_thresh) &(slide_min) &(slide_max)
% pushbutton3 code...
end

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

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by