Here's my complete code for a gui where I want to adjust the threshhold of an image with a slider in the figure. I have everything working except for the slider step size. When I keep the line in that specifies what step size the slider should take, the slider doesn't work at all. When I leave that line out, things work exactly as I want (except for the step size of course).
Any help or input would be greatly appreciated!
function final_image_threshhold = GetImageThreshhold(image,flag) if (strcmp(flag,'None') == 1) function_marker = 1; elseif (strcmp(flag,'AOMDEL') == 1) function_marker = 2; else error('Unknown flag in GetImageThreshhold'); end max_threshhold = max(image(:)); se = strel('disk',10,4); if (function_marker == 1) new_image = 255*(double(image > round(max_threshhold/2))); default_colormap = 1; elseif (function_marker == 2) new_image = image > round(max_threshhold/2); new_image = bwareaopen(new_image,13); new_image = bwmorph(new_image,'spur'); new_image = imdilate(imerode(imdilate(new_image,se),se),se); new_image = bwlabel(new_image); default_colormap = 1; else end current_figure = imshow(imadjust(uint8(new_image))); colormap_menu = uicontrol('Style','popupmenu',... 'Value',default_colormap,... 'String',{'ColorMap','winter','lines','jet','hsv','hot','cool','gray'},... 'Position',[20 -10 80 50],... 'Callback', @SetColorMap); %#ok<NASGU>
threshhold_slider = uicontrol('Style','slider',... 'Min',0,'Max',ceil(max_threshhold),'Value',round(max_threshhold/2),... 'SliderStep',[100*round(1/(max_threshhold + 1)),250*round(1/(max_threshhold + 1))],... %%%_______Line in Question_______%%% 'Position',[110 15 410 25],... 'Callback', {@SetThreshholdLevel,image,current_figure,function_marker}); threshhold_button = uicontrol('Style', 'pushbutton',... 'String', 'Continue',... 'Position', [530 14 70 28],... 'Callback', @ThreshButtonDone); %#ok<NASGU>
figure(999); set(999,'Visible','off'); waitfor(999); final_image_threshhold = get(threshhold_slider,'Value'); close all; end function SetColorMap(source,~) val = get(source,'Value'); maps = get(source,'String'); newmap = maps{val}; colormap(newmap); end function SetThreshholdLevel(slider_uic,~,image,current_figure,function_marker) new_threshhold = round(get(slider_uic,'Value')) se = strel('disk',10,4); if (function_marker == 1) new_image = uint8(image > new_threshhold)*255; elseif (function_marker == 2) new_image = uint8(image > round(new_threshhold)); new_image = bwareaopen(new_image,13); new_image = bwmorph(new_image,'spur'); new_image = imdilate(imerode(imdilate(new_image,se),se),se); new_image = bwlabel(new_image); else end set(current_figure,'cData',new_image); end function ThreshButtonDone(~,~) close(999); end
Best Answer