How to connect GUI sliders to image analysis
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
DIMITRIOS THEODOROPOULOS
el 20 de Dic. de 2018
Comentada: DIMITRIOS THEODOROPOULOS
el 22 de Dic. de 2018
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
0 comentarios
Respuesta aceptada
Cris LaPierre
el 20 de Dic. de 2018
Editada: Cris LaPierre
el 20 de Dic. de 2018
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.
0 comentarios
Más respuestas (3)
Cris LaPierre
el 20 de Dic. de 2018
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 comentarios
Cris LaPierre
el 20 de Dic. de 2018
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
el 20 de Dic. de 2018
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
el 20 de Dic. de 2018
1 comentario
Cris LaPierre
el 20 de Dic. de 2018
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
el 21 de Dic. de 2018
Editada: Cris LaPierre
el 21 de Dic. de 2018
7 comentarios
Ver también
Categorías
Más información sobre Interactive Control and Callbacks 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!