How to add slider to figure ? manual thresholding

8 views (last 30 days)
Hi
I have a an image that I want to add a ui to threshold manually. code below
im = imread('image.png);
for i = 1:rows
for j = 1:cols
if(im(i,j) < threshold)
out(i,j) = 0;
elseif(im(i,j) > threshold)
out(i,j) = 1;
end
end
end
imshow(out);
how do I add a slider that can manually change the threshold in the figure ? help thanks

Answers (2)

Jan
Jan on 7 Feb 2016
At first simplyfy your code to the single line - assumed, that you do not want to keep the values of im==threshold:
out = double(im > threshold);

Image Analyst
Image Analyst on 7 Feb 2016
See how I did it in my interactive thresholding app: http://www.mathworks.com/matlabcentral/fileexchange/29372-thresholding-an-image
Basically put down a slider on your GUI. Then in your code, get its value
threshold = get(handles.sldThreshold, 'Value');
Then use that. It would also be nice if you use line() to place a vertical bar over the histogram like I do. This is extremely helpful to the user.

Community Treasure Hunt

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

Start Hunting!