How to add slider to figure ? manual thresholding

5 次查看(过去 30 天)
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

回答(2 个)

Jan
Jan 2016-2-7
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 2016-2-7
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!

Translated by