Histogram matcher
Histogram matcher in a nutshell.
Plugin for match the brightness of one slice of a Stack with the next one;
Do not use this plugin if meaningful global brightness variations along the Z-axis of a stack are expected;
This plugin is multichannel;
Python API reference:
bmiptools.transformation.dynamics.histogram_matcher.HistogramMatcher
.
This plugin can be used to match the histograms among the various slices of a stack. This makes the brightness level of the slice more uniform, reducing or eliminating the sudden brightness/contrast variation among one slices an the next one.
The Python API reference of the plugin is
bmiptools.transformation.dynamics.histogram_matcher.HistogramMatcher
.
Transformation dictionary
The transformation dictionary for this plugin look like this.
{'reference_slice': 0
}
The plugin-specific parameters contained in this dictionary are:
reference_slice
: position of the slice used as reference during the matching of the histograms.
Further details useful the the usage of this plugin with the Python API can be found in the __init__
method of the
class HistogramMatcher
Use case
The typical uses of this plugin are:
Remove the sudden brightness variation along the Z-axis in a stack.
Homogenize the slices in a stack to easier the optimization of the other plugins in a pipeline.
Tip
Do not use this plugin on a stack where meaningful brightness variations slice after slice are expected. These variations
A good idea is to use this plugin in the beginning of a pipeline (first or second plugin), in order to have an homogenized stack as input of the core plugins of a pipeline. In this way, it is more likely that the application of the core plugins (initialized with parameters both set by the user or found by some optimization procedure) produces similar effects for each slice of the stack.
Application example
As example consider the portion of a FIB-SEM stack of a biological sample, visualized as animated gif (saving mode
available in the python API, see bmiptools.stack.Stack.save_as_gif()
), in order to see how the overall
brightness level suddenly change from one slice to the next.
Note the strong reduction of the overall brightness happening at approximately the half of the clip. After histogram matching, the sudden changes in brightness disappear.
.
Note
The script used to produce the images displayed can be found here. To reproduce the images showed above one may consult the examples/documentation_scritps folder, where is explained how to run the example scripts and where one can find all the necessary input data.
Implementation details
The core operation of this plugin is the matching of the histogram among two images. This is done by using the skimage
function skimage.exposure.match_histogram
(see here for
further details). Given two slices of a stack \(a\) and \(b\), let \(HM(a,b)\) be the function matching the
histogram of the image \(b\) with the histogram of the image \(a\) (used as reference). Then, given the input
\(K \times J \times I\) stack \(S(k,j,i)\) and a reference slice in position \(k_0\), consider \(k\)-th
slice \(S[k](x,y)\). The HistogramMatcher
plugin perform the following operations:
Starting from \(k=k_0+1\), then
\[S[k](j,i) \rightarrow S_{output}[k](i,j) = HM(S[k-1](j,i),S[k](j,i)).\]This operation is repeated increasing \(k\) by 1 till \(k=K-1\) is reached.
Going back to \(k=k_0-1\)
\[S[k](j,i) \rightarrow S_{output}[k](i,j) = HM(S[k+1](j,i),S[k](j,i)).\]This operation is repeated decreasing \(k\) by 1 till \(k=0\) is reached.
For multichannel stack, the transformations above are applied for each channel independently.
Further details
Websites: