Rank

ClearMap.ImageProcessing.Filter.Rank.Bilateral

Approximate bilateral rank filter for local (custom kernel) mean.

ClearMap.ImageProcessing.Filter.Rank.Parametric

Parameteric rank filters

ClearMap.ImageProcessing.Filter.Rank.Percentile

Inferior and superior ranks, provided by the user, are passed to the kernel function to provide a softer version of the rank filters.

ClearMap.ImageProcessing.Filter.Rank.Rank

Main 3d rank filter module

ClearMap.ImageProcessing.Filter.Rank.RankResample

Rank filter on resampled data.

Rank filter module.

This module provides 3d filters based on the local histogram / rank order of an image.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

mean_bilateral(source, selem=None, sink=None, mask=None, s0=10, s1=10, **kwargs)[source]

Apply a flat kernel bilateral filter.

This is an edge-preserving and noise reducing denoising filter. It averages pixels based on their spatial closeness and radiometric similarity.

Spatial closeness is measured by considering only the local pixel neighborhood given by a structuring element.

Radiometric similarity is defined by the greylevel interval [g-s0, g+s1] where g is the current pixel greylevel.

Only pixels belonging to the structuring element and having a graylevel inside this interval are averaged.

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.

s0,s1int

The lower and upper widths around the center value for the bilateral window.

Returns

sinkarray

The filtered array.

pop_bilateral(source, selem=None, sink=None, mask=None, s0=10, s1=10, **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. Additionally pixels must have a graylevel inside the interval [g-s0, g+s1] where g is the gray value of the center pixel.

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.

s0,s1int

The lower and upper widths around the center value for the bilateral window.

Returns

sinkarray

The filtered array.

sum_bilateral(source, selem=None, sink=None, mask=None, s0=10, s1=10, **kwargs)[source]

Apply a flat kernel bilateral filter.

This is an edge-preserving and noise reducing denoising filter. It sums pixels based on their spatial closeness and radiometric similarity.

Spatial closeness is measured by considering only the local pixel neighborhood given by a structuring element (selem).

Radiometric similarity is defined by the greylevel interval [g-s0, g+s1] where g is the current pixel greylevel.

Only pixels belonging to the structuring element AND having a greylevel inside this interval are summed.

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

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.

s0,s1int

The lower and upper widths around the center value for the bilateral window.

Returns

sinkarray

The filtered array.

sum_relative_bilateral(source, selem=None, sink=None, mask=None, s0=0.5, s1=2.0, **kwargs)[source]

Apply a flat kernel bilateral filter.

This is an edge-preserving and noise reducing denoising filter. It sums pixels based on their spatial closeness and radiometric similarity.

Spatial closeness is measured by considering only the local pixel neighborhood given by a structuring element (selem).

Radiometric similarity is defined by the greylevel interval [g-s0, g+s1] where g is the current pixel greylevel.

Only pixels belonging to the structuring element AND having a greylevel inside this interval are summed.

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

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.

s0,s1int

The lower and upper widths around the center value for the bilateral window.

Returns

sinkarray

The filtered array.

mean_scale_bilateral(source, selem=None, sink=None, mask=None, s0=10, s1=10, p0=0, p1=0, **kwargs)[source]

Mean pixel value using a bilateral window size that scales with local pixel intensity.

The filter linearly scales the biateral window size as [g-s0-p0*g, g+s1+p1*g].

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.

s0,s1int

The lower and upper widths around the center value for the bilateral window.

p0,p1float

The lower and upper scale values for the bilateral window.

Returns

sinkarray

The filtered array.

nilblack(source, selem=None, sink=None, mask=None, k=0.0, **kwargs)[source]

Local nilblack threshold of an image.

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.

max_binint or None

Maximal number of bins.

kfloat

The factor between mean and standard deviation: threshold = mu + k * std

Returns

sinkarray

The filtered array.

sauvola(source, selem=None, sink=None, mask=None, k=0.0, R=1.0)[source]

Local Sauvola threshold of an image.

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.

max_binint or None

Maximal number of bins.

k, Rfloat

The factors in the formula: threshold = mu + k * (std/R - 1) * (mu - max_bin)

Returns

sinkarray

The filtered array.

contrast_limited_percentile(source, selem=None, sink=None, mask=None, percentile=0.0, limit=None, contrast_limit=0.1, **kwargs)[source]

Local Sauvola threshold of an image.

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.

max_binint or None

Maximal number of bins.

k, Rfloat

The factors in the formula: threshold = mu + k * (std/R - 1) * (mu - max_bin)

Returns

sinkarray

The filtered array.

light_sheet_artifact_correction(source, selem=None, sink=None, mask=None, percentiles=(0.0, 1.0), limit=None, contrast_limit=0.5, **kwargs)[source]

Local Sauvola threshold of an image.

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.

max_binint or None

Maximal number of bins.

k, Rfloat

The factors in the formula: threshold = mu + k * (std/R - 1) * (mu - max_bin)

Returns

sinkarray

The filtered array.