List of my modules...

Module: Threshold_Global

Description:

Converts image to "black and white" with a simple global thresholding. I used quotes because it depends on the greylevels you set in the Values port, and if you set a third greylevel for the outside is a mask or ROI (region of interest) is connected.

Illustration of the binarisation procedure. Original image is on the left, result on the right, in which the object is defined as black, and background as white.

Notes

Connections:

Image

[required]
The input image, of type HxUniformScalarField3.

ROI

[optional]
A Region Of Interest (ROI), defined in a HxSelectRoi. Will only count the pixels in the ROI if one is connected. A pixel is defined as in the ROI if the intersection between the ROI and the unit cube that defines the volume occupied by the pixel is non-empty.

Mask

[optional]
A mask image, defined in a class HxUniformScalarField3. Will only count the pixels if the corresponding pixel in the mask satisfies the threshold comparison defined in the appropriate ports.

Histogram

[optional]
A pre-computed histogram, defined in a class HxSpreadSheet. This can be useful if e.g. the histogram was generated on reference region or reference image, and the threshold needs to be computed from there for the connected image or the set region.
The histogram must have the same structure as that generated by the module Histogram_ (detailed here).

Ports:

Threshold


Value to compare with the pixel intensity.

Comparison


Defines how the threshold is used to define the pixels of the object.

Values


Values in the resulting image for the object and background.

Automatic choice of threshold

This part is for automatically choosing a threshold value. Hopefully I'll add more methods as I go along...

Auto


Sets the type of automatic threshold selection: none, histogram-based or iterative. Pressing the button only sets the threshold in the Threshold port (does not check the comparator in the Comparison port).

AutoHisto


Selects the type of histogram-based threshold value selection. If a histogram-based method is selected (and if no histogram is connected at the input), then additional ports will be displayed for defining the histogram. See here for details about these (Warning: port ordering is haphazard, so they can appear in the middle of the others).

Peaks

This is an implementation of the algorithm described by Sezan1, with a few customisations. The original core of the method is as follows: The paper goes on to describe a closeness criterion between two peaks so as to merge them when necessary (depends on the application). This criterion is equal to the difference between the greylevels of the end of one peak and the start of the next. The merged peak starts at the start of the first one, ends at the end of the second one, and its maximum is the biggest of the maximum of each. Finally, the threshold value selection presented is a weighted average between the end of one peak and the start of the next.
Implementation and customisations
Intermediate data are stored in the histogram HxSpreadsheet in an additional table named Peaks.

Notes

Otsu

This method is an discrete analog of Fisher's linear discriminant2, and was introduced by the namebearer Nobuyuki Otsu in a hugely cited paper3.

It finds the grey-level threshold θOtsu such that the variance between the two classes of pixels defined by that threshold is maximum. In maths it can be written as:

θOtsu = argmaxθ{∑k<θp(k)(μ0 - μ)2 + ∑k≥θp(k)(μ1 - μ)2}
Where: Contrary to the original definition, this implementation does not necessarily compute the threshold on integer grey-levels. It uses those defined by the histogram.

Bayesian

This method supposes that the image is made up of two classes of greylevels each having a Gaussian distribution. In other words, we suppose that the histogram is a union of two Gaussians. A (normalised) Gaussian can be defined by an expected value μ and variance σ2, and is written g(x) = (1/√(2π)σ)exp(-(x-μ)22). This can also translate as the probability of observing x in such a distribution.

The idea is that a threshold value defines two groups, one containing all pixels with a strictly smaller greylevel, and with greater or equal greylevel. From each, the mean and variance are computed (μ0, σ0, μ1, σ1) and define the Gaussian distribution for each group. In this framework, the optimal threshold θ would have an equal probability of belonging to either group, i.e. g0(θ) = g1(θ).

In practice, we test only the values defined in the histogram, and we won't find a threshold θ such that g0(θ) is perfectly equal to g1(θ). What is done instead is that for each threshold candidate x, the two Gaussians are determined and (i.e. the means and variances are computed), and g0(x) and g1(x) are calculated. We then compute the ratio of the largest by the smallest: max(g0(x), g1(x))/min(g0(x), g1(x)). From all the candidates defined by the histogram bins, we choose the one with the ratio closest to 1 as θ.

Notes

AutoIter


Selects the type of iterative threshold value selection, when the relevant option is chosen in the Auto port.

Isodata

Widely used in 2D medical image processing, this is a iterative clustering algorithm that sets the threshold as the average of the means of the grey-levels of the two clusters4: Note that sometimes the (light) pixels of the object have a higher variance than the (dark) background, and using this method on the logarithm of the image rather than the image itself gives better results.

Porosity

Finds the threshold such that the percentage of pixels with a greylevel stricly lower than the threshold best approaches the percentage given.

Note on the iterative methods

On very large images, it takes a long time to iterate over all the pixels, so these methods are first computed on 1 % of the pixels (random sampling), and when it converges it does the same on 2 % of the pixels, and so on (doubling every time) until 100 %. Quite often the threshold found with 1 % of the pixels will stay there until the end of the process.

Commands:

Additional options can be accessed when typing in the console Binarise COMMAND_NAME.

verbose

Displays timing information after the computation. Retype to hide info.

create

Runs the computation. Returns the name of the output, so it can be used in a script, such as set RESULT [Binarise create].

Scripting:

Typical use in a TCL script would look like so:
	set B [create Binarise]
	$B Image connect $INPUT_IMAGE; $B fire
#	$B Threshold setValue $THRESHOLD; $B Comparison setValue 3
	$B Auto setValue 2; $B fire
	$B Iter_Method setValue 3 1; $B fire
	set OUTPUT_IMAGE [$B create]

References:

1 Sezan, M. (1990). A peak detection algorithm and its application to histogram-based image data reduction, Computer Vision, Graphics, & Image Processing 49: 36-51.
2 Fisher, R. A. (1936). The Use of Multiple Measurements in Taxonomic Problems. Annals of Eugenics 7 (2): 179-188.
3 Otsu, N. (1979). A threshold selection method from gray-level histograms. IEEE transactions on systems, man, and cybernetics SMC-9 (1): 62-66.
4 Ridler, T. W.; Calvard, S. (1978). Picture Thresholding Using an Iterative Selection Method. IEEE transactions on systems, man, and cybernetics SMC-8 (8): 630-632.