skimage.filters.rank#
Auto-level image using local histogram. |
|
Return grayscale local autolevel of an image. |
|
Enhance contrast of an image. |
|
Enhance contrast of an image. |
|
Local entropy. |
|
Equalize image using local histogram. |
|
Return local geometric mean of an image. |
|
Return local gradient of an image (i.e. local maximum - local minimum). |
|
Return local gradient of an image (i.e., local maximum - local minimum). |
|
Assign to each pixel the most common value within its neighborhood. |
|
Return local maximum of an image. |
|
Return local mean of an image. |
|
Apply a flat kernel bilateral filter. |
|
Return local mean of an image. |
|
Return local median of an image. |
|
Return local minimum of an image. |
|
Return local mode of an image. |
|
Noise feature. |
|
Local Otsu's threshold value for each pixel. |
|
Return local percentile 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 image subtracted from its local mean. |
|
Return image subtracted from its local mean. |
|
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. |
|
Compute normalized sliding window histogram. |
- skimage.filters.rank.autolevel(image, footprint, out=None, mask=None, shift_x=0, shift_y=0, shift_z=0)[source]#
Auto-level image using local histogram.
This filter locally stretches the histogram of gray values to cover the entire range of values from “white” to “black”.
- Parameters:
- imagendarray of shape ([P,] M, N) and dtype (uint8 or uint16)
Input image.
- footprintndarray
The neighborhood expressed as an ndarray of 1’s and 0’s.
- outndarray of shape ([P,] M, N), same dtype as input
image If None, a new array is allocated.
- maskndarray of dtype (int or float), optional
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, shift_zint
Offset added to the footprint center point. Shift is bounded to the footprint sizes (center must be inside the given footprint).
- Returns:
- outndarray of shape ([P,] M, N), same dtype as input
image Output image.
- outndarray of shape ([P,] M, N), same dtype as input
Examples
>>> from _skimage2 import data >>> from _skimage2.morphology import disk, ball >>> from _skimage2.filters.rank import autolevel >>> import numpy as np >>> img = data.camera() >>> rng = np.random.default_rng() >>> volume = rng.integers(0, 255, size=(10,10,10), dtype=np.uint8) >>> auto = autolevel(img, disk(5)) >>> auto_vol = autolevel(volume, ball(5))
- skimage.filters.rank.autolevel_percentile(image, footprint, out=None, mask=None, shift_x=0, shift_y=0, p0=0, p1=1)[source]#
Return grayscale local autolevel of an image.
This filter locally stretches the histogram of grayvalues to cover the entire range of values from “white” to “black”.
Only grayvalues between percentiles [p0, p1] are considered in the filter.
- Parameters:
- imagendarray of shape (M, N) and dtype (uint8 or uint16)
Input image.
- footprintndarray of shape (m, n)
The neighborhood expressed as a 2-D array of 1’s and 0’s.
- outndarray of shape (M, N), same dtype as input
image If None, a new array is allocated.
- maskndarray
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_yint
Offset added to the footprint center point. Shift is bounded to the footprint sizes (center must be inside the given footprint).
- p0, p1float, optional, in interval [0, 1]
Define the [p0, p1] percentile interval to be considered for computing the value.
- Returns:
- outndarray of shape (M, N), same dtype as input
image Output image.
- outndarray of shape (M, N), same dtype as input
- skimage.filters.rank.enhance_contrast(image, footprint, out=None, mask=None, shift_x=0, shift_y=0, shift_z=0)[source]#
Enhance contrast of an image.
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.
- Parameters:
- imagendarray of shape ([P,] M, N) and dtype (uint8 or uint16)
Input image.
- footprintndarray
The neighborhood expressed as an ndarray of 1’s and 0’s.
- outndarray of shape ([P,] M, N), same dtype as input
image If None, a new array is allocated.
- maskndarray of dtype (int or float), optional
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, shift_zint
Offset added to the footprint center point. Shift is bounded to the footprint sizes (center must be inside the given footprint).
- Returns:
- out([P,] M, N) ndarray, same dtype as
image Output image
- out([P,] M, N) ndarray, same dtype as
Examples
>>> from _skimage2 import data >>> from _skimage2.morphology import disk, ball >>> from _skimage2.filters.rank import enhance_contrast >>> import numpy as np >>> img = data.camera() >>> rng = np.random.default_rng() >>> volume = rng.integers(0, 255, size=(10,10,10), dtype=np.uint8) >>> out = enhance_contrast(img, disk(5)) >>> out_vol = enhance_contrast(volume, ball(5))
- skimage.filters.rank.enhance_contrast_percentile(image, footprint, out=None, mask=None, shift_x=0, shift_y=0, p0=0, p1=1)[source]#
Enhance contrast of an image.
This replaces each pixel by the local maximum if the pixel grayvalue is closer to the local maximum than the local minimum. Otherwise it is replaced by the local minimum.
Only grayvalues between percentiles [p0, p1] are considered in the filter.
- Parameters:
- image2-D array (uint8, uint16)
Input image.
- footprintndarray of shape (m, n)
The neighborhood expressed as a 2-D array of 1’s and 0’s.
- out2-D array, same dtype as input
image If None, a new array is allocated.
- maskndarray
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_yint
Offset added to the footprint center point. Shift is bounded to the footprint sizes (center must be inside the given footprint).
- p0, p1float, optional, in interval [0, 1]
Define the [p0, p1] percentile interval to be considered for computing the value.
- Returns:
- out2-D array, same dtype as input
image Output image.
- out2-D array, same dtype as input
- skimage.filters.rank.entropy(image, footprint, out=None, mask=None, shift_x=0, shift_y=0, shift_z=0)[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 gray level distribution.
- Parameters:
- imagendarray of shape ([P,] M, N) and dtype (uint8 or uint16)
Input image.
- footprintndarray
The neighborhood expressed as an ndarray of 1’s and 0’s.
- outndarray of shape ([P,] M, N), same dtype as input
image If None, a new array is allocated.
- maskndarray of dtype (int or float), optional
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, shift_zint
Offset added to the footprint center point. Shift is bounded to the footprint sizes (center must be inside the given footprint).
- Returns:
- outndarray of shape ([P,] M, N) and dtype float
Output image.
References
Examples
>>> from _skimage2 import data >>> from _skimage2.filters.rank import entropy >>> from _skimage2.morphology import disk, ball >>> import numpy as np >>> img = data.camera() >>> rng = np.random.default_rng() >>> volume = rng.integers(0, 255, size=(10,10,10), dtype=np.uint8) >>> ent = entropy(img, disk(5)) >>> ent_vol = entropy(volume, ball(5))
- skimage.filters.rank.equalize(image, footprint, out=None, mask=None, shift_x=0, shift_y=0, shift_z=0)[source]#
Equalize image using local histogram.
- Parameters:
- imagendarray of shape ([P,] M, N) and dtype (uint8 or uint16)
Input image.
- footprintndarray
The neighborhood expressed as an ndarray of 1’s and 0’s.
- outndarray of shape ([P,] M, N), same dtype as input
image If None, a new array is allocated.
- maskndarray of dtype (int or float), optional
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, shift_zint
Offset added to the footprint center point. Shift is bounded to the footprint sizes (center must be inside the given footprint).
- Returns:
- out([P,] M, N) ndarray, same dtype as
image Output image.
- out([P,] M, N) ndarray, same dtype as
Examples
>>> from _skimage2 import data >>> from _skimage2.morphology import disk, ball >>> from _skimage2.filters.rank import equalize >>> import numpy as np >>> img = data.camera() >>> rng = np.random.default_rng() >>> volume = rng.integers(0, 255, size=(10,10,10), dtype=np.uint8) >>> equ = equalize(img, disk(5)) >>> equ_vol = equalize(volume, ball(5))
- skimage.filters.rank.geometric_mean(image, footprint, out=None, mask=None, shift_x=0, shift_y=0, shift_z=0)[source]#
Return local geometric mean of an image.
- Parameters:
- imagendarray of shape ([P,] M, N) and dtype (uint8 or uint16)
Input image.
- footprintndarray
The neighborhood expressed as an ndarray of 1’s and 0’s.
- outndarray of shape ([P,] M, N), same dtype as input
image If None, a new array is allocated.
- maskndarray of dtype (int or float), optional
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, shift_zint
Offset added to the footprint center point. Shift is bounded to the footprint sizes (center must be inside the given footprint).
- Returns:
- out([P,] M, N) ndarray, same dtype as
image Output image.
- out([P,] M, N) ndarray, same dtype as
References
[1]Gonzalez, R. C. and Woods, R. E. “Digital Image Processing (3rd Edition).” Prentice-Hall Inc, 2006.
Examples
>>> from _skimage2 import data >>> from _skimage2.morphology import disk, ball >>> from _skimage2.filters.rank import mean >>> import numpy as np >>> img = data.camera() >>> rng = np.random.default_rng() >>> volume = rng.integers(0, 255, size=(10,10,10), dtype=np.uint8) >>> avg = geometric_mean(img, disk(5)) >>> avg_vol = geometric_mean(volume, ball(5))
- skimage.filters.rank.gradient(image, footprint, out=None, mask=None, shift_x=0, shift_y=0, shift_z=0)[source]#
Return local gradient of an image (i.e. local maximum - local minimum).
- Parameters:
- imagendarray of shape ([P,] M, N) and dtype (uint8 or uint16)
Input image.
- footprintndarray
The neighborhood expressed as an ndarray of 1’s and 0’s.
- outndarray of shape ([P,] M, N), same dtype as input
image If None, a new array is allocated.
- maskndarray of dtype (int or float), optional
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, shift_zint
Offset added to the footprint center point. Shift is bounded to the footprint sizes (center must be inside the given footprint).
- Returns:
- out([P,] M, N) ndarray, same dtype as
image Output image.
- out([P,] M, N) ndarray, same dtype as
Examples
>>> from _skimage2 import data >>> from _skimage2.morphology import disk, ball >>> from _skimage2.filters.rank import gradient >>> import numpy as np >>> img = data.camera() >>> rng = np.random.default_rng() >>> volume = rng.integers(0, 255, size=(10,10,10), dtype=np.uint8) >>> out = gradient(img, disk(5)) >>> out_vol = gradient(volume, ball(5))
- skimage.filters.rank.gradient_percentile(image, footprint, out=None, mask=None, shift_x=0, shift_y=0, p0=0, p1=1)[source]#
Return local gradient of an image (i.e., local maximum - local minimum).
Only grayvalues between percentiles [p0, p1] are considered in the filter.
- Parameters:
- imagendarray of shape (M, N) and dtype (uint8 or uint16)
Input image.
- footprintndarray of shape (m, n)
The neighborhood expressed as a 2-D array of 1’s and 0’s.
- outndarray of shape (M, N) and dtype int
If None, a new array is allocated.
- maskndarray
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_yint
Offset added to the footprint center point. Shift is bounded to the footprint sizes (center must be inside the given footprint).
- p0, p1float, optional, in interval [0, 1]
Define the [p0, p1] percentile interval to be considered for computing the value.
- Returns:
- outndarray of shape (M, N) and dtype int
Output image.
- skimage.filters.rank.majority(image, footprint, *, out=None, mask=None, shift_x=0, shift_y=0, shift_z=0)[source]#
Assign to each pixel the most common value within its neighborhood.
- Parameters:
- imagendarray of dtype (int or float)
Image array.
- footprint2-D array (integer or float)
The neighborhood expressed as a 2-D array of 1’s and 0’s.
- outndarray of dtype int, optional
If None, a new array will be allocated.
- maskndarray of dtype (int or float), optional
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_yint, optional
Offset added to the footprint center point. Shift is bounded to the footprint sizes (center must be inside the given footprint).
- Returns:
- outndarray of dtype int, optional
Output image.
Examples
>>> import numpy as np >>> import _skimage2 as ski2 >>> img = ski2.data.camera() >>> rng = np.random.default_rng() >>> volume = rng.integers(0, 255, size=(10, 10, 10), dtype=np.uint8) >>> maj_img = ski2.filters.rank.majority(img, ski2.morphology.disk(5)) >>> maj_img_vol = ski2.filters.rank.majority(volume, ski2.morphology.ball(5))
- skimage.filters.rank.maximum(image, footprint, out=None, mask=None, shift_x=0, shift_y=0, shift_z=0)[source]#
Return local maximum of an image.
- Parameters:
- imagendarray of shape ([P,] M, N) and dtype (uint8 or uint16)
Input image.
- footprintndarray
The neighborhood expressed as an ndarray of 1’s and 0’s.
- outndarray of shape ([P,] M, N), same dtype as input
image If None, a new array is allocated.
- maskndarray of dtype (int or float), optional
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, shift_zint
Offset added to the footprint center point. Shift is bounded to the footprint sizes (center must be inside the given footprint).
- Returns:
- out([P,] M, N) ndarray, same dtype as
image Output image.
- out([P,] M, N) ndarray, same dtype as
See also
Notes
The lower algorithm complexity makes
skimage.filters.rank.maximummore efficient for larger images and footprints.Examples
>>> from _skimage2 import data >>> from _skimage2.morphology import disk, ball >>> from _skimage2.filters.rank import maximum >>> import numpy as np >>> img = data.camera() >>> rng = np.random.default_rng() >>> volume = rng.integers(0, 255, size=(10,10,10), dtype=np.uint8) >>> out = maximum(img, disk(5)) >>> out_vol = maximum(volume, ball(5))
- skimage.filters.rank.mean(image, footprint, out=None, mask=None, shift_x=0, shift_y=0, shift_z=0)[source]#
Return local mean of an image.
- Parameters:
- imagendarray of shape ([P,] M, N) and dtype (uint8 or uint16)
Input image.
- footprintndarray
The neighborhood expressed as an ndarray of 1’s and 0’s.
- outndarray of shape ([P,] M, N), same dtype as input
image If None, a new array is allocated.
- maskndarray of dtype (int or float), optional
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, shift_zint
Offset added to the footprint center point. Shift is bounded to the footprint sizes (center must be inside the given footprint).
- Returns:
- out([P,] M, N) ndarray, same dtype as
image Output image.
- out([P,] M, N) ndarray, same dtype as
Examples
>>> from _skimage2 import data >>> from _skimage2.morphology import disk, ball >>> from _skimage2.filters.rank import mean >>> import numpy as np >>> img = data.camera() >>> rng = np.random.default_rng() >>> volume = rng.integers(0, 255, size=(10,10,10), dtype=np.uint8) >>> avg = mean(img, disk(5)) >>> avg_vol = mean(volume, ball(5))
- skimage.filters.rank.mean_bilateral(image, footprint, out=None, mask=None, shift_x=0, shift_y=0, s0=10, s1=10)[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 footprint (structuring element).
Radiometric similarity is defined by the graylevel interval [g-s0, g+s1] where g is the current pixel graylevel.
Only pixels belonging to the footprint and having a graylevel inside this interval are averaged.
- Parameters:
- image2-D array (uint8, uint16)
Input image.
- footprint2-D array
The neighborhood expressed as a 2-D array of 1’s and 0’s.
- out2-D array, same dtype as input
image If None, a new array is allocated.
- maskndarray
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_yint
Offset added to the footprint center point. Shift is bounded to the footprint sizes (center must be inside the given footprint).
- s0, s1int
Define the [s0, s1] interval around the grayvalue of the center pixel to be considered for computing the value.
- Returns:
- out2-D array, same dtype as input
image Output image.
- out2-D array, same dtype as input
Examples
>>> import numpy as np >>> from _skimage2 import data >>> from _skimage2.morphology import disk >>> from _skimage2.filters.rank import mean_bilateral >>> img = data.camera().astype(np.uint16) >>> bilat_img = mean_bilateral(img, disk(20), s0=10,s1=10)
- skimage.filters.rank.mean_percentile(image, footprint, out=None, mask=None, shift_x=0, shift_y=0, p0=0, p1=1)[source]#
Return local mean of an image.
Only grayvalues between percentiles [p0, p1] are considered in the filter.
- Parameters:
- imagendarray of shape (M, N) and dtype (uint8 or uint16)
Input image.
- footprintndarray of shape (m, n)
The neighborhood expressed as a 2-D array of 1’s and 0’s.
- outndarray of shape (M, N) and dtype int
If None, a new array is allocated.
- maskndarray
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_yint
Offset added to the footprint center point. Shift is bounded to the footprint sizes (center must be inside the given footprint).
- p0, p1float, optional, in interval [0, 1]
Define the [p0, p1] percentile interval to be considered for computing the value.
- Returns:
- outndarray of shape (M, N) and dtype int
Output image.
- skimage.filters.rank.median(image, footprint=None, out=None, mask=None, shift_x=0, shift_y=0, shift_z=0)[source]#
Return local median of an image.
- Parameters:
- imagendarray of shape ([P,] M, N) and dtype (uint8 or uint16)
Input image.
- footprintndarray
The neighborhood expressed as an ndarray of 1’s and 0’s. If None, a full square of size 3 is used.
- outndarray of shape ([P,] M, N), same dtype as input
image If None, a new array is allocated.
- maskndarray of dtype (int or float), optional
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, shift_zint
Offset added to the footprint center point. Shift is bounded to the footprint sizes (center must be inside the given footprint).
- Returns:
- out([P,] M, N) ndarray, same dtype as
image Output image.
- out([P,] M, N) ndarray, same dtype as
See also
skimage.filters.medianImplementation of a median filtering which handles images with floating precision.
Examples
>>> from _skimage2 import data >>> from _skimage2.morphology import disk, ball >>> from _skimage2.filters.rank import median >>> import numpy as np >>> img = data.camera() >>> rng = np.random.default_rng() >>> volume = rng.integers(0, 255, size=(10,10,10), dtype=np.uint8) >>> med = median(img, disk(5)) >>> med_vol = median(volume, ball(5))
- skimage.filters.rank.minimum(image, footprint, out=None, mask=None, shift_x=0, shift_y=0, shift_z=0)[source]#
Return local minimum of an image.
- Parameters:
- imagendarray of shape ([P,] M, N) and dtype (uint8 or uint16)
Input image.
- footprintndarray
The neighborhood expressed as an ndarray of 1’s and 0’s.
- outndarray of shape ([P,] M, N), same dtype as input
image If None, a new array is allocated.
- maskndarray of dtype (int or float), optional
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, shift_zint
Offset added to the footprint center point. Shift is bounded to the footprint sizes (center must be inside the given footprint).
- Returns:
- outndarray of shape ([P,] M, N), same dtype as input
image Output image.
- outndarray of shape ([P,] M, N), same dtype as input
See also
Notes
The lower algorithm complexity makes
skimage.filters.rank.minimummore efficient for larger images and footprints.Examples
>>> from _skimage2 import data >>> from _skimage2.morphology import disk, ball >>> from _skimage2.filters.rank import minimum >>> import numpy as np >>> img = data.camera() >>> rng = np.random.default_rng() >>> volume = rng.integers(0, 255, size=(10,10,10), dtype=np.uint8) >>> out = minimum(img, disk(5)) >>> out_vol = minimum(volume, ball(5))
- skimage.filters.rank.modal(image, footprint, out=None, mask=None, shift_x=0, shift_y=0, shift_z=0)[source]#
Return local mode of an image.
The mode is the value that appears most often in the local histogram.
- Parameters:
- imagendarray of shape ([P,] M, N) and dtype (uint8 or uint16)
Input image.
- footprintndarray
The neighborhood expressed as an ndarray of 1’s and 0’s.
- outndarray of shape ([P,] M, N), same dtype as input
image If None, a new array is allocated.
- maskndarray of dtype (int or float), optional
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, shift_zint
Offset added to the footprint center point. Shift is bounded to the footprint sizes (center must be inside the given footprint).
- Returns:
- out([P,] M, N) ndarray, same dtype as
image Output image.
- out([P,] M, N) ndarray, same dtype as
Examples
>>> from _skimage2 import data >>> from _skimage2.morphology import disk, ball >>> from _skimage2.filters.rank import modal >>> import numpy as np >>> img = data.camera() >>> rng = np.random.default_rng() >>> volume = rng.integers(0, 255, size=(10,10,10), dtype=np.uint8) >>> out = modal(img, disk(5)) >>> out_vol = modal(volume, ball(5))
- skimage.filters.rank.noise_filter(image, footprint, out=None, mask=None, shift_x=0, shift_y=0, shift_z=0)[source]#
Noise feature.
- Parameters:
- imagendarray of shape ([P,] M, N) and dtype (uint8 or uint16)
Input image.
- footprintndarray
The neighborhood expressed as an ndarray of 1’s and 0’s.
- outndarray of shape ([P,] M, N), same dtype as input
image If None, a new array is allocated.
- maskndarray of dtype (int or float), optional
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, shift_zint
Offset added to the footprint center point. Shift is bounded to the footprint sizes (center must be inside the given footprint).
- Returns:
- outndarray of shape ([P,] M, N), same dtype as input
image Output image.
- outndarray of shape ([P,] M, N), same dtype as input
References
[1]N. Hashimoto et al. Referenceless image quality evaluation for whole slide imaging. J Pathol Inform 2012;3:9.
Examples
>>> from _skimage2 import data >>> from _skimage2.morphology import disk, ball >>> from _skimage2.filters.rank import noise_filter >>> import numpy as np >>> img = data.camera() >>> rng = np.random.default_rng() >>> volume = rng.integers(0, 255, size=(10,10,10), dtype=np.uint8) >>> out = noise_filter(img, disk(5)) >>> out_vol = noise_filter(volume, ball(5))
- skimage.filters.rank.otsu(image, footprint, out=None, mask=None, shift_x=0, shift_y=0, shift_z=0)[source]#
Local Otsu’s threshold value for each pixel.
- Parameters:
- imagendarray of shape ([P,] M, N) and dtype (uint8 or uint16)
Input image.
- footprintndarray
The neighborhood expressed as an ndarray of 1’s and 0’s.
- outndarray of shape ([P,] M, N), same dtype as input
image If None, a new array is allocated.
- maskndarray of dtype (int or float), optional
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, shift_zint
Offset added to the footprint center point. Shift is bounded to the footprint sizes (center must be inside the given footprint).
- Returns:
- outndarray of shape ([P,] M, N), same dtype as input
image Output image.
- outndarray of shape ([P,] M, N), same dtype as input
References
Examples
>>> from _skimage2 import data >>> from _skimage2.filters.rank import otsu >>> from _skimage2.morphology import disk, ball >>> import numpy as np >>> img = data.camera() >>> rng = np.random.default_rng() >>> volume = rng.integers(0, 255, size=(10,10,10), dtype=np.uint8) >>> local_otsu = otsu(img, disk(5)) >>> thresh_image = img >= local_otsu >>> local_otsu_vol = otsu(volume, ball(5)) >>> thresh_image_vol = volume >= local_otsu_vol
- skimage.filters.rank.percentile(image, footprint, out=None, mask=None, shift_x=0, shift_y=0, p0=0)[source]#
Return local percentile of an image.
Returns the value of the p0 lower percentile of the local grayvalue distribution.
Only grayvalues between percentiles [p0, p1] are considered in the filter.
- Parameters:
- image2-D array (uint8, uint16)
Input image.
- footprintndarray of shape (m, n)
The neighborhood expressed as a 2-D array of 1’s and 0’s.
- out2-D array, same dtype as input
image If None, a new array is allocated.
- maskndarray
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_yint
Offset added to the footprint center point. Shift is bounded to the footprint sizes (center must be inside the given footprint).
- p0float, optional, in interval [0, 1]
Set the percentile value.
- Returns:
- out2-D array, same dtype as input
image Output image.
- out2-D array, same dtype as input
- skimage.filters.rank.pop(image, footprint, out=None, mask=None, shift_x=0, shift_y=0, shift_z=0)[source]#
Return the local number (population) of pixels.
The number of pixels is defined as the number of pixels which are included in the footprint and the mask.
- Parameters:
- imagendarray of shape ([P,] M, N) and dtype (uint8 or uint16)
Input image.
- footprintndarray
The neighborhood expressed as an ndarray of 1’s and 0’s.
- outndarray of shape ([P,] M, N), same dtype as input
image If None, a new array is allocated.
- maskndarray of dtype (int or float), optional
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, shift_zint
Offset added to the footprint center point. Shift is bounded to the footprint sizes (center must be inside the given footprint).
- Returns:
- outndarray of shape ([P,] M, N), same dtype as input
image Output image.
- outndarray of shape ([P,] M, N), same dtype as input
Examples
>>> from _skimage2.morphology import footprint_rectangle # Need to add 3D example >>> import _skimage2.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, footprint_rectangle((3, 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)
- skimage.filters.rank.pop_bilateral(image, footprint, out=None, mask=None, shift_x=0, shift_y=0, 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 footprint and the mask. Additionally pixels must have a graylevel inside the interval [g-s0, g+s1] where g is the grayvalue of the center pixel.
- Parameters:
- image2-D array (uint8, uint16)
Input image.
- footprint2-D array
The neighborhood expressed as a 2-D array of 1’s and 0’s.
- out2-D array, same dtype as input
image If None, a new array is allocated.
- maskndarray
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_yint
Offset added to the footprint center point. Shift is bounded to the footprint sizes (center must be inside the given footprint).
- s0, s1int
Define the [s0, s1] interval around the grayvalue of the center pixel to be considered for computing the value.
- Returns:
- out2-D array, same dtype as input
image Output image.
- out2-D array, same dtype as input
Examples
>>> import numpy as np >>> from _skimage2.morphology import footprint_rectangle >>> import _skimage2.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, footprint_rectangle((3, 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)
- skimage.filters.rank.pop_percentile(image, footprint, out=None, mask=None, shift_x=0, shift_y=0, 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 footprint and the mask.
Only grayvalues between percentiles [p0, p1] are considered in the filter.
- Parameters:
- image2-D array (uint8, uint16)
Input image.
- footprintndarray of shape (m, n)
The neighborhood expressed as a 2-D array of 1’s and 0’s.
- out2-D array, same dtype as input
image If None, a new array is allocated.
- maskndarray
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_yint
Offset added to the footprint center point. Shift is bounded to the footprint sizes (center must be inside the given footprint).
- p0, p1float, optional, in interval [0, 1]
Define the [p0, p1] percentile interval to be considered for computing the value.
- Returns:
- out2-D array, same dtype as input
image Output image.
- out2-D array, same dtype as input
- skimage.filters.rank.subtract_mean(image, footprint, out=None, mask=None, shift_x=0, shift_y=0, shift_z=0)[source]#
Return image subtracted from its local mean.
- Parameters:
- imagendarray of shape ([P,] M, N) and dtype (uint8 or uint16)
Input image.
- footprintndarray
The neighborhood expressed as an ndarray of 1’s and 0’s.
- outndarray of shape ([P,] M, N), same dtype as input
image If None, a new array is allocated.
- maskndarray of dtype (int or float), optional
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, shift_zint
Offset added to the footprint center point. Shift is bounded to the footprint sizes (center must be inside the given footprint).
- Returns:
- out([P,] M, N) ndarray, same dtype as
image Output image.
- out([P,] M, N) ndarray, same dtype as
Notes
Subtracting the mean value may introduce underflow. To compensate this potential underflow, the obtained difference is downscaled by a factor of 2 and shifted by
n_bins / 2 - 1, the median value of the local histogram (n_bins = max(3, image.max()) +1for 16-bits images and 256 otherwise).Examples
>>> from _skimage2 import data >>> from _skimage2.morphology import disk, ball >>> from _skimage2.filters.rank import subtract_mean >>> import numpy as np >>> img = data.camera() >>> rng = np.random.default_rng() >>> volume = rng.integers(0, 255, size=(10,10,10), dtype=np.uint8) >>> out = subtract_mean(img, disk(5)) >>> out_vol = subtract_mean(volume, ball(5))
- skimage.filters.rank.subtract_mean_percentile(image, footprint, out=None, mask=None, shift_x=0, shift_y=0, p0=0, p1=1)[source]#
Return image subtracted from its local mean.
Only grayvalues between percentiles [p0, p1] are considered in the filter.
- Parameters:
- image2-D array (uint8, uint16)
Input image.
- footprintndarray of shape (m, n)
The neighborhood expressed as a 2-D array of 1’s and 0’s.
- out2-D array, same dtype as input
image If None, a new array is allocated.
- maskndarray
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_yint
Offset added to the footprint center point. Shift is bounded to the footprint sizes (center must be inside the given footprint).
- p0, p1float, optional, in interval [0, 1]
Define the [p0, p1] percentile interval to be considered for computing the value.
- Returns:
- out2-D array, same dtype as input
image Output image.
- out2-D array, same dtype as input
- skimage.filters.rank.sum(image, footprint, out=None, mask=None, shift_x=0, shift_y=0, shift_z=0)[source]#
Return the local sum of pixels.
Note that the sum may overflow depending on the data type of the input array.
- Parameters:
- imagendarray of shape ([P,] M, N) and dtype (uint8 or uint16)
Input image.
- footprintndarray
The neighborhood expressed as an ndarray of 1’s and 0’s.
- outndarray of shape ([P,] M, N), same dtype as input
image If None, a new array is allocated.
- maskndarray of dtype (int or float), optional
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, shift_zint
Offset added to the footprint center point. Shift is bounded to the footprint sizes (center must be inside the given footprint).
- Returns:
- outndarray of shape ([P,] M, N), same dtype as input
image Output image.
- outndarray of shape ([P,] M, N), same dtype as input
Examples
>>> from _skimage2.morphology import footprint_rectangle # Need to add 3D example >>> import _skimage2.filters.rank as rank # Cube seems to fail but >>> img = np.array([[0, 0, 0, 0, 0], # Ball can pass ... [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, footprint_rectangle((3, 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)
- skimage.filters.rank.sum_bilateral(image, footprint, out=None, mask=None, shift_x=0, shift_y=0, s0=10, s1=10)[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 footprint (structuring element).
Radiometric similarity is defined by the graylevel interval [g-s0, g+s1] where g is the current pixel graylevel.
Only pixels belonging to the footprint AND having a graylevel inside this interval are summed.
Note that the sum may overflow depending on the data type of the input array.
- Parameters:
- image2-D array (uint8, uint16)
Input image.
- footprint2-D array
The neighborhood expressed as a 2-D array of 1’s and 0’s.
- out2-D array, same dtype as input
image If None, a new array is allocated.
- maskndarray
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_yint
Offset added to the footprint center point. Shift is bounded to the footprint sizes (center must be inside the given footprint).
- s0, s1int
Define the [s0, s1] interval around the grayvalue of the center pixel to be considered for computing the value.
- Returns:
- out2-D array, same dtype as input
image Output image.
- out2-D array, same dtype as input
Examples
>>> import numpy as np >>> from _skimage2 import data >>> from _skimage2.morphology import disk >>> from _skimage2.filters.rank import sum_bilateral >>> img = data.camera().astype(np.uint16) >>> bilat_img = sum_bilateral(img, disk(10), s0=10, s1=10)
- skimage.filters.rank.sum_percentile(image, footprint, out=None, mask=None, shift_x=0, shift_y=0, p0=0, p1=1)[source]#
Return the local sum of pixels.
Only grayvalues 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:
- image2-D array (uint8, uint16)
Input image.
- footprintndarray of shape (m, n)
The neighborhood expressed as a 2-D array of 1’s and 0’s.
- out2-D array, same dtype as input
image If None, a new array is allocated.
- maskndarray
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_yint
Offset added to the footprint center point. Shift is bounded to the footprint sizes (center must be inside the given footprint).
- p0, p1float, optional, in interval [0, 1]
Define the [p0, p1] percentile interval to be considered for computing the value.
- Returns:
- out2-D array, same dtype as input
image Output image.
- out2-D array, same dtype as input
- skimage.filters.rank.threshold(image, footprint, out=None, mask=None, shift_x=0, shift_y=0, shift_z=0)[source]#
Local threshold of an image.
The resulting binary mask is True if the gray value of the center pixel is greater than the local mean.
- Parameters:
- imagendarray of shape ([P,] M, N) and dtype (uint8 or uint16)
Input image.
- footprintndarray
The neighborhood expressed as an ndarray of 1’s and 0’s.
- outndarray of shape ([P,] M, N), same dtype as input
image If None, a new array is allocated.
- maskndarray of dtype (int or float), optional
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, shift_zint
Offset added to the footprint center point. Shift is bounded to the footprint sizes (center must be inside the given footprint).
- Returns:
- outndarray of shape ([P,] M, N), same dtype as input
image Output image.
- outndarray of shape ([P,] M, N), same dtype as input
Examples
>>> from _skimage2.morphology import footprint_rectangle # Need to add 3D example >>> from _skimage2.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, footprint_rectangle((3, 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)
- skimage.filters.rank.threshold_percentile(image, footprint, out=None, mask=None, shift_x=0, shift_y=0, p0=0)[source]#
Local threshold of an image.
The resulting binary mask is True if the grayvalue of the center pixel is greater than the local mean.
Only grayvalues between percentiles [p0, p1] are considered in the filter.
- Parameters:
- image2-D array (uint8, uint16)
Input image.
- footprintndarray of shape (m, n)
The neighborhood expressed as a 2-D array of 1’s and 0’s.
- out2-D array, same dtype as input
image If None, a new array is allocated.
- maskndarray
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_yint
Offset added to the footprint center point. Shift is bounded to the footprint sizes (center must be inside the given footprint).
- p0float, optional, in interval [0, 1]
Set the percentile value.
- Returns:
- out2-D array, same dtype as input
image Output image.
- out2-D array, same dtype as input
- skimage.filters.rank.windowed_histogram(image, footprint, out=None, mask=None, shift_x=0, shift_y=0, n_bins=None)[source]#
Compute normalized sliding window histogram.
- Parameters:
- imagendarray of shape (H, W) and dtype (int or float)
Input image.
- footprintndarray of dtype (int or float)
The neighborhood expressed as a 2-D array of 1’s and 0’s.
- outndarray of shape (H, W, N) and dtype (int or float), optional
If None, a new array is allocated.
- maskndarray of dtype (int or float), optional
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_yint, optional
Offset added to the footprint center point. Shift is bounded to the footprint sizes (center must be inside the given footprint).
- n_binsint or None
The number of histogram bins. Defaults to
image.max() + 1if None is passed.
- Returns:
- outndarray of shape (H, W, N) and dtype float
Nisn_binsorimage.max() + 1if no value is passed ton_bins. Effectively, each pixel is a N-D feature vector that is the histogram. The sum of the elements in the feature vector is 1, unless no pixels in the window were covered by bothfootprintandmask, in which case all elements are 0.
Examples
>>> from _skimage2 import data >>> from _skimage2.filters.rank import windowed_histogram >>> from _skimage2.morphology import disk, ball >>> import numpy as np >>> img = data.camera() >>> rng = np.random.default_rng() >>> volume = rng.integers(0, 255, size=(10,10,10), dtype=np.uint8) >>> hist_img = windowed_histogram(img, disk(5))