Question

I have a vector for which I need to calculate a threshold to convert it to a binary vector (above threshold=1, below=0). The values of the vector are either close to zero or far from it. So if plotted the vector, values either lie near X-axis or shoot up high(so there is a clear difference between the values). Each time, the values in the vector change so I need to calculate the threshold dynamically. There is no limit on max or min values that the vector can take. I know that otsu's method is used for grayscale images but since the range values for my vector is varying, I think I cannot use it. Is there any standard way to calculate threshold for my case? If not, are there any good workarounds?

No correct solution

OTHER TIPS

I suggest you specify the percentage of values that will become 1, and use the corresponding percentile value as the threshold (computed with prctile function from the Statistics Toolbox):

x = [3 45 0.1 0.4 10 5 6 1.2];
p = 70; %// percent of values that should become 1

threshold = prctile(x,p);
x_quant = x>=threshold;

This approach makes the threshold automatically adapt to your values. Since your data are unbounded, using percentiles may be better than using averages, because with the average a single large value can deviate your threshold more than desired.

In the example,

x_quant =

     0     1     0     0     1     0     0     0

if the limits dont differ in a single vector and the 0 and 1 values are nearly equal in probability, why dont you simply use the mean of the vector as a threshold?

>> X=[6 .5 .9  3 .4 .6 7]

X =

    6.0000    0.5000    0.9000    3.0000    0.4000    0.6000    7.0000

>> X>=mean(X)

ans =

     1     0     0     1     0     0     1

if the probability is different for ones and zeros you might want to multiply the mean in the comparison to fit again. note that this is a very simplistic aproach, which can surly be improved to better fit your problem

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top