What is the best way to find an accurate threshold value for im2bw?

1 view (last 30 days)
I have been attempting to find the best way to threshold an image for the im2bw function however any method I have attempted has resulted in failure. Most recently this has involved plotting a histogram of each colour and depending on where the noise is, using an if loop to remove that noise. The code below demonstrates how I have done this. Does anyone know of a better method so I can accurately find the threshold limit?
if sum(lower_values_red) < sum(higher_values_red) %this loop will decide what part of the histogram to remove
red_lower_limit = double(mean(r(:))) - double(std(double(r(:))));
red_upper_limit = red_realogram.BinLimits(2);
else
sum(lower_values_red) > sum(higher_values_red);
red_lower_limit = red_realogram.BinLimits(1);
red_upper_limit = double(mean(r(:))) + double(std(double(r(:))));
end
red_thresh = red_lower_limit/red_upper_limit;

Answers (1)

Thorsten
Thorsten on 18 Jul 2016
Steve's blog may help: http://blogs.mathworks.com/steve/

Community Treasure Hunt

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

Start Hunting!