Module: filters.rank
¶

Autolevel image using local histogram. 
Return greyscale local autolevel of an image. 


Local bottomhat of an image. 

Equalize image using local histogram. 

Return local gradient of an image (i.e. 
Return local gradient of an image (i.e. 


Return local maximum of an image. 

Return local mean of an image. 

Return local geometric mean of an image. 

Return local mean of an image. 

Apply a flat kernel bilateral filter. 

Return image subtracted from its local mean. 
Return image subtracted from its local mean. 


Return local median of an image. 

Return local minimum of an image. 

Return local mode of an image. 

Enhance contrast of an image. 
Enhance contrast of an image. 


Return the local number (population) of pixels. 

Return the local number (population) of pixels. 

Return the local number (population) of pixels. 

Return the local sum of pixels. 

Apply a flat kernel bilateral filter. 

Return the local sum of pixels. 

Local threshold of an image. 
Local threshold of an image. 


Local tophat of an image. 

Noise feature. 

Local entropy. 

Local Otsu’s threshold value for each pixel. 

Return local percentile of an image. 
Normalized sliding window histogram 


Majority filter assign to each pixel the most occuring value within its neighborhood. 
autolevel¶

skimage.filters.rank.
autolevel
(image, selem, out=None, mask=None, shift_x=False, shift_y=False)[source]¶ Autolevel image using local histogram.
This filter locally stretches the histogram of greyvalues to cover the entire range of values from “white” to “black”.
 Parameters
image : 2D array (uint8, uint16)
Input image.
selem : 2D array
The neighborhood expressed as a 2D array of 1’s and 0’s.
out : 2D array (same dtype as input)
If None, a new array is allocated.
mask : ndarray
Mask array that defines (>0) area of the image included in the local neighborhood. If None, the complete image is used (default).
shift_x, shift_y : int
Offset added to the structuring element center point. Shift is bounded to the structuring element sizes (center must be inside the given structuring element).
 Returns
out : 2D array (same dtype as input image)
Output image.
Examples
>>> from skimage import data >>> from skimage.morphology import disk >>> from skimage.filters.rank import autolevel >>> img = data.camera() >>> auto = autolevel(img, disk(5))
Examples using skimage.filters.rank.autolevel
¶
autolevel_percentile¶

skimage.filters.rank.
autolevel_percentile
(image, selem, out=None, mask=None, shift_x=False, shift_y=False, p0=0, p1=1)[source]¶ Return greyscale local autolevel of an image.
This filter locally stretches the histogram of greyvalues to cover the entire range of values from “white” to “black”.
Only greyvalues between percentiles [p0, p1] are considered in the filter.
 Parameters
image : 2D array (uint8, uint16)
Input image.
selem : 2D array
The neighborhood expressed as a 2D array of 1’s and 0’s.
out : 2D array (same dtype as input)
If None, a new array is allocated.
mask : ndarray
Mask array that defines (>0) area of the image included in the local neighborhood. If None, the complete image is used (default).
shift_x, shift_y : int
Offset added to the structuring element center point. Shift is bounded to the structuring element sizes (center must be inside the given structuring element).
p0, p1 : float in [0, …, 1]
Define the [p0, p1] percentile interval to be considered for computing the value.
 Returns
out : 2D array (same dtype as input image)
Output image.
Examples using skimage.filters.rank.autolevel_percentile
¶
bottomhat¶

skimage.filters.rank.
bottomhat
(image, selem, out=None, mask=None, shift_x=False, shift_y=False)[source]¶ Local bottomhat of an image.
This filter computes the morphological closing of the image and then subtracts the result from the original image.
 Parameters
image : 2D array (uint8, uint16)
Input image.
selem : 2D array
The neighborhood expressed as a 2D array of 1’s and 0’s.
out : 2D array (same dtype as input)
If None, a new array is allocated.
mask : 2D array
Mask array that defines (>0) area of the image included in the local neighborhood. If None, the complete image is used (default).
shift_x, shift_y : int
Offset added to the structuring element center point. Shift is bounded to the structuring element sizes (center must be inside the given structuring element).
 Returns
out : 2D array (same dtype as input image)
Output image.
Examples
>>> from skimage import data >>> from skimage.morphology import disk >>> from skimage.filters.rank import bottomhat >>> img = data.camera() >>> out = bottomhat(img, disk(5))
equalize¶

skimage.filters.rank.
equalize
(image, selem, out=None, mask=None, shift_x=False, shift_y=False)[source]¶ Equalize image using local histogram.
 Parameters
image : 2D array (uint8, uint16)
Input image.
selem : 2D array
The neighborhood expressed as a 2D array of 1’s and 0’s.
out : 2D array (same dtype as input)
If None, a new array is allocated.
mask : ndarray
Mask array that defines (>0) area of the image included in the local neighborhood. If None, the complete image is used (default).
shift_x, shift_y : int
Offset added to the structuring element center point. Shift is bounded to the structuring element sizes (center must be inside the given structuring element).
 Returns
out : 2D array (same dtype as input image)
Output image.
Examples
>>> from skimage import data >>> from skimage.morphology import disk >>> from skimage.filters.rank import equalize >>> img = data.camera() >>> equ = equalize(img, disk(5))
gradient¶

skimage.filters.rank.
gradient
(image, selem, out=None, mask=None, shift_x=False, shift_y=False)[source]¶ Return local gradient of an image (i.e. local maximum  local minimum).
 Parameters
image : 2D array (uint8, uint16)
Input image.
selem : 2D array
The neighborhood expressed as a 2D array of 1’s and 0’s.
out : 2D array (same dtype as input)
If None, a new array is allocated.
mask : ndarray
Mask array that defines (>0) area of the image included in the local neighborhood. If None, the complete image is used (default).
shift_x, shift_y : int
Offset added to the structuring element center point. Shift is bounded to the structuring element sizes (center must be inside the given structuring element).
 Returns
out : 2D array (same dtype as input image)
Output image.
Examples
>>> from skimage import data >>> from skimage.morphology import disk >>> from skimage.filters.rank import gradient >>> img = data.camera() >>> out = gradient(img, disk(5))
gradient_percentile¶

skimage.filters.rank.
gradient_percentile
(image, selem, out=None, mask=None, shift_x=False, shift_y=False, p0=0, p1=1)[source]¶ Return local gradient of an image (i.e. local maximum  local minimum).
Only greyvalues between percentiles [p0, p1] are considered in the filter.
 Parameters
image : 2D array (uint8, uint16)
Input image.
selem : 2D array
The neighborhood expressed as a 2D array of 1’s and 0’s.
out : 2D array (same dtype as input)
If None, a new array is allocated.
mask : ndarray
Mask array that defines (>0) area of the image included in the local neighborhood. If None, the complete image is used (default).
shift_x, shift_y : int
Offset added to the structuring element center point. Shift is bounded to the structuring element sizes (center must be inside the given structuring element).
p0, p1 : float in [0, …, 1]
Define the [p0, p1] percentile interval to be considered for computing the value.
 Returns
out : 2D array (same dtype as input image)
Output image.
maximum¶

skimage.filters.rank.
maximum
(image, selem, out=None, mask=None, shift_x=False, shift_y=False)[source]¶ Return local maximum of an image.
 Parameters
image : 2D array (uint8, uint16)
Input image.
selem : 2D array
The neighborhood expressed as a 2D array of 1’s and 0’s.
out : 2D array (same dtype as input)
If None, a new array is allocated.
mask : ndarray
Mask array that defines (>0) area of the image included in the local neighborhood. If None, the complete image is used (default).
shift_x, shift_y : int
Offset added to the structuring element center point. Shift is bounded to the structuring element sizes (center must be inside the given structuring element).
 Returns
out : 2D array (same dtype as input image)
Output image.
See also
Notes
The lower algorithm complexity makes skimage.filters.rank.maximum more efficient for larger images and structuring elements.
Examples
>>> from skimage import data >>> from skimage.morphology import disk >>> from skimage.filters.rank import maximum >>> img = data.camera() >>> out = maximum(img, disk(5))
Examples using skimage.filters.rank.maximum
¶
mean¶

skimage.filters.rank.
mean
(image, selem, out=None, mask=None, shift_x=False, shift_y=False)[source]¶ Return local mean of an image.
 Parameters
image : 2D array (uint8, uint16)
Input image.
selem : 2D array
The neighborhood expressed as a 2D array of 1’s and 0’s.
out : 2D array (same dtype as input)
If None, a new array is allocated.
mask : ndarray
Mask array that defines (>0) area of the image included in the local neighborhood. If None, the complete image is used (default).
shift_x, shift_y : int
Offset added to the structuring element center point. Shift is bounded to the structuring element sizes (center must be inside the given structuring element).
 Returns
out : 2D array (same dtype as input image)
Output image.
Examples
>>> from skimage import data >>> from skimage.morphology import disk >>> from skimage.filters.rank import mean >>> img = data.camera() >>> avg = mean(img, disk(5))
geometric_mean¶

skimage.filters.rank.
geometric_mean
(image, selem, out=None, mask=None, shift_x=False, shift_y=False)[source]¶ Return local geometric mean of an image.
 Parameters
image : 2D array (uint8, uint16)
Input image.
selem : 2D array
The neighborhood expressed as a 2D array of 1’s and 0’s.
out : 2D array (same dtype as input)
If None, a new array is allocated.
mask : ndarray
Mask array that defines (>0) area of the image included in the local neighborhood. If None, the complete image is used (default).
shift_x, shift_y : int
Offset added to the structuring element center point. Shift is bounded to the structuring element sizes (center must be inside the given structuring element).
 Returns
out : 2D array (same dtype as input image)
Output image.
References
 R289
Gonzalez, R. C. and Wood, R. E. “Digital Image Processing (3rd Edition).” PrenticeHall Inc, 2006.
Examples
>>> from skimage import data >>> from skimage.morphology import disk >>> from skimage.filters.rank import mean >>> img = data.camera() >>> avg = geometric_mean(img, disk(5))
mean_percentile¶

skimage.filters.rank.
mean_percentile
(image, selem, out=None, mask=None, shift_x=False, shift_y=False, p0=0, p1=1)[source]¶ Return local mean of an image.
Only greyvalues between percentiles [p0, p1] are considered in the filter.
 Parameters
image : 2D array (uint8, uint16)
Input image.
selem : 2D array
The neighborhood expressed as a 2D array of 1’s and 0’s.
out : 2D array (same dtype as input)
If None, a new array is allocated.
mask : ndarray
Mask array that defines (>0) area of the image included in the local neighborhood. If None, the complete image is used (default).
shift_x, shift_y : int
Offset added to the structuring element center point. Shift is bounded to the structuring element sizes (center must be inside the given structuring element).
p0, p1 : float in [0, …, 1]
Define the [p0, p1] percentile interval to be considered for computing the value.
 Returns
out : 2D array (same dtype as input image)
Output image.
Examples using skimage.filters.rank.mean_percentile
¶
mean_bilateral¶

skimage.filters.rank.
mean_bilateral
(image, selem, out=None, mask=None, shift_x=False, shift_y=False, s0=10, s1=10)[source]¶ Apply a flat kernel bilateral filter.
This is an edgepreserving 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 [gs0, g+s1] where g is the current pixel greylevel.
Only pixels belonging to the structuring element and having a greylevel inside this interval are averaged.
 Parameters
image : 2D array (uint8, uint16)
Input image.
selem : 2D array
The neighborhood expressed as a 2D array of 1’s and 0’s.
out : 2D array (same dtype as input)
If None, a new array is allocated.
mask : ndarray
Mask array that defines (>0) area of the image included in the local neighborhood. If None, the complete image is used (default).
shift_x, shift_y : int
Offset added to the structuring element center point. Shift is bounded to the structuring element sizes (center must be inside the given structuring element).
s0, s1 : int
Define the [s0, s1] interval around the greyvalue of the center pixel to be considered for computing the value.
 Returns
out : 2D array (same dtype as input image)
Output image.
See also
denoise_bilateral
Examples
>>> from skimage import data >>> from skimage.morphology import disk >>> from skimage.filters.rank import mean_bilateral >>> img = data.camera().astype(np.uint16) >>> bilat_img = mean_bilateral(img, disk(20), s0=10,s1=10)
subtract_mean¶

skimage.filters.rank.
subtract_mean
(image, selem, out=None, mask=None, shift_x=False, shift_y=False)[source]¶ Return image subtracted from its local mean.
 Parameters
image : 2D array (uint8, uint16)
Input image.
selem : 2D array
The neighborhood expressed as a 2D array of 1’s and 0’s.
out : 2D array (same dtype as input)
If None, a new array is allocated.
mask : ndarray
Mask array that defines (>0) area of the image included in the local neighborhood. If None, the complete image is used (default).
shift_x, shift_y : int
Offset added to the structuring element center point. Shift is bounded to the structuring element sizes (center must be inside the given structuring element).
 Returns
out : 2D array (same dtype as input image)
Output image.
Examples
>>> from skimage import data >>> from skimage.morphology import disk >>> from skimage.filters.rank import subtract_mean >>> img = data.camera() >>> out = subtract_mean(img, disk(5))
subtract_mean_percentile¶

skimage.filters.rank.
subtract_mean_percentile
(image, selem, out=None, mask=None, shift_x=False, shift_y=False, p0=0, p1=1)[source]¶ Return image subtracted from its local mean.
Only greyvalues between percentiles [p0, p1] are considered in the filter.
 Parameters
image : 2D array (uint8, uint16)
Input image.
selem : 2D array
The neighborhood expressed as a 2D array of 1’s and 0’s.
out : 2D array (same dtype as input)
If None, a new array is allocated.
mask : ndarray
Mask array that defines (>0) area of the image included in the local neighborhood. If None, the complete image is used (default).
shift_x, shift_y : int
Offset added to the structuring element center point. Shift is bounded to the structuring element sizes (center must be inside the given structuring element).
p0, p1 : float in [0, …, 1]
Define the [p0, p1] percentile interval to be considered for computing the value.
 Returns
out : 2D array (same dtype as input image)
Output image.
median¶

skimage.filters.rank.
median
(image, selem=None, out=None, mask=None, shift_x=False, shift_y=False)[source]¶ Return local median of an image.
 Parameters
image : 2D array (uint8, uint16)
Input image.
selem : 2D array, optional
The neighborhood expressed as a 2D array of 1’s and 0’s. If None, a full square of size 3 is used.
out : 2D array (same dtype as input)
If None, a new array is allocated.
mask : ndarray
Mask array that defines (>0) area of the image included in the local neighborhood. If None, the complete image is used (default).
shift_x, shift_y : int
Offset added to the structuring element center point. Shift is bounded to the structuring element sizes (center must be inside the given structuring element).
 Returns
out : 2D array (same dtype as input image)
Output image.
See also
skimage.filters.median
Implementation of a median filtering which handles images with floating precision.
Examples
>>> from skimage import data >>> from skimage.morphology import disk >>> from skimage.filters.rank import median >>> img = data.camera() >>> med = median(img, disk(5))
minimum¶

skimage.filters.rank.
minimum
(image, selem, out=None, mask=None, shift_x=False, shift_y=False)[source]¶ Return local minimum of an image.
 Parameters
image : 2D array (uint8, uint16)
Input image.
selem : 2D array
The neighborhood expressed as a 2D array of 1’s and 0’s.
out : 2D array (same dtype as input)
If None, a new array is allocated.
mask : ndarray
Mask array that defines (>0) area of the image included in the local neighborhood. If None, the complete image is used (default).
shift_x, shift_y : int
Offset added to the structuring element center point. Shift is bounded to the structuring element sizes (center must be inside the given structuring element).
 Returns
out : 2D array (same dtype as input image)
Output image.
See also
Notes
The lower algorithm complexity makes skimage.filters.rank.minimum more efficient for larger images and structuring elements.
Examples
>>> from skimage import data >>> from skimage.morphology import disk >>> from skimage.filters.rank import minimum >>> img = data.camera() >>> out = minimum(img, disk(5))
Examples using skimage.filters.rank.minimum
¶
modal¶

skimage.filters.rank.
modal
(image, selem, out=None, mask=None, shift_x=False, shift_y=False)[source]¶ Return local mode of an image.
The mode is the value that appears most often in the local histogram.
 Parameters
image : 2D array (uint8, uint16)
Input image.
selem : 2D array
The neighborhood expressed as a 2D array of 1’s and 0’s.
out : 2D array (same dtype as input)
If None, a new array is allocated.
mask : ndarray
Mask array that defines (>0) area of the image included in the local neighborhood. If None, the complete image is used (default).
shift_x, shift_y : int
Offset added to the structuring element center point. Shift is bounded to the structuring element sizes (center must be inside the given structuring element).
 Returns
out : 2D array (same dtype as input image)
Output image.
Examples
>>> from skimage import data >>> from skimage.morphology import disk >>> from skimage.filters.rank import modal >>> img = data.camera() >>> out = modal(img, disk(5))
enhance_contrast¶

skimage.filters.rank.
enhance_contrast
(image, selem, out=None, mask=None, shift_x=False, shift_y=False)[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.
 Parameters
image : 2D array (uint8, uint16)
Input image.
selem : 2D array
The neighborhood expressed as a 2D array of 1’s and 0’s.
out : 2D array (same dtype as input)
If None, a new array is allocated.
mask : ndarray
Mask array that defines (>0) area of the image included in the local neighborhood. If None, the complete image is used (default).
shift_x, shift_y : int
Offset added to the structuring element center point. Shift is bounded to the structuring element sizes (center must be inside the given structuring element).
 Returns
out : 2D array (same dtype as input image)
The result of the local enhance_contrast.
Examples
>>> from skimage import data >>> from skimage.morphology import disk >>> from skimage.filters.rank import enhance_contrast >>> img = data.camera() >>> out = enhance_contrast(img, disk(5))
Examples using skimage.filters.rank.enhance_contrast
¶
enhance_contrast_percentile¶

skimage.filters.rank.
enhance_contrast_percentile
(image, selem, out=None, mask=None, shift_x=False, shift_y=False, p0=0, p1=1)[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.
 Parameters
image : 2D array (uint8, uint16)
Input image.
selem : 2D array
The neighborhood expressed as a 2D array of 1’s and 0’s.
out : 2D array (same dtype as input)
If None, a new array is allocated.
mask : ndarray
Mask array that defines (>0) area of the image included in the local neighborhood. If None, the complete image is used (default).
shift_x, shift_y : int
Offset added to the structuring element center point. Shift is bounded to the structuring element sizes (center must be inside the given structuring element).
p0, p1 : float in [0, …, 1]
Define the [p0, p1] percentile interval to be considered for computing the value.
 Returns
out : 2D array (same dtype as input image)
Output image.
Examples using skimage.filters.rank.enhance_contrast_percentile
¶
pop¶

skimage.filters.rank.
pop
(image, selem, out=None, mask=None, shift_x=False, shift_y=False)[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.
 Parameters
image : 2D array (uint8, uint16)
Input image.
selem : 2D array
The neighborhood expressed as a 2D array of 1’s and 0’s.
out : 2D array (same dtype as input)
If None, a new array is allocated.
mask : ndarray
Mask array that defines (>0) area of the image included in the local neighborhood. If None, the complete image is used (default).
shift_x, shift_y : int
Offset added to the structuring element center point. Shift is bounded to the structuring element sizes (center must be inside the given structuring element).
 Returns
out : 2D array (same dtype as input image)
Output image.
Examples
>>> from skimage.morphology import square >>> import skimage.filters.rank as rank >>> img = 255 * np.array([[0, 0, 0, 0, 0], ... [0, 1, 1, 1, 0], ... [0, 1, 1, 1, 0], ... [0, 1, 1, 1, 0], ... [0, 0, 0, 0, 0]], dtype=np.uint8) >>> rank.pop(img, square(3)) array([[4, 6, 6, 6, 4], [6, 9, 9, 9, 6], [6, 9, 9, 9, 6], [6, 9, 9, 9, 6], [4, 6, 6, 6, 4]], dtype=uint8)
pop_percentile¶

skimage.filters.rank.
pop_percentile
(image, selem, out=None, mask=None, shift_x=False, shift_y=False, p0=0, p1=1)[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.
 Parameters
image : 2D array (uint8, uint16)
Input image.
selem : 2D array
The neighborhood expressed as a 2D array of 1’s and 0’s.
out : 2D array (same dtype as input)
If None, a new array is allocated.
mask : ndarray
Mask array that defines (>0) area of the image included in the local neighborhood. If None, the complete image is used (default).
shift_x, shift_y : int
Offset added to the structuring element center point. Shift is bounded to the structuring element sizes (center must be inside the given structuring element).
p0, p1 : float in [0, …, 1]
Define the [p0, p1] percentile interval to be considered for computing the value.
 Returns
out : 2D array (same dtype as input image)
Output image.
pop_bilateral¶

skimage.filters.rank.
pop_bilateral
(image, selem, out=None, mask=None, shift_x=False, shift_y=False, s0=10, s1=10)[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 greylevel inside the interval [gs0, g+s1] where g is the greyvalue of the center pixel.
 Parameters
image : 2D array (uint8, uint16)
Input image.
selem : 2D array
The neighborhood expressed as a 2D array of 1’s and 0’s.
out : 2D array (same dtype as input)
If None, a new array is allocated.
mask : ndarray
Mask array that defines (>0) area of the image included in the local neighborhood. If None, the complete image is used (default).
shift_x, shift_y : int
Offset added to the structuring element center point. Shift is bounded to the structuring element sizes (center must be inside the given structuring element).
s0, s1 : int
Define the [s0, s1] interval around the greyvalue of the center pixel to be considered for computing the value.
 Returns
out : 2D array (same dtype as input image)
Output image.
Examples
>>> from skimage.morphology import square >>> import skimage.filters.rank as rank >>> img = 255 * np.array([[0, 0, 0, 0, 0], ... [0, 1, 1, 1, 0], ... [0, 1, 1, 1, 0], ... [0, 1, 1, 1, 0], ... [0, 0, 0, 0, 0]], dtype=np.uint16) >>> rank.pop_bilateral(img, square(3), s0=10, s1=10) array([[3, 4, 3, 4, 3], [4, 4, 6, 4, 4], [3, 6, 9, 6, 3], [4, 4, 6, 4, 4], [3, 4, 3, 4, 3]], dtype=uint16)
sum¶

skimage.filters.rank.
sum
(image, selem, out=None, mask=None, shift_x=False, shift_y=False)[source]¶ Return the local sum of pixels.
Note that the sum may overflow depending on the data type of the input array.
 Parameters
image : 2D array (uint8, uint16)
Input image.
selem : 2D array
The neighborhood expressed as a 2D array of 1’s and 0’s.
out : 2D array (same dtype as input)
If None, a new array is allocated.
mask : ndarray
Mask array that defines (>0) area of the image included in the local neighborhood. If None, the complete image is used (default).
shift_x, shift_y : int
Offset added to the structuring element center point. Shift is bounded to the structuring element sizes (center must be inside the given structuring element).
 Returns
out : 2D array (same dtype as input image)
Output image.
Examples
>>> from skimage.morphology import square >>> import skimage.filters.rank as rank >>> img = np.array([[0, 0, 0, 0, 0], ... [0, 1, 1, 1, 0], ... [0, 1, 1, 1, 0], ... [0, 1, 1, 1, 0], ... [0, 0, 0, 0, 0]], dtype=np.uint8) >>> rank.sum(img, square(3)) array([[1, 2, 3, 2, 1], [2, 4, 6, 4, 2], [3, 6, 9, 6, 3], [2, 4, 6, 4, 2], [1, 2, 3, 2, 1]], dtype=uint8)
sum_bilateral¶

skimage.filters.rank.
sum_bilateral
(image, selem, out=None, mask=None, shift_x=False, shift_y=False, s0=10, s1=10)[source]¶ Apply a flat kernel bilateral filter.
This is an edgepreserving 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 (selem).
Radiometric similarity is defined by the greylevel interval [gs0, 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.
 Parameters
image : 2D array (uint8, uint16)
Input image.
selem : 2D array
The neighborhood expressed as a 2D array of 1’s and 0’s.
out : 2D array (same dtype as input)
If None, a new array is allocated.
mask : ndarray
Mask array that defines (>0) area of the image included in the local neighborhood. If None, the complete image is used (default).
shift_x, shift_y : int
Offset added to the structuring element center point. Shift is bounded to the structuring element sizes (center must be inside the given structuring element).
s0, s1 : int
Define the [s0, s1] interval around the greyvalue of the center pixel to be considered for computing the value.
 Returns
out : 2D array (same dtype as input image)
Output image.
See also
denoise_bilateral
Examples
>>> from skimage import data >>> from skimage.morphology import disk >>> from skimage.filters.rank import sum_bilateral >>> img = data.camera().astype(np.uint16) >>> bilat_img = sum_bilateral(img, disk(10), s0=10, s1=10)
sum_percentile¶

skimage.filters.rank.
sum_percentile
(image, selem, out=None, mask=None, shift_x=False, shift_y=False, p0=0, p1=1)[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.
 Parameters
image : 2D array (uint8, uint16)
Input image.
selem : 2D array
The neighborhood expressed as a 2D array of 1’s and 0’s.
out : 2D array (same dtype as input)
If None, a new array is allocated.
mask : ndarray
Mask array that defines (>0) area of the image included in the local neighborhood. If None, the complete image is used (default).
shift_x, shift_y : int
Offset added to the structuring element center point. Shift is bounded to the structuring element sizes (center must be inside the given structuring element).
p0, p1 : float in [0, …, 1]
Define the [p0, p1] percentile interval to be considered for computing the value.
 Returns
out : 2D array (same dtype as input image)
Output image.
threshold¶

skimage.filters.rank.
threshold
(image, selem, out=None, mask=None, shift_x=False, shift_y=False)[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.
 Parameters
image : 2D array (uint8, uint16)
Input image.
selem : 2D array
The neighborhood expressed as a 2D array of 1’s and 0’s.
out : 2D array (same dtype as input)
If None, a new array is allocated.
mask : ndarray
Mask array that defines (>0) area of the image included in the local neighborhood. If None, the complete image is used (default).
shift_x, shift_y : int
Offset added to the structuring element center point. Shift is bounded to the structuring element sizes (center must be inside the given structuring element).
 Returns
out : 2D array (same dtype as input image)
Output image.
Examples
>>> from skimage.morphology import square >>> from skimage.filters.rank import threshold >>> img = 255 * np.array([[0, 0, 0, 0, 0], ... [0, 1, 1, 1, 0], ... [0, 1, 1, 1, 0], ... [0, 1, 1, 1, 0], ... [0, 0, 0, 0, 0]], dtype=np.uint8) >>> threshold(img, square(3)) array([[0, 0, 0, 0, 0], [0, 1, 1, 1, 0], [0, 1, 0, 1, 0], [0, 1, 1, 1, 0], [0, 0, 0, 0, 0]], dtype=uint8)
threshold_percentile¶

skimage.filters.rank.
threshold_percentile
(image, selem, out=None, mask=None, shift_x=False, shift_y=False, p0=0)[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.
 Parameters
image : 2D array (uint8, uint16)
Input image.
selem : 2D array
The neighborhood expressed as a 2D array of 1’s and 0’s.
out : 2D array (same dtype as input)
If None, a new array is allocated.
mask : ndarray
Mask array that defines (>0) area of the image included in the local neighborhood. If None, the complete image is used (default).
shift_x, shift_y : int
Offset added to the structuring element center point. Shift is bounded to the structuring element sizes (center must be inside the given structuring element).
p0 : float in [0, …, 1]
Set the percentile value.
 Returns
out : 2D array (same dtype as input image)
Output image.
tophat¶

skimage.filters.rank.
tophat
(image, selem, out=None, mask=None, shift_x=False, shift_y=False)[source]¶ Local tophat of an image.
This filter computes the morphological opening of the image and then subtracts the result from the original image.
 Parameters
image : 2D array (uint8, uint16)
Input image.
selem : 2D array
The neighborhood expressed as a 2D array of 1’s and 0’s.
out : 2D array (same dtype as input)
If None, a new array is allocated.
mask : ndarray
Mask array that defines (>0) area of the image included in the local neighborhood. If None, the complete image is used (default).
shift_x, shift_y : int
Offset added to the structuring element center point. Shift is bounded to the structuring element sizes (center must be inside the given structuring element).
 Returns
out : 2D array (same dtype as input image)
Output image.
Examples
>>> from skimage import data >>> from skimage.morphology import disk >>> from skimage.filters.rank import tophat >>> img = data.camera() >>> out = tophat(img, disk(5))
noise_filter¶

skimage.filters.rank.
noise_filter
(image, selem, out=None, mask=None, shift_x=False, shift_y=False)[source]¶ Noise feature.
 Parameters
image : 2D array (uint8, uint16)
Input image.
selem : 2D array
The neighborhood expressed as a 2D array of 1’s and 0’s.
out : 2D array (same dtype as input)
If None, a new array is allocated.
mask : ndarray
Mask array that defines (>0) area of the image included in the local neighborhood. If None, the complete image is used (default).
shift_x, shift_y : int
Offset added to the structuring element center point. Shift is bounded to the structuring element sizes (center must be inside the given structuring element).
 Returns
out : 2D array (same dtype as input image)
Output image.
References
 R290
N. Hashimoto et al. Referenceless image quality evaluation for whole slide imaging. J Pathol Inform 2012;3:9.
Examples
>>> from skimage import data >>> from skimage.morphology import disk >>> from skimage.filters.rank import noise_filter >>> img = data.camera() >>> out = noise_filter(img, disk(5))
entropy¶

skimage.filters.rank.
entropy
(image, selem, out=None, mask=None, shift_x=False, shift_y=False)[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.
 Parameters
image : 2D array (uint8, uint16)
Input image.
selem : 2D array
The neighborhood expressed as a 2D array of 1’s and 0’s.
out : 2D array (same dtype as input)
If None, a new array is allocated.
mask : ndarray
Mask array that defines (>0) area of the image included in the local neighborhood. If None, the complete image is used (default).
shift_x, shift_y : int
Offset added to the structuring element center point. Shift is bounded to the structuring element sizes (center must be inside the given structuring element).
 Returns
out : ndarray (double)
Output image.
References
Examples
>>> from skimage import data >>> from skimage.filters.rank import entropy >>> from skimage.morphology import disk >>> img = data.camera() >>> ent = entropy(img, disk(5))
otsu¶

skimage.filters.rank.
otsu
(image, selem, out=None, mask=None, shift_x=False, shift_y=False)[source]¶ Local Otsu’s threshold value for each pixel.
 Parameters
image : ndarray
Image array (uint8 array).
selem : 2D array
The neighborhood expressed as a 2D array of 1’s and 0’s.
out : ndarray
If None, a new array will be allocated.
mask : ndarray
Mask array that defines (>0) area of the image included in the local neighborhood. If None, the complete image is used (default).
shift_x, shift_y : int
Offset added to the structuring element center point. Shift is bounded to the structuring element sizes (center must be inside the given structuring element).
 Returns
out : 2D array (same dtype as input image)
Output image.
References
Examples
>>> from skimage import data >>> from skimage.filters.rank import otsu >>> from skimage.morphology import disk >>> img = data.camera() >>> local_otsu = otsu(img, disk(5)) >>> thresh_image = img >= local_otsu
percentile¶

skimage.filters.rank.
percentile
(image, selem, out=None, mask=None, shift_x=False, shift_y=False, p0=0)[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.
 Parameters
image : 2D array (uint8, uint16)
Input image.
selem : 2D array
The neighborhood expressed as a 2D array of 1’s and 0’s.
out : 2D array (same dtype as input)
If None, a new array is allocated.
mask : ndarray
Mask array that defines (>0) area of the image included in the local neighborhood. If None, the complete image is used (default).
shift_x, shift_y : int
Offset added to the structuring element center point. Shift is bounded to the structuring element sizes (center must be inside the given structuring element).
p0 : float in [0, …, 1]
Set the percentile value.
 Returns
out : 2D array (same dtype as input image)
Output image.
windowed_histogram¶

skimage.filters.rank.
windowed_histogram
(image, selem, out=None, mask=None, shift_x=False, shift_y=False, n_bins=None)[source]¶ Normalized sliding window histogram
 Parameters
image : ndarray
Image array (uint8 array).
selem : 2D array
The neighborhood expressed as a 2D array of 1’s and 0’s.
out : ndarray
If None, a new array will be allocated.
mask : ndarray
Mask array that defines (>0) area of the image included in the local neighborhood. If None, the complete image is used (default).
shift_x, shift_y : int
Offset added to the structuring element center point. Shift is bounded to the structuring element sizes (center must be inside the given structuring element).
n_bins : int or None
The number of histogram bins. Will default to
image.max() + 1
if None is passed. Returns
out : 3D array with float dtype of dimensions (H,W,N), where (H,W) are
the dimensions of the input image and N is n_bins or
image.max() + 1
if no value is provided as a parameter. Effectively, each pixel is a ND feature vector that is the histogram. The sum of the elements in the feature vector will be 1, unless no pixels in the window were covered by both selem and mask, in which case all elements will be 0.
Examples
>>> from skimage import data >>> from skimage.filters.rank import windowed_histogram >>> from skimage.morphology import disk >>> img = data.camera() >>> hist_img = windowed_histogram(img, disk(5))
Examples using skimage.filters.rank.windowed_histogram
¶
majority¶

skimage.filters.rank.
majority
(image, selem, out=None, mask=None, shift_x=False, shift_y=False)[source]¶ Majority filter assign to each pixel the most occuring value within its neighborhood.
 Parameters
image : ndarray
Image array (uint8, uint16 array).
selem : 2D array
The neighborhood expressed as a 2D array of 1’s and 0’s.
out : ndarray
If None, a new array will be allocated.
mask : ndarray
Mask array that defines (>0) area of the image included in the local neighborhood. If None, the complete image is used (default).
shift_x, shift_y : int
Offset added to the structuring element center point. Shift is bounded to the structuring element sizes (center must be inside the given structuring element).
 Returns
out : 2D array (same dtype as input image)
Output image.
Examples
>>> from skimage import data >>> from skimage.filters.rank import majority >>> from skimage.morphology import disk >>> img = data.camera() >>> maj_img = majority(img, disk(5))