Threshold

Threshold[data]

thresholds data by replacing values close to zero by zero.

Threshold[data,tspec]

thresholds data using threshold specification tspec.

Threshold[image,]

replaces small values of image by zero.

Threshold[sound,]

replaces small values of sound by zero.

Details

  • Thresholding is a mathematical segmentation operation to set values in a specific region to zero and occasionally diminish values outside the region.
  • Threshold works with data arrays of any rank, as well as 2D and 3D images.
  • Threshold[data] is equivalent to Threshold[data,{"Hard",10-10}].
  • The threshold specification tspec can be of the form {tfun,pars}.
  • Possible tfun names and options include:
  • Available thresholding functions tfun and their parameters are (using input data ):
  • {"Hard",δ} 0 TemplateBox[{x}, Abs]<=delta; x TemplateBox[{x}, Abs]>delta;
    {"Soft",δ} 0 TemplateBox[{x}, Abs]<=delta; sgn(x) (TemplateBox[{x}, Abs]-delta) TemplateBox[{x}, Abs]>delta;
    {"Firm",δ,r,p} 0 TemplateBox[{x}, Abs]<=delta-delta p r; 1/(delta r)sgn(x) (delta+delta r-delta p  r) (TemplateBox[{x}, Abs]-delta+delta p r) delta-delta p r<TemplateBox[{x}, Abs]<=delta+delta (-p) r+delta r; x TemplateBox[{x}, Abs]>delta+delta (-p) r+delta r;
    {"PiecewiseGarrote",δ}0 TemplateBox[{x}, Abs]<=delta; x-(delta^2)/x TemplateBox[{x}, Abs]>delta
    {"SmoothGarrote",δ,n}
    {"Hyperbola",delta} 0 TemplateBox[{x}, Abs]<=delta; sgn(x) sqrt(x^2-delta^2) TemplateBox[{x}, Abs]>delta;
    {"LargestValues",k}keep the largest k data points
  • In all cases delta is assumed to be a positive number or a thresholding function tfunc to compute delta. Each tfunc[data] should return a positive number.
  • The parameter conditions for "Firm" are that r is a positive real and p a real number between 0 and 1.
  • The parameter conditions for "SmoothGarrote" is to have n be a positive machine integer.
  • The threshold delta can be automatically computed using the following methods:
  • {"BlackFraction",b}make a fraction b of all pixels be black
    "Cluster"cluster variance maximization (Otsu's algorithm)
    "Entropy"histogram entropy minimization (Kapur's method)
    "Mean"use the mean level as the threshold
    "Median"use the median pixel level as the threshold
    "MinimumError"KittlerIllingworth minimum error thresholding method

Examples

open allclose all

Basic Examples  (3)

Zero out elements that are very close to 0:

Zero out elements with absolute value smaller than 3/2:

Keep the 3 largest absolute values:

Threshold an image:

Scope  (14)

Data  (7)

Threshold data by replacing values close to zero by zero:

Zero out elements with absolute value smaller than 3/2:

Threshold a list of complex values:

Threshold a 2D array:

Threshold a grayscale image:

This shows the resulting histogram:

Threshold a color image:

Notice that thresholding happens on each channel separately:

Perform a clustering threshold on a 3D image:

Threshold Specification  (7)

"Hard" thresholding replaces data values with absolute value below with 0:

With "Soft" thresholding, data values below threshold are set to 0; others are diminished by :

"Firm" thresholding is a compromise between "Hard" and "Soft" thresholding:

"PiecewiseGarrote" thresholding is similar to "Firm", but uses a single parameter:

"SmoothGarrote" thresholding:

"Hyperbola" thresholding:

"LargestValues" thresholding preserves samples with largest absolute values:

Properties & Relations  (7)

"Hard" thresholding sets to 0 all data values with absolute value below a certain threshold :

Vary the value of the threshold :

"Hard" thresholding is similar to Chop:

"Soft" thresholding performs a shrinking operation:

Vary the value of the threshold :

"Firm" thresholding is a compromise between "Hard" and "Soft" thresholding:

"Firm" thresholding has uniformly smaller variance than "Hard" thresholding:

In the limit β->, "Firm" threshold performs "Soft" thresholding:

In the limit β->η, "Firm" threshold performs "Hard" thresholding:

"PiecewiseGarrote" thresholding:

This is similar to "Firm" thresholding with the advantage of having a single parameter delta:

Vary the value of the threshold :

"SmoothGarrote" thresholding:

In the limit n, "SmoothGarrote" goes to "Hard" thresholding:

Vary the values of the threshold and the exponent value :

"Hyperbola" thresholding:

"LargestValues" thresholding:

Possible Issues  (1)

When using {"LargestValues",k} and if data elements repeat, more than nonzero elements may be returned:

Enumerate all possible outcomes:

Wolfram Research (2010), Threshold, Wolfram Language function, https://reference.wolfram.com/language/ref/Threshold.html (updated 2012).

Text

Wolfram Research (2010), Threshold, Wolfram Language function, https://reference.wolfram.com/language/ref/Threshold.html (updated 2012).

CMS

Wolfram Language. 2010. "Threshold." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2012. https://reference.wolfram.com/language/ref/Threshold.html.

APA

Wolfram Language. (2010). Threshold. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Threshold.html

BibTeX

@misc{reference.wolfram_2023_threshold, author="Wolfram Research", title="{Threshold}", year="2012", howpublished="\url{https://reference.wolfram.com/language/ref/Threshold.html}", note=[Accessed: 18-March-2024 ]}

BibLaTeX

@online{reference.wolfram_2023_threshold, organization={Wolfram Research}, title={Threshold}, year={2012}, url={https://reference.wolfram.com/language/ref/Threshold.html}, note=[Accessed: 18-March-2024 ]}