Rank#
Main 3d rank filter module#
The package is based on the 2d skimage.filters.rank filter module.
These filters compute the local histogram at each pixel, using a sliding window similar to the method described in [1]. A histogram is built using a moving window in order to limit redundant computation. The moving window follows a snake-like path:
…————————/————————–/ -————————-…
The local histogram is updated at each pixel as the structuring element window moves by, i.e. only those pixels entering and leaving the structuring element update the local histogram. The histogram size is 8-bit (256 bins) for 8-bit images and 2- to 16-bit for 16-bit images depending on the maximum value of the image.
The filter is applied up to the image border, the neighborhood used is adjusted accordingly. The user may provide a mask image (same size as input image) where non zero values are the part of the image participating in the histogram computation. By default the entire image is filtered.
This implementation outperforms grey.dilation for large structuring elements.
Input image can be 8-bit or 16-bit, for 16-bit input images, the number of histogram bins is determined from the maximum value present in the image.
Result image is 8-/16-bit or double with respect to the input image and the rank filter operation.
References
- autolevel(source, selem=None, sink=None, mask=None, **kwargs)[source]#
Auto-level image using local histogram.
This filter locally stretches the histogram of greyvalues to cover the entire range of values from “white” to “black”.
Arguments
- sourcearray
Input array.
- selemarray
Structuring element, if None use a cube of size 3.
- sinkarray
Output array, if None, a new array is allocated.
- maskarray
Optional mask, if None, the complete source is used. Pixels in the mask are zero in the output.
Returns
- sinkarray
The filtered array.
- bottomhat(source, selem=None, sink=None, mask=None, **kwargs)[source]#
Local bottom-hat.
This filter computes the morphological closing of the image and then subtracts the result from the original image.
Arguments
- sourcearray
Input array.
- selemarray
Structure element. If None, use a cube of size 3.
- sinkarray
Output array. If None, a new array is allocated.
- maskarray
Optional mask, if None, the complete source is used. Pixels on the mask are zero in the output.
Returns
- sinkarray
The filtered array.
- enhance_contrast(source, selem=None, sink=None, mask=None, **kwargs)[source]#
Enhance contrast.
This replaces each pixel by the local maximum if the pixel gray value is closer to the local maximum than the local minimum. Otherwise it is replaced by the local minimum.
Arguments
- sourcearray
Input array.
- selemarray
Structure element. If None, use a cube of size 3.
- sinkarray
Output array. If None, a new array is allocated.
- maskarray
Optional mask, if None, the complete source is used. Pixels on the mask are zero in the output.
Returns
- sinkarray
The filtered array.
- entropy(source, selem=None, sink=None, mask=None, **kwargs)[source]#
Local entropy.
The entropy is computed using base 2 logarithm i.e. the filter returns the minimum number of bits needed to encode the local greylevel distribution.
Arguments
- sourcearray
Input array.
- selemarray
Structure element. If None, use a cube of size 3.
- sinkarray
Output array. If None, a new array is allocated.
- maskarray
Optional mask, if None, the complete source is used. Pixels on the mask are zero in the output.
Returns
- sinkarray
The filtered array.
- equalize(source, selem=None, sink=None, mask=None, **kwargs)[source]#
Equalize image using local histogram.
Arguments
- sourcearray
Input array.
- selemarray
Structure element. If None, use a cube of size 3.
- sinkarray
Output array. If None, a new array is allocated.
- maskarray
Optional mask, if None, the complete source is used. Pixels on the mask are zero in the output.
Returns
- sinkarray
The filtered array.
- geometric_mean(source, selem=None, sink=None, mask=None, **kwargs)[source]#
Return local geometric mean.
Arguments
- sourcearray
Input array.
- selemarray
Structure element. If None, use a cube of size 3.
- sinkarray
Output array. If None, a new array is allocated.
- maskarray
Optional mask, if None, the complete source is used. Pixels on the mask are zero in the output.
Returns
- sinkarray
The filtered array.
- gradient(source, selem=None, sink=None, mask=None, **kwargs)[source]#
Return local gradient of an image (i.e. local maximum - local minimum).
Arguments
- sourcearray
Input array.
- selemarray
Structure element. If None, use a cube of size 3.
- sinkarray
Output array. If None, a new array is allocated.
- maskarray
Optional mask, if None, the complete source is used. Pixels on the mask are zero in the output.
Returns
- sinkarray
The filtered array.
- histogram(source, selem=None, sink=None, mask=None, max_bin=None)[source]#
Normalized sliding window histogram
Arguments
- sourcearray
Input array.
- selemarray
Structure element. If None, use a cube of size 3.
- sinkarray
Output array. If None, a new array is allocated.
- maskarray
Optional mask, if None, the complete source is used. Pixels on the mask are zero in the output.
- max_binint or None
Maximal number of bins.
Returns
- sinkarray
Array of the source shape pluse on extra dimension for the histogram at each pixel.
- maximum(source, selem=None, sink=None, mask=None, **kwargs)[source]#
Return local maximum.
Arguments
- sourcearray
Input array.
- selemarray
Structure element. If None, use a cube of size 3.
- sinkarray
Output array. If None, a new array is allocated.
- maskarray
Optional mask, if None, the complete source is used. Pixels on the mask are zero in the output.
Returns
- sinkarray
The filtered array.
- mean(source, selem=None, sink=None, mask=None, **kwargs)[source]#
Return local mean.
Arguments
- sourcearray
Input array.
- selemarray
Structure element. If None, use a cube of size 3.
- sinkarray
Output array. If None, a new array is allocated.
- maskarray
Optional mask, if None, the complete source is used. Pixels on the mask are zero in the output.
Returns
- sinkarray
The filtered array.
- median(source, selem=None, sink=None, mask=None, **kwargs)[source]#
Return local median.
Arguments
- sourcearray
Input array.
- selemarray
Structure element. If None, use a cube of size 3.
- sinkarray
Output array. If None, a new array is allocated.
- maskarray
Optional mask, if None, the complete source is used. Pixels on the mask are zero in the output.
Returns
- sinkarray
The filtered array.
- minimum(source, selem=None, sink=None, mask=None, **kwargs)[source]#
Return local minimum.
Arguments
- sourcearray
Input array.
- selemarray
Structure element. If None, use a cube of size 3.
- sinkarray
Output array. If None, a new array is allocated.
- maskarray
Optional mask, if None, the complete source is used. Pixels on the mask are zero in the output.
Returns
- sinkarray
The filtered array.
- minmax(source, selem=None, sink=None, mask=None, **kwargs)[source]#
Return local maximum and minimum.
Arguments
- sourcearray
Input array.
- selemarray
Structure element. If None, use a cube of size 3.
- sinkarray
Output array. If None, a new array is allocated.
- maskarray
Optional mask, if None, the complete source is used. Pixels on the mask are zero in the output.
Returns
- sinkarray
The filtered array.
- modal(source, selem=None, sink=None, mask=None, **kwargs)[source]#
Return local mode.
The mode is the value that appears most often in the local histogram.
Arguments
- sourcearray
Input array.
- selemarray
Structure element. If None, use a cube of size 3.
- sinkarray
Output array. If None, a new array is allocated.
- maskarray
Optional mask, if None, the complete source is used. Pixels on the mask are zero in the output.
Returns
- sinkarray
The filtered array.
- noise_filter(source, selem=None, sink=None, mask=None, **kwargs)[source]#
Noise feature.
Arguments
- sourcearray
Input array.
- selemarray
Structure element. If None, use a cube of size 3.
- sinkarray
Output array. If None, a new array is allocated.
- maskarray
Optional mask, if None, the complete source is used. Pixels on the mask are zero in the output.
Returns
- sinkarray
The filtered array.
- otsu(source, selem=None, sink=None, mask=None, **kwargs)[source]#
Local Otsu’s threshold value for each pixel.
Arguments
- sourcearray
Input array.
- selemarray
Structure element. If None, use a cube of size 3.
- sinkarray
Output array. If None, a new array is allocated.
- maskarray
Optional mask, if None, the complete source is used. Pixels on the mask are zero in the output.
Returns
- sinkarray
The filtered array.
- pop(source, selem=None, sink=None, mask=None, **kwargs)[source]#
Return the local number (population) of pixels.
Arguments
- sourcearray
Input array.
- selemarray
Structure element. If None, use a cube of size 3.
- sinkarray
Output array. If None, a new array is allocated.
- maskarray
Optional mask, if None, the complete source is used. Pixels on the mask are zero in the output.
Returns
- sinkarray
The filtered array.
- std(source, selem=None, sink=None, mask=None, **kwargs)[source]#
Local standard deviation.
Arguments
- sourcearray
Input array.
- selemarray
Structure element. If None, use a cube of size 3.
- sinkarray
Output array. If None, a new array is allocated.
- maskarray
Optional mask, if None, the complete source is used. Pixels on the mask are zero in the output.
Returns
- sinkarray
The filtered array.
- subtract_mean(source, selem=None, sink=None, mask=None, **kwargs)[source]#
Return image subtracted from its local mean.
Arguments
- sourcearray
Input array.
- selemarray
Structure element. If None, use a cube of size 3.
- sinkarray
Output array. If None, a new array is allocated.
- maskarray
Optional mask, if None, the complete source is used. Pixels on the mask are zero in the output.
Returns
- sinkarray
The filtered array.
- threshold(source, selem=None, sink=None, mask=None, **kwargs)[source]#
Local threshold.
The resulting binary mask is True if the greyvalue of the center pixel is greater than the local mean.
Arguments
- sourcearray
Input array.
- selemarray
Structure element. If None, use a cube of size 3.
- sinkarray
Output array. If None, a new array is allocated.
- maskarray
Optional mask, if None, the complete source is used. Pixels on the mask are zero in the output.
Returns
- sinkarray
The filtered array.
- tophat(source, selem=None, sink=None, mask=None, **kwargs)[source]#
Local top-hat.
This filter computes the morphological opening of the image and then subtracts the result from the original image.
Arguments
- sourcearray
Input array.
- selemarray
Structure element. If None, use a cube of size 3.
- sinkarray
Output array. If None, a new array is allocated.
- maskarray
Optional mask, if None, the complete source is used. Pixels on the mask are zero in the output.
Returns
- sinkarray
The filtered array.