Percentile#

Inferior and superior ranks, provided by the user, are passed to the kernel function to provide a softer version of the rank filters. E.g. autolevel_percentile will stretch image levels between percentile [p0, p1] instead of using [min, max]. It means that isolated bright or dark pixels will not produce halos.

The local histogram is computed using a sliding window.

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.

autolevel_percentile(source, selem=None, sink=None, mask=None, percentiles=(0, 1), **kwargs)[source]#

Return greyscale local autolevel of an 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.

max_binint or None

Maximal number of bins.

percentilestuple of floats

The lower and upper percentiles in [0,1] to use for calculating the histogram.

Returns

sinkarray

The filtered array.

enhance_contrast_percentile(source, selem=None, sink=None, mask=None, percentiles=(0, 1), **kwargs)[source]#

Enhance contrast of an image.

This replaces each pixel by the local maximum if the pixel greyvalue is closer to the local maximum than the local minimum. Otherwise it is replaced by the local minimum.

Only greyvalues between percentiles [p0, p1] are considered in the filter.

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.

percentilestuple of floats

The lower and upper percentiles in [0,1] to use for calculating the histogram.

Returns

sinkarray

The filtered array.

gradient_percentile(source, selem=None, sink=None, mask=None, percentiles=(0, 1), **kwargs)[source]#

Return local gradient of an image (i.e. local maximum - local minimum).

Only greyvalues between percentiles [p0, p1] are considered in the filter.

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.

percentilestuple of floats

The lower and upper percentiles in [0,1] to use for calculating the histogram.

Returns

sinkarray

The filtered array.

mean_percentile(source, selem=None, sink=None, mask=None, percentiles=(0, 1), **kwargs)[source]#

Return local mean of an image.

Only greyvalues between percentiles [p0, p1] are considered in the filter.

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.

percentilestuple of floats

The lower and upper percentiles in [0,1] to use for calculating the histogram.

Returns

sinkarray

The filtered array.

percentile(source, selem=None, sink=None, mask=None, percentile=0, **kwargs)[source]#

Return local percentile of an image.

Returns the value of the p0 lower percentile of the local greyvalue distribution.

Only greyvalues between percentiles [p0, p1] are considered in the filter.

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.

percentilefloat

The percentile in [0,1] to use for calculating the histogram.

Returns

sinkarray

The filtered array.

pop_percentile(source, selem=None, sink=None, mask=None, percentiles=(0, 1), **kwargs)[source]#

Return the local number (population) of pixels.

The number of pixels is defined as the number of pixels which are included in the structuring element and the mask.

Only greyvalues between percentiles [p0, p1] are considered in the filter.

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.

percentilestuple of floats

The lower and upper percentiles in [0,1] to use for calculating the histogram.

Returns

sinkarray

The filtered array.

subtract_mean_percentile(source, selem=None, sink=None, mask=None, percentiles=(0, 1), **kwargs)[source]#

Return image subtracted from its local mean.

Only greyvalues between percentiles [p0, p1] are considered in the filter.

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.

percentilesfloat

The lower and upper percentiles in [0,1] to use for calculating the histogram.

Returns

sinkarray

The filtered array.

sum_above_percentile(source, selem=None, sink=None, mask=None, percentile=0.5, **kwargs)[source]#

Return the local sum of pixels.

Only greyvalues between percentiles [p0, p1] are considered in the filter.

Note that the sum may overflow depending on the data type of the input array.

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.

percentilefloat

The percentiles in [0,1] to use for calculating the histogram.

Returns

sinkarray

The filtered array.

sum_percentile(source, selem=None, sink=None, mask=None, percentiles=(0, 1), **kwargs)[source]#

Return the local sum of pixels.

Only greyvalues between percentiles [p0, p1] are considered in the filter.

Note that the sum may overflow depending on the data type of the input array.

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.

percentilestuple of floats

The lower and upper percentiles in [0,1] to use for calculating the histogram.

Returns

sinkarray

The filtered array.

threshold_percentile(source, selem=None, sink=None, mask=None, percentile=0, **kwargs)[source]#

Local threshold of an image.

The resulting binary mask is True if the greyvalue of the center pixel is greater than the local mean.

Only greyvalues between percentiles [p0, p1] are considered in the filter.

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.

percentilefloat

The percentile in [0,1] to use for calculating the histogram.

Returns

sinkarray

The filtered array.