{ } Raw JSON

bundles / skimage latest / skimage / filters / rank / generic / subtract_mean

function

skimage.filters.rank.generic:subtract_mean

source: /dev/scikit-image/src/skimage/filters/rank/generic.py :834

Signature

def   subtract_mean ( image footprint out = None mask = None shift_x = 0 shift_y = 0 shift_z = 0 )

Summary

Return image subtracted from its local mean.

Parameters

image : ndarray of shape ([P,] M, N) and dtype (uint8 or uint16)

Input image.

footprint : ndarray

The neighborhood expressed as an ndarray of 1's and 0's.

out : ndarray of shape ([P,] M, N), same dtype as input `image`

If None, a new array is allocated.

mask : ndarray 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_z : int

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.

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()) +1 for 16-bits images and 256 otherwise).

Examples

from skimage import data
from skimage.morphology import disk, ball
from skimage.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))

Aliases

  • skimage.filters.rank.subtract_mean