Dear Matlab Community,
I'm working to create a tool that would measure diameter of our fibers. We've decided to create a GUI for ease of use and to change parameters when needed.
I'm creating GUI with the help of GUIDE. I want to have image updated on the axes when slider is moved, but it doesn't seem to work. Disp line is executed when slider is moved, but I'm not sure why picture isn't displayed. How do I know if bwopen line is executed? Why do variable disappear from matlab workspace? Lastly, Am I using right technique to import and handle images?
I'm totally new to this. I'm referring books to learn about GUI. I'm struggling with slider for about two weeks.
I'm referring to this text: "Learning to Program with MATLAB – Building GUI Tools"
Is there any other tutorial or text you'd recommend?
Sincerely, Kev
Here is the code for GUI:
% --- Executes on button press in load_file.
function load_file_Callback(hObject, eventdata, handles) % hObject handle to load_file (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global read_image [filename, user_canceled] = imgetfile(); %fmt = 'jpg';
%[path,user_cance]=imgetfile();
if user_canceled msgbox(sprintf('Error'),'Error','Error'); return end read_image = imread(filename); axes(handles.axes1); imshow(read_image); % --- Executes on button press in binarize.
function binarize_Callback(hObject, eventdata, handles) % hObject handle to binarize (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global read_image colour_to_gray = rgb2gray(read_image); % Apply median filtering on grayscale image for smoothing
filtered_image = medfilt2(colour_to_gray); %imtool(filtered_image)
% Convert grayscale into Binary using Otsu Method
level = graythresh(filtered_image); binary = im2bw(filtered_image, level); axes(handles.axes1); imshow(binary); % --- Executes on slider movement.
function xSlider_Callback(hObject, eventdata, handles) % hObject handle to xSlider (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
global binary x=get(handles.xSlider, 'Value'); xs=num2str(x); set(handles.xText, 'String', xs); disp( ' Go, go, go, world! ' ); bw_open = imopen(binary, strel('disk', x)); axes(handles.axes1); imshow(bw_open)
Best Answer