cuCIM API Reference#
Clara Submodules#
 class cucim.clara.CuImage#
 Attributes
associated_images
Returns a set of associated image names.
channel_names
A channel name list.
coord_sys
Coordinate frame in which the direction cosines are measured.
device
A device type.
dims
A string containing a list of dimensions being requested.
direction
Direction cosines (size is always 3x3).
dtype
The data type of the image.
is_loaded
True if image data is loaded & available.
metadata
A metadata object as dict.
ndim
The number of dimensions.
origin
Physical location of (0, 0, 0) (size is always 3).
path
Underlying file path for this object.
raw_metadata
A raw metadata string.
resolutions
Returns a dict that includes resolution information.
shape
A tuple of dimension sizes (in the order of dims)
typestr
The data type of the image in string format.
Methods
associated_image
(self[, name, device])Returns an associated image for the given name, as a CuImage object.
cache
([type])Get cache object.
close
(self)Closes the file handle.
profiler
(**kwargs)Get profiler object.
read_region
(self[, location, size, level, ...])Returns a subresolution image.
save
(self, arg0)Saves image data to the file path.
size
(self[, dim_order])Returns size as a tuple for the given dimension order.
spacing
(self[, dim_order])Returns physical size in tuple.
spacing_units
(self[, dim_order])Units for each spacing element (size is same with ndim).
 associated_image(self: cucim.clara._cucim.CuImage, name: str = '', device: cucim.clara._cucim.io.Device = cpu) object #
Returns an associated image for the given name, as a CuImage object.
 property associated_images#
Returns a set of associated image names.
Digital Pathology image usually has a label/thumbnail or a macro image(lowpower snapshot of the entire glass slide). Names of those images (such as ‘macro’ and ‘label’) are in associated_images.
 static cache(type: object = None, **kwargs) cucim.clara._cucim.cache.ImageCache #
Get cache object.
 property channel_names#
A channel name list.
 close(self: cucim.clara._cucim.CuImage) None #
Closes the file handle.
Once the file handle is closed, the image object (if loaded before) still exists but cannot read additional images from the file.
 property coord_sys#
Coordinate frame in which the direction cosines are measured.
Available Coordinate frame names are not finalized yet.
 property device#
A device type.
By default t is cpu (It will be changed since v0.19.0).
 property dims#
A string containing a list of dimensions being requested.
 The default is to return the six standard dims (‘STCZYX’) unless it is a DP multiresolution image.
[sites, time, channel(or wavelength), z, y, x]. S  Sites or multiposition locations.
NOTE: in OMETIFF’s metadata, dimension order would be specified as ‘XYZCTS’ (first one is fastiterating dimension).
 property direction#
Direction cosines (size is always 3x3).
 property dtype#
The data type of the image.
 property is_loaded#
True if image data is loaded & available.
 is_trace_enabled = False#
 property metadata#
A metadata object as dict.
It would be a dictionary(keyvalue pair) in general but can be a complex object (e.g., OMETIFF metadata).
 property ndim#
The number of dimensions.
 property origin#
Physical location of (0, 0, 0) (size is always 3).
 property path#
Underlying file path for this object.
 static profiler(**kwargs) cucim.clara._cucim.profiler.Profiler #
Get profiler object.
 property raw_metadata#
A raw metadata string.
 read_region(self: cucim.clara._cucim.CuImage, location: Iterable = (), size: List[int] = (), level: int = 0, num_workers: int = 0, batch_size: int = 1, drop_last: bool = False, prefetch_factor: int = 2, shuffle: bool = False, seed: int = 0, device: cucim.clara._cucim.io.Device = cpu, buf: object = None, shm_name: str = '', **kwargs) object #
Returns a subresolution image.
location and size’s dimension order is reverse of image’s dimension order.
Need to specify (X,Y) and (Width, Height) instead of (Y,X) and (Height, Width).
If location is not specified, location would be (0, 0) if Z=0. Otherwise, location would be (0, 0, 0)
Like OpenSlide, location is level0 based coordinates (using the level0 reference frame)
If size is not specified, size would be (width, height) of the image at the specified level.
<not supported yet> Additional parameters (S,T,C,Z) are similar to <https://allencellmodeling.github.io/aicsimageio/aicsimageio.html#aicsimageio.aics_image.AICSImage.get_image_data>
Do not yet support indices/ranges for (S,T,C,Z).
Default value for level, S, T, Z are zero.
Default value for C is 1 (whole channels)
<not supported yet> device could be one of the following strings or Device object: e.g., ‘cpu’, ‘cuda’, ‘cuda:0’ (use index 0), cucim.clara.io.Device(cucim.clara.io.CUDA,0).
<not supported yet> If buf is specified (buf’s type can be either numpy object that implements __array_interface__, or cupycompatible object that implements __cuda_array_interface__), the read image would be saved into buf object without creating CPU/GPU memory.
<not supported yet> If shm_name is specified, shared memory would be created and data would be read in the shared memory.
 property resolutions#
Returns a dict that includes resolution information.
level_count: The number of levels
level_dimensions: A tuple of dimension tuples (width, height)
level_downsamples: A tuple of downsample factors
level_tile_sizes: A tuple of tile size tuple (tile width, tile_height)
 save(self: cucim.clara._cucim.CuImage, arg0: str) None #
Saves image data to the file path.
Currently it supports only .ppm file format that can be viewed by eog command in Ubuntu.
 property shape#
A tuple of dimension sizes (in the order of dims)
 size(self: cucim.clara._cucim.CuImage, dim_order: str = '') List[int] #
Returns size as a tuple for the given dimension order.
 spacing(self: cucim.clara._cucim.CuImage, dim_order: str = '') List[float] #
Returns physical size in tuple.
If dim_order is specified, it returns phisical size for the dimensions. If a dimension given by the dim_order doesn’t exist, it returns 1.0 by default for the missing dimension.
 Args:
dim_order: A dimension string (e.g., ‘XYZ’)
 Returns:
A tuple with physical size for each dimension
 spacing_units(self: cucim.clara._cucim.CuImage, dim_order: str = '') List[str] #
Units for each spacing element (size is same with ndim).
 property typestr#
The data type of the image in string format.
The value can be converted to NumPy’s dtype using numpy.dtype(). (e.g., numpy.dtype(img.typestr)).
 class cucim.clara.DLDataType#
 Attributes
 property bits#
Number of bits, common choices are 8, 16, 32.
 property code#
Type code of base types.
 property lanes#
Number of lanes in the type, used for vector types.
 class cucim.clara.DLDataTypeCode#
Members:
DLInt
DLUInt
DLFloat
DLBfloat
 Attributes
name
name(self: handle) > str
 value
 DLBfloat = <DLDataTypeCode.DLBfloat: 4>#
 DLFloat = <DLDataTypeCode.DLFloat: 2>#
 DLInt = <DLDataTypeCode.DLInt: 0>#
 DLUInt = <DLDataTypeCode.DLUInt: 1>#
 property name#
 property value#
cache#
 class cucim.clara.cache.CacheType#
Members:
NoCache
PerProcess
SharedMemory
 Attributes
name
name(self: handle) > str
 value
 NoCache = <CacheType.NoCache: 0>#
 PerProcess = <CacheType.PerProcess: 1>#
 property name#
 property value#
 class cucim.clara.cache.ImageCache#
 Attributes
capacity
A capacity of list/hashmap.
config
Returns the dictionary of configuration.
free_memory
A cache memory size available in the cache memory.
hit_count
A cache hit count.
memory_capacity
A capacity of cache memory.
memory_size
A size of cache memory used.
miss_count
A cache miss count.
size
A size of list/hashmap.
type
A Cache type.
Methods
record
(self[, value])Records the cache statistics.
reserve
(self, memory_capacity, **kwargs)Reserves more memory if possible.
 property capacity#
A capacity of list/hashmap.
 property config#
Returns the dictionary of configuration.
 property free_memory#
A cache memory size available in the cache memory.
 property hit_count#
A cache hit count.
 property memory_capacity#
A capacity of cache memory.
 property memory_size#
A size of cache memory used.
 property miss_count#
A cache miss count.
 record(self: cucim.clara._cucim.cache.ImageCache, value: object = None) bool #
Records the cache statistics.
 reserve(self: cucim.clara._cucim.cache.ImageCache, memory_capacity: int, **kwargs) None #
Reserves more memory if possible.
 property size#
A size of list/hashmap.
 property type#
A Cache type.
 cucim.clara.cache.preferred_memory_capacity(img: object = None, image_size: Optional[List[int]] = None, tile_size: Optional[List[int]] = None, patch_size: Optional[List[int]] = None, bytes_per_pixel: int = 3) int #
Returns a good cache memory capacity value in MiB for the given conditions.
Please see how the value is calculated: https://godbolt.org/z/8vxnPfKM5
 Args:
img: A CuImage object that can provide image_size, tile_size, bytes_per_pixel information. If this argument is provided, only patch_size from the arguments is used for the calculation. image_size: A list of values that presents the image size (width, height). tile_size: A list of values that presents the tile size (width, height). The default value is (256, 256). patch_size: A list of values that presents the patch size (width, height). The default value is (256, 256). bytes_per_pixel: The number of bytes that each pixel in the 2D image takes place. The default value is 3.
 Returns:
int: The suggested memory capacity in MiB.
filesystem#
 class cucim.clara.filesystem.CuFileDriver#
Methods
close
(self)Closes opened file if not closed.
pread
(self, buf, count, file_offset[, ...])Reads up to count bytes from the file driver at offset file_offset (from the start of the file) into the buffer buf starting at offset buf_offset.
pwrite
(self, buf, count, file_offset[, ...])Reads up to count bytes from the file driver at offset file_offset (from the start of the file) into the buffer buf starting at offset buf_offset.
 close(self: cucim.clara._cucim.filesystem.CuFileDriver) bool #
Closes opened file if not closed.
 pread(self: cucim.clara._cucim.filesystem.CuFileDriver, buf: object, count: int, file_offset: int, buf_offset: int = 0) int #
Reads up to count bytes from the file driver at offset file_offset (from the start of the file) into the buffer buf starting at offset buf_offset. The file offset is not changed.
 Args:
buf: A buffer where read bytes are stored. Buffer can be either in CPU memory or (CUDA) GPU memory. count: The number of bytes to read. file_offset: An offset from the start of the file. buf_offset: An offset from the start of the buffer. Default value is 0.
 Returns:
The number of bytes read if succeed, 1 otherwise.
 pwrite(self: cucim.clara._cucim.filesystem.CuFileDriver, buf: object, count: int, file_offset: int, buf_offset: int = 0) int #
Reads up to count bytes from the file driver at offset file_offset (from the start of the file) into the buffer buf starting at offset buf_offset. The file offset is not changed.
 Args:
buf: A buffer where write bytes come from. Buffer can be either in CPU memory or (CUDA) GPU memory. count: The number of bytes to write. file_offset: An offset from the start of the file. buf_offset: An offset from the start of the buffer. Default value is 0.
 Returns:
The number of bytes written if succeed, 1 otherwise.
 cucim.clara.filesystem.close(arg0: cucim.clara._cucim.filesystem.CuFileDriver) bool #
Closes the given file driver.
 Args:
fd: An CuFileDriver object.
 Returns:
True if succeed, False otherwise.
 cucim.clara.filesystem.discard_page_cache(file_path: str) bool #
Discards a system (page) cache for the given file path.
 Args:
file_path: A file path to drop system cache.
 Returns:
True if succeed, False otherwise.
 cucim.clara.filesystem.open(file_path: str, flags: str, mode: int = 420) cucim.clara._cucim.filesystem.CuFileDriver #
Open file with specific flags and mode.
‘flags’ can be one of the following flag string:
“r”: os.O_RDONLY
“r+”: os.O_RDWR
“w”: os.O_RDWR  os.O_CREAT  os.O_TRUNC
“a”: os.O_RDWR  os.O_CREAT
In addition to above flags, the method append os.O_CLOEXEC and os.O_DIRECT by default.
The following is optional flags that can be added to above string:
‘p’: Use POSIX APIs only (first try to open with O_DIRECT). It does not use GDS.
‘n’: Do not add O_DIRECT flag.
‘m’: Use memorymapped file. This flag is supported only for the readonly file descriptor.
When ‘m’ is used, PROT_READ and MAP_SHARED are used for the parameter of mmap() function.
 Args:
file_path: A file path to open. flags: File flags in string. Default value is “r”. mode: A file mode. Default value is ‘0o644’.
 Returns:
An object of CuFileDriver.
 cucim.clara.filesystem.pread(fd: cucim.clara._cucim.filesystem.CuFileDriver, buf: object, count: int, file_offset: int, buf_offset: int = 0) int #
Reads up to count bytes from file driver fd at offset offset (from the start of the file) into the buffer buf starting at offset buf_offset. The file offset is not changed.
 Args:
fd: An object of CuFileDriver. buf: A buffer where read bytes are stored. Buffer can be either in CPU memory or (CUDA) GPU memory. count: The number of bytes to read. file_offset: An offset from the start of the file. buf_offset: An offset from the start of the buffer. Default value is 0.
 Returns:
The number of bytes read if succeed, 1 otherwise.
 cucim.clara.filesystem.pwrite(fd: cucim.clara._cucim.filesystem.CuFileDriver, buf: object, count: int, file_offset: int, buf_offset: int = 0) int #
Write up to count bytes from the buffer buf starting at offset buf_offset to the file driver fd at offset offset (from the start of the file). The file offset is not changed.
 Args:
fd: An object of CuFileDriver. buf: A buffer where write bytes come from. Buffer can be either in CPU memory or (CUDA) GPU memory. count: The number of bytes to write. file_offset: An offset from the start of the file. buf_offset: An offset from the start of the buffer. Default value is 0.
 Returns:
The number of bytes written if succeed, 1 otherwise.
io#
 class cucim.clara.io.Device#

Methods
parse_type
(arg0)Create DeviceType object from the device name string.
 property index#
Device index.
 static parse_type(arg0: str) cucim.clara._cucim.io.DeviceType #
Create DeviceType object from the device name string.
 property type#
Device type.
core Submodules#
color#
 cucim.core.operations.color.color_jitter(img: Any, brightness=0, contrast=0, saturation=0, hue=0)#
Applies color jitter by random sequential application of 4 operations (brightness, contrast, saturation, hue).
 Parameters
 imgchannel first, cupy.ndarray or numpy.ndarray
Input data of shape (C, H, W). Can also batch process input of shape (N, C, H, W). Can be a numpy.ndarray or cupy.ndarray.
 brightnessfloat or 2tuple of float, optional
Nonnegative factor to jitter the brightness by. When brightness is a scalar, scaling will be by a random value in range
[max(0, 1  brightness), (1 + brightness)]
. brightness can also be a 2tuple specifying the range for the random scaling factor. A value of 0 or (1, 1) will result in no change. contrastfloat or 2tuple of float, optional
Nonnegative factor to jitter the contrast by. When contrast is a scalar, scaling will be by a random value between
[max(0, 1  contrast), (1 + contrast)]
. contrast can also be a 2tuple specifying the range for the random scaling factor. A value of 0 or (1, 1) will result in no change. saturationfloat or 2tuple of float, optional
Nonnegative factor to jitter the saturation by. When saturation is a scalar, scaling will be by a random value between
[max(0, 1  saturation), (1 + saturation)]
. saturation can also be a 2tuple specifying the range for the random scaling factor. A value of 0 or (1, 1) will result in no change. huefloat or 2tuple of float, optional
Factor between [0.5, 0.5] to jitter hue by. When hue is a scalar, scaling will be by a random value between in the range
[hue, hue]
. hue can also be a 2tuple specifying the range. A value of 0 or (0, 0) will result in no change.
 Returns
 outcupy.ndarray or numpy.ndarray
Output data. Same dimensions and type as input.
 Raises
 ValueError
If ‘brightness’,’contrast’,’saturation’ or ‘hue’ is outside of allowed range
 TypeError
If input ‘img’ is not cupy.ndarray or numpy.ndarray
Examples
>>> import cucim.core.operations.color as ccl >>> # input is channel first 3d array >>> output_array = ccl.color_jitter(input_arr,.25,.75,.25,.04)
 cucim.core.operations.color.rand_color_jitter(img: Any, brightness=0, contrast=0, saturation=0, hue=0, prob: float = 0.1, whole_batch: bool = False)#
Randomly applies color jitter by random sequential application of 4 operations (brightness, contrast, saturation, hue).
 Parameters
 imgchannel first, cupy.ndarray or numpy.ndarray
Input data of shape (C, H, W). Can also batch process input of shape (N, C, H, W). Can be a numpy.ndarray or cupy.ndarray.
 brightnessfloat or 2tuple of float, optional
Nonnegative factor to jitter the brightness by. When brightness is a scalar, scaling will be by a random value in range
[max(0, 1  brightness), (1 + brightness)]
. brightness can also be a 2tuple specifying the range for the random scaling factor. A value of 0 or (1, 1) will result in no change. contrastfloat or 2tuple of float, optional
Nonnegative factor to jitter the contrast by. When contrast is a scalar, scaling will be by a random value between
[max(0, 1  contrast), (1 + contrast)]
. contrast can also be a 2tuple specifying the range for the random scaling factor. A value of 0 or (1, 1) will result in no change. saturationfloat or 2tuple of float, optional
Nonnegative factor to jitter the saturation by. When saturation is a scalar, scaling will be by a random value between
[max(0, 1  saturation), (1 + saturation)]
. saturation can also be a 2tuple specifying the range for the random scaling factor. A value of 0 or (1, 1) will result in no change. huefloat or 2tuple of float, optional
Factor between [0.5, 0.5] to jitter hue by. When hue is a scalar, scaling will be by a random value between in the range
[hue, hue]
. hue can also be a 2tuple specifying the range. A value of 0 or (0, 0) will result in no change. prob: probability of applying color jitter.
(Default 0.1, with 10% probability it returns a color jittered array)
 whole_batch: Flag to apply transform on whole batch.
If False, each image in the batch is randomly transformed It True, entire batch is transformed
 Returns
 ——
 outcupy.ndarray or numpy.ndarray
Output data. Same dimensions and type as input.
 Raises
 ValueError
If ‘brightness’,’contrast’,’saturation’ or ‘hue’ is outside of allowed range
 TypeError
If input ‘img’ is not cupy.ndarray or numpy.ndarray
Examples
>>> import cucim.core.operations.color as ccl >>> # input is channel first 3d array >>> output_array = ccl.rand_color_jitter(input_arr,.25,.75,.25,.04)
expose#
intensity#
 cucim.core.operations.intensity.normalize_data(img: Any, norm_constant: float, min_value: float, max_value: float, type: str = 'range') Any #
Apply intensity normalization to the input array. Normalize intensities to the range of [0, norm_constant].
 Parameters
 imgchannel first, cupy.ndarray or numpy.ndarray
Input data of shape (C, H, W). Can also batch process input of shape (N, C, H, W). Can be a numpy.ndarray or cupy.ndarray.
 norm_constant: float
Normalization range of the input data. [0, norm_constant]
 min_valuefloat
Minimum intensity value in input data.
 max_valuefloat
Maximum intensity value in input data.
 type{‘range’, ‘atan’}
Type of normalization.
 Returns
 outcupy.ndarray or numpy.ndarray
Output data. Same dimensions and type as input.
 Raises
 TypeError
If input ‘img’ is not cupy.ndarray or numpy.ndarray
 ValueError
If input original intensity min and max are same
 ValueError
If incorrect normalization type is invoked
Examples
>>> import cucim.core.operations.intensity as its >>> # input is channel first 3d array >>> output_array = its.normalize_data(input_arr, 10, 0 , 255)
 cucim.core.operations.intensity.rand_zoom(img: Any, min_zoom: Union[Sequence[float], float] = 0.9, max_zoom: Union[Sequence[float], float] = 1.1, prob: float = 0.1, whole_batch: bool = False)#
Randomly Calls zoom with random zoom factor
 Parameters
 imgchannel first, cupy.ndarray or numpy.ndarray
Input data of shape (C, H, W). Can also batch process input of shape (N, C, H, W). Can be a numpy.ndarray or cupy.ndarray.
 min_zoom: Min zoom factor. Can be float or sequence same size as image.
If a float, select a random factor from [min_zoom, max_zoom] then apply to all spatial dims to keep the original spatial shape ratio. If a sequence, min_zoom should contain one value for each spatial axis. If 2 values provided for 3D data, use the first value for both H & W dims to keep the same zoom ratio.
 max_zoom: Max zoom factor. Can be float or sequence same size as image.
If a float, select a random factor from [min_zoom, max_zoom] then apply to all spatial dims to keep the original spatial shape ratio. If a sequence, max_zoom should contain one value for each spatial axis. If 2 values provided for 3D data, use the first value for both H & W dims to keep the same zoom ratio.
 prob: Probability of zooming.
 whole_batch: Flag to apply transform on whole batch.
If False, each image in the batch is randomly transformed It True, entire batch is transformed randomly.
 Returns
 outcupy.ndarray or numpy.ndarray
Output data. Same dimensions and type as input.
 Raises
 TypeError
If input ‘img’ is not cupy.ndarray or numpy.ndarray
Examples
>>> import cucim.core.operations.intensity as its >>> # input is channel first 3d array >>> output_array = its.rand_zoom(input_arr)
 cucim.core.operations.intensity.scale_intensity_range(img: Any, b_max: float, b_min: float, a_max: float, a_min: float, clip: bool = False) Any #
Apply intensity scaling to the input array. Scaling from [a_min, a_max] to [b_min, b_max] with clip option.
 Parameters
 imgchannel first, cupy.ndarray or numpy.ndarray
Input data of shape (C, H, W). Can also batch process input of shape (N, C, H, W). Can be a numpy.ndarray or cupy.ndarray.
 b_minfloat
intensity target range min.
 b_maxfloat
intensity target range max.
 a_minfloat
intensity original range min.
 a_maxfloat
intensity original range max.
 clipfloat
whether to perform clip after scaling.
 Returns
 outcupy.ndarray or numpy.ndarray
Output data. Same dimensions and type as input.
 Raises
 TypeError
If input ‘img’ is not cupy.ndarray or numpy.ndarray
 ValueError
If input original intensity min and max are same
Examples
>>> import cucim.core.operations.intensity as its >>> # input is channel first 3d array >>> output_array = its.scale_intensity_range(input_arr, 0.0, 255.0, 1.0, 1.0, False)
 cucim.core.operations.intensity.zoom(img: Any, zoom_factor: Sequence[float])#
Zooms an ND image
 Parameters
 imgchannel first, cupy.ndarray or numpy.ndarray
Input data of shape (C, H, W). Can also batch process input of shape (N, C, H, W). Can be a numpy.ndarray or cupy.ndarray.
 zoom_factor: Sequence[float]
The zoom factor along the spatial axes. Zoom factor should contain one value for each spatial axis.
 Returns
 ——
 outcupy.ndarray or numpy.ndarray
Output data. Same dimensions and type as input.
 Raises
 TypeError
If input ‘img’ is not cupy.ndarray or numpy.ndarray
Examples
>>> import cucim.core.operations.intensity as its >>> # input is channel first 3d array >>> output_array = its.zoom(input_arr,[1.1,1.1])
spatial#
 cucim.core.operations.spatial.image_flip(img: Any, spatial_axis: ()) Any #
Shape preserving order reversal of elements in input array along the given spatial axis
 Parameters
 imgcupy.ndarray or numpy.ndarray
Input data. Can be numpy.ndarray or cupy.ndarray
 spatial_axistuple
spatial axis along which to flip over the input array
 Returns
 outcupy.ndarray or numpy.ndarray
Output data. Same dimensions and type as input.
 Raises
 TypeError
If input ‘img’ is not cupy.ndarray or numpy.ndarray
Examples
>>> import cucim.core.operations.spatial as spt >>> # input is channel first 3d array >>> output_array = spt.image_flip(input_arr, (1, 2))
 cucim.core.operations.spatial.image_rotate_90(img: Any, k: int, spatial_axis: ()) Any #
Rotate input array by 90 degress along the given axis
 Parameters
 imgcupy.ndarray or numpy.ndarray
Input data. Can be numpy.ndarray or cupy.ndarray
 kint
number of times to rotate
 spatial_axistuple
spatial axis along which to rotate the input array by 90 degrees
 Returns
 outcupy.ndarray or numpy.ndarray
Output data. Same dimensions and type as input.
 Raises
 TypeError
If input ‘img’ is not cupy.ndarray or numpy.ndarray
Examples
>>> import cucim.core.operations.spatial as spt >>> # input is channel first 3d array >>> output_array = spt.image_rotate_90(input_arr,1,(1,2))
 cucim.core.operations.spatial.rand_image_flip(img: Any, spatial_axis: (), prob: float = 0.1, whole_batch: bool = False) Any #
Randomly flips the image along axis.
 Parameters
 imgcupy.ndarray or numpy.ndarray
Input data. Can be numpy.ndarray or cupy.ndarray
 prob: Probability of flipping.
 spatial_axistuple
spatial axis along which to flip over the input array
 whole_batch: Flag to apply transform on whole batch.
If False, each image in the batch is randomly transformed It True, entire batch is transformed randomly.
 Returns
 outcupy.ndarray or numpy.ndarray
Output data. Same dimensions and type as input.
 Raises
 TypeError
If input ‘img’ is not cupy.ndarray or numpy.ndarray
Examples
>>> import cucim.core.operations.spatial as spt >>> # input is channel first 3d array >>> output_array = spt.rand_image_flip(input_arr,spatial_axis=(1,2))
 cucim.core.operations.spatial.rand_image_rotate_90(img: Any, spatial_axis: (), prob: float = 0.1, max_k: int = 3, whole_batch: bool = False) Any #
With probability prob, input arrays are rotated by 90 degrees in the plane specified by spatial_axis.
 Parameters
 imgcupy.ndarray or numpy.ndarray
Input data. Can be numpy.ndarray or cupy.ndarray
 prob: probability of rotating.
(Default 0.1, with 10% probability it returns a rotated array)
 max_k: number of rotations
will be sampled from np.random.randint(max_k) + 1, (Default 3).
 spatial_axistuple
spatial axis along which to rotate the input array by 90 degrees
 whole_batch: Flag to apply transform on whole batch.
If False, each image in the batch is randomly transformed It True, entire batch is transformed randomly.
 Returns
 outcupy.ndarray or numpy.ndarray
Output data. Same dimensions and type as input.
 Raises
 TypeError
If input ‘img’ is not cupy.ndarray or numpy.ndarray
Examples
>>> import cucim.core.operations.spatial as spt >>> # input is channel first 3d array >>> output_array = spt.rand_image_rotate_90(input_arr, spatial_axis=(1, 2))
skimage Submodules#
color#
 cucim.skimage.color.combine_stains(stains, conv_matrix, *, channel_axis= 1)#
Stain to RGB color space conversion.
 Parameters
 stains(…, 3, …) array_like
The image in stain color space. By default, the final dimension denotes channels.
 conv_matrix: ndarray
The stain separation matrix as described by G. Landini [1].
 channel_axisint, optional
This parameter indicates which axis of the array corresponds to channels.
 Returns
 out(…, 3, …) ndarray
The image in RGB format. Same dimensions as input.
 Raises
 ValueError
If stains is not at least 2D with shape (…, 3, …).
Notes
Stain combination matrices available in the
color
module and their respective colorspace:rgb_from_hed
: Hematoxylin + Eosin + DABrgb_from_hdx
: Hematoxylin + DABrgb_from_fgx
: Feulgen + Light Greenrgb_from_bex
: Giemsa stain : Methyl Blue + Eosinrgb_from_rbd
: FastRed + FastBlue + DABrgb_from_gdx
: Methyl Green + DABrgb_from_hax
: Hematoxylin + AECrgb_from_bro
: Blue matrix Anilline Blue + Red matrix Azocarmine + Orange matrix OrangeGrgb_from_bpx
: Methyl Blue + Ponceau Fuchsinrgb_from_ahx
: Alcian Blue + Hematoxylinrgb_from_hpx
: Hematoxylin + PAS
References
 1
 2
A. C. Ruifrok and D. A. Johnston, “Quantification of histochemical staining by color deconvolution,” Anal. Quant. Cytol. Histol., vol. 23, no. 4, pp. 291–299, Aug. 2001.
Examples
>>> import cupy as cp >>> from skimage import data >>> from cucim.skimage.color import (separate_stains, combine_stains, ... hdx_from_rgb, rgb_from_hdx) >>> ihc = cp.array(data.immunohistochemistry()) >>> ihc_hdx = separate_stains(ihc, hdx_from_rgb) >>> ihc_rgb = combine_stains(ihc_hdx, rgb_from_hdx)
 cucim.skimage.color.convert_colorspace(arr, fromspace, tospace, *, channel_axis= 1)#
Convert an image array to a new color space.
 Valid color spaces are:
‘RGB’, ‘HSV’, ‘RGB CIE’, ‘XYZ’, ‘YUV’, ‘YIQ’, ‘YPbPr’, ‘YCbCr’, ‘YDbDr’
 Parameters
 arr(…, 3, …) array_like
The image to convert. By default, the final dimension denotes channels.
 fromspacestr
The color space to convert from. Can be specified in lower case.
 tospacestr
The color space to convert to. Can be specified in lower case.
 channel_axisint, optional
This parameter indicates which axis of the array corresponds to channels.
 Returns
 out(…, 3, …) ndarray
The converted image. Same dimensions as input.
 Raises
 ValueError
If fromspace is not a valid color space
 ValueError
If tospace is not a valid color space
Notes
Conversion is performed through the “central” RGB color space, i.e. conversion from XYZ to HSV is implemented as
XYZ > RGB > HSV
instead of directly.Examples
>>> import cupy as cp >>> from skimage import data >>> img = cp.array(data.astronaut()) >>> img_hsv = convert_colorspace(img, 'RGB', 'HSV')
 cucim.skimage.color.deltaE_cie76(lab1, lab2, channel_axis= 1)#
Euclidean distance between two points in Lab color space
 Parameters
 lab1array_like
reference color (Lab colorspace)
 lab2array_like
comparison color (Lab colorspace)
 channel_axisint, optional
This parameter indicates which axis of the arrays corresponds to channels.
 Returns
 dEarray_like
distance between colors lab1 and lab2
References
 1
 2
A. R. Robertson, “The CIE 1976 colordifference formulae,” Color Res. Appl. 2, 711 (1977).
 cucim.skimage.color.deltaE_ciede2000(lab1, lab2, kL=1, kC=1, kH=1, *, channel_axis= 1)#
Color difference as given by the CIEDE 2000 standard.
CIEDE 2000 is a major revision of CIDE94. The perceptual calibration is largely based on experience with automotive paint on smooth surfaces.
 Parameters
 lab1array_like
reference color (Lab colorspace)
 lab2array_like
comparison color (Lab colorspace)
 kLfloat (range), optional
lightness scale factor, 1 for “acceptably close”; 2 for “imperceptible” see deltaE_cmc
 kCfloat (range), optional
chroma scale factor, usually 1
 kHfloat (range), optional
hue scale factor, usually 1
 channel_axisint, optional
This parameter indicates which axis of the arrays corresponds to channels.
 Returns
 deltaEarray_like
The distance between lab1 and lab2
Notes
CIEDE 2000 assumes parametric weighting factors for the lightness, chroma, and hue (kL, kC, kH respectively). These default to 1.
References
 1
 2
http://www.ece.rochester.edu/~gsharma/ciede2000/ciede2000noteCRNA.pdf DOI:10.1364/AO.33.008069
 3
M. Melgosa, J. Quesada, and E. Hita, “Uniformity of some recent color metrics tested with an accurate colordifference tolerance dataset,” Appl. Opt. 33, 80698077 (1994).
 cucim.skimage.color.deltaE_ciede94(lab1, lab2, kH=1, kC=1, kL=1, k1=0.045, k2=0.015, *, channel_axis= 1)#
Color difference according to CIEDE 94 standard
Accommodates perceptual nonuniformities through the use of application specific scale factors (kH, kC, kL, k1, and k2).
 Parameters
 lab1array_like
reference color (Lab colorspace)
 lab2array_like
comparison color (Lab colorspace)
 kHfloat, optional
Hue scale
 kCfloat, optional
Chroma scale
 kLfloat, optional
Lightness scale
 k1float, optional
first scale parameter
 k2float, optional
second scale parameter
 channel_axisint, optional
This parameter indicates which axis of the arrays corresponds to channels.
 Returns
 dEarray_like
color difference between lab1 and lab2
Notes
deltaE_ciede94 is not symmetric with respect to lab1 and lab2. CIEDE94 defines the scales for the lightness, hue, and chroma in terms of the first color. Consequently, the first color should be regarded as the “reference” color.
kL, k1, k2 depend on the application and default to the values suggested for graphic arts
Parameter
Graphic Arts
Textiles
kL
1.000
2.000
k1
0.045
0.048
k2
0.015
0.014
References
 cucim.skimage.color.deltaE_cmc(lab1, lab2, kL=1, kC=1, *, channel_axis= 1)#
Color difference from the CMC l:c standard.
This color difference was developed by the Colour Measurement Committee (CMC) of the Society of Dyers and Colourists (United Kingdom). It is intended for use in the textile industry.
The scale factors kL, kC set the weight given to differences in lightness and chroma relative to differences in hue. The usual values are
kL=2
,kC=1
for “acceptability” andkL=1
,kC=1
for “imperceptibility”. Colors withdE > 1
are “different” for the given scale factors. Parameters
 lab1array_like
reference color (Lab colorspace)
 lab2array_like
comparison color (Lab colorspace)
 channel_axisint, optional
This parameter indicates which axis of the arrays corresponds to channels.
 Returns
 dEarray_like
distance between colors lab1 and lab2
Notes
deltaE_cmc the defines the scales for the lightness, hue, and chroma in terms of the first color. Consequently
deltaE_cmc(lab1, lab2) != deltaE_cmc(lab2, lab1)
References
 1
 2
http://www.brucelindbloom.com/index.html?Eqn_DeltaE_CIE94.html
 3
F. J. J. Clarke, R. McDonald, and B. Rigg, “Modification to the JPC79 colourdifference formula,” J. Soc. Dyers Colour. 100, 128132 (1984).
 cucim.skimage.color.gray2rgb(image, *, channel_axis= 1)#
Create an RGB representation of a graylevel image.
 Parameters
 imagearray_like
Input image.
 channel_axisint, optional
This parameter indicates which axis of the output array will correspond to channels.
 Returns
 rgb(…, 3, …) ndarray
RGB image. A new dimension of length 3 is added to input image.
Notes
If the input is a 1dimensional image of shape
(M, )
, the output will be shape(M, 3)
.
 cucim.skimage.color.gray2rgba(image, alpha=None, *, channel_axis= 1)#
Create a RGBA representation of a graylevel image.
 Parameters
 imagearray_like
Input image.
 alphaarray_like, optional
Alpha channel of the output image. It may be a scalar or an array that can be broadcast to
image
. If not specified it is set to the maximum limit corresponding to theimage
dtype. channel_axisint, optional
This parameter indicates which axis of the output array will correspond to channels.
 Returns
 rgbandarray
RGBA image. A new dimension of length 4 is added to input image shape.
 cucim.skimage.color.hed2rgb(hed, *, channel_axis= 1)#
HaematoxylinEosinDAB (HED) to RGB color space conversion.
 Parameters
 hed(…, 3, …) array_like
The image in the HED color space. By default, the final dimension denotes channels.
 channel_axisint, optional
This parameter indicates which axis of the array corresponds to channels.
 Returns
 out(…, 3, …) ndarray
The image in RGB. Same dimensions as input.
 Raises
 ValueError
If hed is not at least 2D with shape (…, 3, …).
References
 1
A. C. Ruifrok and D. A. Johnston, “Quantification of histochemical staining by color deconvolution.,” Analytical and quantitative cytology and histology / the International Academy of Cytology [and] American Society of Cytology, vol. 23, no. 4, pp. 2919, Aug. 2001.
Examples
>>> import cupy as cp >>> from skimage import data >>> from cucim.skimage.color import rgb2hed, hed2rgb >>> ihc = cp.array(data.immunohistochemistry()) >>> ihc_hed = rgb2hed(ihc) >>> ihc_rgb = hed2rgb(ihc_hed)
 cucim.skimage.color.hsv2rgb(hsv, *, channel_axis= 1)#
HSV to RGB color space conversion.
 Parameters
 hsv(…, 3, …) array_like
The image in HSV format. By default, the final dimension denotes channels.
 channel_axisint, optional
This parameter indicates which axis of the array corresponds to channels.
 Returns
 out(…, 3, …) ndarray
The image in RGB format. Same dimensions as input.
 Raises
 ValueError
If hsv is not at least 2D with shape (…, 3, …).
Notes
Conversion between RGB and HSV color spaces results in some loss of precision, due to integer arithmetic and rounding [1].
References
Examples
>>> import cupy as cp >>> from skimage import data >>> img = cp.array(data.astronaut()) >>> img_hsv = rgb2hsv(img) >>> img_rgb = hsv2rgb(img_hsv)
 cucim.skimage.color.lab2lch(lab, *, channel_axis= 1)#
CIELAB to CIELCH color space conversion.
LCH is the cylindrical representation of the LAB (Cartesian) colorspace
 Parameters
 lab(…, 3, …) array_like
The ND image in CIELAB format. The last (
N+1
th) dimension must have at least 3 elements, corresponding to theL
,a
, andb
color channels. Subsequent elements are copied. channel_axisint, optional
This parameter indicates which axis of the array corresponds to channels.
 Returns
 out(…, 3, …) ndarray
The image in LCH format, in a ND array with same shape as input lab.
 Raises
 ValueError
If lch does not have at least 3 color channels (i.e. l, a, b).
Notes
The Hue is expressed as an angle between
(0, 2*pi)
Examples
>>> from skimage import data >>> from cucim.skimage.color import rgb2lab, lab2lch >>> img = cp.array(data.astronaut()) >>> img_lab = rgb2lab(img) >>> img_lch = lab2lch(img_lab)
 cucim.skimage.color.lab2rgb(lab, illuminant='D65', observer='2', *, channel_axis= 1)#
Lab to RGB color space conversion.
 Parameters
 lab(…, 3, …) array_like
The image in Lab format. By default, the final dimension denotes channels.
 illuminant{“A”, “B”, “C”, “D50”, “D55”, “D65”, “D75”, “E”}, optional
The name of the illuminant (the function is NOT case sensitive).
 observer{“2”, “10”, “R”}, optional
The aperture angle of the observer.
 channel_axisint, optional
This parameter indicates which axis of the array corresponds to channels.
 Returns
 out(…, 3, …) ndarray
The image in RGB format. Same dimensions as input.
 Raises
 ValueError
If lab is not at least 2D with shape (…, 3, …).
Notes
This function uses lab2xyz and xyz2rgb. By default Observer=”2”, Illuminant=”D65”. CIE XYZ tristimulus values x_ref=95.047, y_ref=100., z_ref=108.883. See function get_xyz_coords for a list of supported illuminants.
References
 cucim.skimage.color.lab2xyz(lab, illuminant='D65', observer='2', *, channel_axis= 1)#
CIELAB to XYZcolor space conversion.
 Parameters
 lab(…, 3, …) array_like
The image in Lab format. By default, the final dimension denotes channels.
 illuminant{“A”, “B”, “C”, “D50”, “D55”, “D65”, “D75”, “E”}, optional
The name of the illuminant (the function is NOT case sensitive).
 observer{“2”, “10”, “R”}, optional
The aperture angle of the observer.
 channel_axisint, optional
This parameter indicates which axis of the array corresponds to channels.
 Returns
 out(…, 3, …) ndarray
The image in XYZ format. Same dimensions as input.
 Raises
 ValueError
If lab is not at least 2D with shape (…, 3, …).
 ValueError
If either the illuminant or the observer angle are not supported or unknown.
 UserWarning
If any of the pixels are invalid (Z < 0).
Notes
By default Observer=”2”, Illuminant=”D65”. CIE XYZ tristimulus values x_ref = 95.047, y_ref = 100., z_ref = 108.883. See function ‘get_xyz_coords’ for a list of supported illuminants.
References
 cucim.skimage.color.label2rgb(label, image=None, colors=None, alpha=0.3, bg_label=0, bg_color=(0, 0, 0), image_alpha=1, kind='overlay', *, saturation=0, channel_axis= 1)#
Return an RGB image where colorcoded labels are painted over the image.
 Parameters
 labelndarray
Integer array of labels with the same shape as image.
 imagendarray, optional
Image used as underlay for labels. It should have the same shape as labels, optionally with an additional RGB (channels) axis. If image is an RGB image, it is converted to grayscale before coloring.
 colorslist, optional
List of colors. If the number of labels exceeds the number of colors, then the colors are cycled.
 alphafloat [0, 1], optional
Opacity of colorized labels. Ignored if image is None.
 bg_labelint, optional
Label that’s treated as the background. If bg_label is specified, bg_color is None, and kind is overlay, background is not painted by any colors.
 bg_colorstr or array, optional
Background color. Must be a name in color_dict or RGB float values between [0, 1].
 image_alphafloat [0, 1], optional
Opacity of the image.
 kindstring, one of {‘overlay’, ‘avg’}
The kind of color image desired. ‘overlay’ cycles over defined colors and overlays the colored labels over the original image. ‘avg’ replaces each labeled segment with its average color, for a stainedclass or pastel painting appearance.
 saturationfloat [0, 1], optional
Parameter to control the saturation applied to the original image between fully saturated (original RGB, saturation=1) and fully unsaturated (grayscale, saturation=0). Only applies when kind=’overlay’.
 channel_axisint, optional
This parameter indicates which axis of the output array will correspond to channels. If image is provided, this must also match the axis of image that corresponds to channels.
 Returns
 resultarray of float, shape (M, N, 3)
The result of blending a cycling colormap (colors) for each distinct value in label with the image, at a certain alpha value.
 cucim.skimage.color.lch2lab(lch, *, channel_axis= 1)#
CIELCH to CIELAB color space conversion.
LCH is the cylindrical representation of the LAB (Cartesian) colorspace
 Parameters
 lch(…, 3, …) array_like
The ND image in CIELCH format. The last (
N+1
th) dimension must have at least 3 elements, corresponding to theL
,a
, andb
color channels. Subsequent elements are copied. channel_axisint, optional
This parameter indicates which axis of the array corresponds to channels.
 Returns
 out(…, 3, …) ndarray
The image in LAB format, with same shape as input lch.
 Raises
 ValueError
If lch does not have at least 3 color channels (i.e. l, c, h).
Examples
>>> from skimage import data >>> from cucim.skimage.color import rgb2lab, lch2lab >>> img = cp.array(data.astronaut()) >>> img_lab = rgb2lab(img) >>> img_lch = lab2lch(img_lab) >>> img_lab2 = lch2lab(img_lch)
 cucim.skimage.color.luv2rgb(luv, *, channel_axis= 1)#
Luv to RGB color space conversion.
 Parameters
 luv(…, 3, …) array_like
The image in CIE Luv format. By default, the final dimension denotes channels.
 Returns
 out(…, 3, …) ndarray
The image in RGB format. Same dimensions as input.
 Raises
 ValueError
If luv is not at least 2D with shape (…, 3, …).
Notes
This function uses luv2xyz and xyz2rgb.
 cucim.skimage.color.luv2xyz(luv, illuminant='D65', observer='2', *, channel_axis= 1)#
CIELuv to XYZ color space conversion.
 Parameters
 luv(…, 3, …) array_like
The image in CIELuv format. By default, the final dimension denotes channels.
 illuminant{“A”, “B”, “C”, “D50”, “D55”, “D65”, “D75”, “E”}, optional
The name of the illuminant (the function is NOT case sensitive).
 observer{“2”, “10”, “R”}, optional
The aperture angle of the observer.
 channel_axisint, optional
This parameter indicates which axis of the array corresponds to channels.
 Returns
 out(…, 3, …) ndarray
The image in XYZ format. Same dimensions as input.
 Raises
 ValueError
If luv is not at least 2D with shape (…, 3, …).
 ValueError
If either the illuminant or the observer angle are not supported or unknown.
Notes
XYZ conversion weights use observer=2A. Reference whitepoint for D65 Illuminant, with XYZ tristimulus values of
(95.047, 100., 108.883)
. See function ‘get_xyz_coords’ for a list of supported illuminants.References
 cucim.skimage.color.rgb2gray(rgb, *, channel_axis= 1)#
Compute luminance of an RGB image.
 Parameters
 rgb(…, 3, …) array_like
The image in RGB format. By default, the final dimension denotes channels.
 Returns
 outndarray
The luminance image  an array which is the same size as the input array, but with the channel dimension removed.
 Raises
 ValueError
If rgb is not at least 2D with shape (…, 3, …).
Notes
The weights used in this conversion are calibrated for contemporary CRT phosphors:
Y = 0.2125 R + 0.7154 G + 0.0721 B
If there is an alpha channel present, it is ignored.
References
Examples
>>> import cupy as cp >>> from cucim.skimage.color import rgb2gray >>> from skimage import data >>> img = cp.array(data.astronaut()) >>> img_gray = rgb2gray(img)
 cucim.skimage.color.rgb2hed(rgb, *, channel_axis= 1)#
RGB to HaematoxylinEosinDAB (HED) color space conversion.
 Parameters
 rgb(…, 3, …) array_like
The image in RGB format. By default, the final dimension denotes channels.
 channel_axisint, optional
This parameter indicates which axis of the array corresponds to channels.
 Returns
 out(…, 3, …) ndarray
The image in HED format. Same dimensions as input.
 Raises
 ValueError
If rgb is not at least 2D with shape (…, 3, …).
References
 1
A. C. Ruifrok and D. A. Johnston, “Quantification of histochemical staining by color deconvolution.,” Analytical and quantitative cytology and histology / the International Academy of Cytology [and] American Society of Cytology, vol. 23, no. 4, pp. 2919, Aug. 2001.
Examples
>>> import cupy as cp >>> from skimage import data >>> from cucim.skimage.color import rgb2hed >>> ihc = cp.array(data.immunohistochemistry()) >>> ihc_hed = rgb2hed(ihc)
 cucim.skimage.color.rgb2hsv(rgb, *, channel_axis= 1)#
RGB to HSV color space conversion.
 Parameters
 rgb(…, 3, …) array_like
The image in RGB format. By default, the final dimension denotes channels.
 channel_axisint, optional
This parameter indicates which axis of the array corresponds to channels.
 Returns
 out(…, 3, …) ndarray
The image in HSV format. Same dimensions as input.
 Raises
 ValueError
If rgb is not at least 2D with shape (…, 3, …).
Notes
Conversion between RGB and HSV color spaces results in some loss of precision, due to integer arithmetic and rounding [1].
References
Examples
>>> import cupy as cp >>> from cucim.skimage import color >>> from skimage import data >>> img = cp.array(data.astronaut()) >>> img_hsv = color.rgb2hsv(img)
 cucim.skimage.color.rgb2lab(rgb, illuminant='D65', observer='2', *, channel_axis= 1)#
Conversion from the sRGB color space (IEC 6196621:1999) to the CIE Lab colorspace under the given illuminant and observer.
 Parameters
 rgb(…, 3, …) array_like
The image in RGB format. By default, the final dimension denotes channels.
 illuminant{“A”, “B”, “C”, “D50”, “D55”, “D65”, “D75”, “E”}, optional
The name of the illuminant (the function is NOT case sensitive).
 observer{“2”, “10”, “R”}, optional
The aperture angle of the observer.
 channel_axisint, optional
This parameter indicates which axis of the array corresponds to channels.
 Returns
 out(…, 3, …) ndarray
The image in Lab format. Same dimensions as input.
 Raises
 ValueError
If rgb is not at least 2D with shape (…, 3, …).
Notes
RGB is a devicedependent color space so, if you use this function, be sure that the image you are analyzing has been mapped to the sRGB color space.
This function uses rgb2xyz and xyz2lab. By default Observer=”2”, Illuminant=”D65”. CIE XYZ tristimulus values x_ref=95.047, y_ref=100., z_ref=108.883. See function get_xyz_coords for a list of supported illuminants.
References
 cucim.skimage.color.rgb2luv(rgb, *, channel_axis= 1)#
RGB to CIELuv color space conversion.
 Parameters
 rgb(…, 3, …) array_like
The image in RGB format. By default, the final dimension denotes channels.
 channel_axisint, optional
This parameter indicates which axis of the array corresponds to channels.
 Returns
 out(…, 3, …) ndarray
The image in CIE Luv format. Same dimensions as input.
 Raises
 ValueError
If rgb is not at least 2D with shape (…, 3, …).
Notes
This function uses rgb2xyz and xyz2luv.
References
 cucim.skimage.color.rgb2rgbcie(rgb, *, channel_axis= 1)#
RGB to RGB CIE color space conversion.
 Parameters
 rgb(…, 3, …) array_like
The image in RGB format. By default, the final dimension denotes channels.
 channel_axisint, optional
This parameter indicates which axis of the array corresponds to channels.
 Returns
 out(…, 3, …) ndarray
The image in RGB CIE format. Same dimensions as input.
 Raises
 ValueError
If rgb is not at least 2D with shape (…, 3, …).
References
Examples
>>> from skimage import data >>> from cucim.skimage.color import rgb2rgbcie >>> img = cp.array(data.astronaut()) >>> img_rgbcie = rgb2rgbcie(img)
 cucim.skimage.color.rgb2xyz(rgb, *, channel_axis= 1)#
RGB to XYZ color space conversion.
 Parameters
 rgb(…, 3, …) array_like
The image in RGB format. By default, the final dimension denotes channels.
 channel_axisint, optional
This parameter indicates which axis of the array corresponds to channels.
 Returns
 out(…, 3, …) ndarray
The image in XYZ format. Same dimensions as input.
 Raises
 ValueError
If rgb is not at least 2D with shape (…, 3, …).
Notes
The CIE XYZ color space is derived from the CIE RGB color space. Note however that this function converts from sRGB.
References
Examples
>>> import cupy as cp >>> from skimage import data >>> img = cp.array(data.astronaut()) >>> img_xyz = rgb2xyz(img)
 cucim.skimage.color.rgb2ycbcr(rgb, *, channel_axis= 1)#
RGB to YCbCr color space conversion.
 Parameters
 rgb(…, 3, …) array_like
The image in RGB format. By default, the final dimension denotes channels.
 channel_axisint, optional
This parameter indicates which axis of the array corresponds to channels.
 Returns
 out(…, 3, …) ndarray
The image in YCbCr format. Same dimensions as input.
 Raises
 ValueError
If rgb is not at least 2D with shape (…, 3, …).
Notes
Y is between 16 and 235. This is the color space commonly used by video codecs; it is sometimes incorrectly called “YUV”.
References
 cucim.skimage.color.rgb2ydbdr(rgb, *, channel_axis= 1)#
RGB to YDbDr color space conversion.
 Parameters
 rgb(…, 3, …) array_like
The image in RGB format. By default, the final dimension denotes channels.
 channel_axisint, optional
This parameter indicates which axis of the array corresponds to channels.
 Returns
 out(…, 3, …) ndarray
The image in YDbDr format. Same dimensions as input.
 Raises
 ValueError
If rgb is not at least 2D with shape (…, 3, …).
Notes
This is the color space commonly used by video codecs. It is also the reversible color transform in JPEG2000.
References
 cucim.skimage.color.rgb2yiq(rgb, *, channel_axis= 1)#
RGB to YIQ color space conversion.
 Parameters
 rgb(…, 3, …) array_like
The image in RGB format. By default, the final dimension denotes channels.
 channel_axisint, optional
This parameter indicates which axis of the array corresponds to channels.
 Returns
 out(…, 3, …) ndarray
The image in YIQ format. Same dimensions as input.
 Raises
 ValueError
If rgb is not at least 2D with shape (…, 3, …).
 cucim.skimage.color.rgb2ypbpr(rgb, *, channel_axis= 1)#
RGB to YPbPr color space conversion.
 Parameters
 rgb(…, 3, …) array_like
The image in RGB format. By default, the final dimension denotes channels.
 channel_axisint, optional
This parameter indicates which axis of the array corresponds to channels.
 Returns
 out(…, 3, …) ndarray
The image in YPbPr format. Same dimensions as input.
 Raises
 ValueError
If rgb is not at least 2D with shape (…, 3, …).
References
 cucim.skimage.color.rgb2yuv(rgb, *, channel_axis= 1)#
RGB to YUV color space conversion.
 Parameters
 rgb(…, 3, …) array_like
The image in RGB format. By default, the final dimension denotes channels.
 channel_axisint, optional
This parameter indicates which axis of the array corresponds to channels.
 Returns
 out(…, 3, …) ndarray
The image in YUV format. Same dimensions as input.
 Raises
 ValueError
If rgb is not at least 2D with shape (…, 3, …).
Notes
Y is between 0 and 1. Use YCbCr instead of YUV for the color space commonly used by video codecs, where Y ranges from 16 to 235.
References
 cucim.skimage.color.rgba2rgb(rgba, background=(1, 1, 1), *, channel_axis= 1)#
RGBA to RGB conversion using alpha blending [1].
 Parameters
 rgba(…, 4, …) array_like
The image in RGBA format. By default, the final dimension denotes channels.
 backgroundarray_like
The color of the background to blend the image with (3 floats between 0 to 1  the RGB value of the background).
 channel_axisint, optional
This parameter indicates which axis of the array corresponds to channels.
 Returns
 out(…, 3, …) ndarray
The image in RGB format. Same dimensions as input.
 Raises
 ValueError
If rgba is not at least 2D with shape (…, 4, …).
References
Examples
>>> import cupy as cp >>> from cucim.skimage import color >>> from skimage import data >>> img_rgba = cp.array(data.logo()) >>> img_rgb = color.rgba2rgb(img_rgba)
 cucim.skimage.color.rgbcie2rgb(rgbcie, *, channel_axis= 1)#
RGB CIE to RGB color space conversion.
 Parameters
 rgbcie(…, 3, …) array_like
The image in RGB CIE format. By default, the final dimension denotes channels.
 channel_axisint, optional
This parameter indicates which axis of the array corresponds to channels.
 Returns
 out(…, 3, …) ndarray
The image in RGB format. Same dimensions as input.
 Raises
 ValueError
If rgbcie is not at least 2D with shape (…, 3, …).
References
Examples
>>> from skimage import data >>> from cucim.skimage.color import rgb2rgbcie, rgbcie2rgb >>> img = cp.array(data.astronaut()) >>> img_rgbcie = rgb2rgbcie(img) >>> img_rgb = rgbcie2rgb(img_rgbcie)
 cucim.skimage.color.separate_stains(rgb, conv_matrix, *, channel_axis= 1)#
RGB to stain color space conversion.
 Parameters
 rgb(…, 3, …) array_like
The image in RGB format. By default, the final dimension denotes channels.
 conv_matrix: ndarray
The stain separation matrix as described by G. Landini [1].
 channel_axisint, optional
This parameter indicates which axis of the array corresponds to channels.
 Returns
 out(…, 3, …) ndarray
The image in stain color space. Same dimensions as input.
 Raises
 ValueError
If rgb is not at least 2D with shape (…, 3, …).
Notes
Stain separation matrices available in the
color
module and their respective colorspace:hed_from_rgb
: Hematoxylin + Eosin + DABhdx_from_rgb
: Hematoxylin + DABfgx_from_rgb
: Feulgen + Light Greenbex_from_rgb
: Giemsa stain : Methyl Blue + Eosinrbd_from_rgb
: FastRed + FastBlue + DABgdx_from_rgb
: Methyl Green + DABhax_from_rgb
: Hematoxylin + AECbro_from_rgb
: Blue matrix Anilline Blue + Red matrix Azocarmine + Orange matrix OrangeGbpx_from_rgb
: Methyl Blue + Ponceau Fuchsinahx_from_rgb
: Alcian Blue + Hematoxylinhpx_from_rgb
: Hematoxylin + PAS
This implementation borrows some ideas from DIPlib [2], e.g. the compensation using a small value to avoid log artifacts when calculating the BeerLambert law.
References
 1
 2
 3
A. C. Ruifrok and D. A. Johnston, “Quantification of histochemical staining by color deconvolution,” Anal. Quant. Cytol. Histol., vol. 23, no. 4, pp. 291–299, Aug. 2001.
Examples
>>> import cupy as cp >>> from skimage import data >>> from cucim.skimage.color import separate_stains, hdx_from_rgb >>> ihc = cp.array(data.immunohistochemistry()) >>> ihc_hdx = separate_stains(ihc, hdx_from_rgb)
 cucim.skimage.color.xyz2lab(xyz, illuminant='D65', observer='2', *, channel_axis= 1)#
XYZ to CIELAB color space conversion.
 Parameters
 xyz(…, 3, …) array_like
The image in XYZ format. By default, the final dimension denotes channels.
 illuminant{“A”, “B”, “C”, “D50”, “D55”, “D65”, “D75”, “E”}, optional
The name of the illuminant (the function is NOT case sensitive).
 observer{“2”, “10”, “R”}, optional
One of: 2degree observer, 10degree observer, or ‘R’ observer as in R function grDevices::convertColor.
 channel_axisint, optional
This parameter indicates which axis of the array corresponds to channels.
 Returns
 out(…, 3, …) ndarray
The image in CIELAB format. Same dimensions as input.
 Raises
 ValueError
If xyz is not at least 2D with shape (…, 3, …).
 ValueError
If either the illuminant or the observer angle is unsupported or unknown.
Notes
By default Observer=”2”, Illuminant=”D65”. CIE XYZ tristimulus values x_ref=95.047, y_ref=100., z_ref=108.883. See function get_xyz_coords for a list of supported illuminants.
References
Examples
>>> import cupy as cp >>> from skimage import data >>> from cucim.skimage.color import rgb2xyz, xyz2lab >>> img = cp.array(data.astronaut()) >>> img_xyz = rgb2xyz(img) >>> img_lab = xyz2lab(img_xyz)
 cucim.skimage.color.xyz2luv(xyz, illuminant='D65', observer='2', *, channel_axis= 1)#
XYZ to CIELuv color space conversion.
 Parameters
 xyz(…, 3, …) array_like
The image in XYZ format. By default, the final dimension denotes channels.
 illuminant{“A”, “B”, “C”, “D50”, “D55”, “D65”, “D75”, “E”}, optional
The name of the illuminant (the function is NOT case sensitive).
 observer{“2”, “10”, “R”}, optional
The aperture angle of the observer.
 channel_axisint, optional
This parameter indicates which axis of the array corresponds to channels.
 Returns
 out(…, 3, …) ndarray
The image in CIELuv format. Same dimensions as input.
 Raises
 ValueError
If xyz is not at least 2D with shape (…, 3, …).
 ValueError
If either the illuminant or the observer angle are not supported or unknown.
Notes
By default XYZ conversion weights use observer=2A. Reference whitepoint for D65 Illuminant, with XYZ tristimulus values of
(95.047, 100., 108.883)
. See function ‘get_xyz_coords’ for a list of supported illuminants.References
Examples
>>> import cupy as cp >>> from skimage import data >>> from cucim.skimage.color import rgb2xyz, xyz2luv >>> img = cp.array(data.astronaut()) >>> img_xyz = rgb2xyz(img) >>> img_luv = xyz2luv(img_xyz)
 cucim.skimage.color.xyz2rgb(xyz, *, channel_axis= 1)#
XYZ to RGB color space conversion.
 Parameters
 xyz(…, 3, …) array_like
The image in XYZ format. By default, the final dimension denotes channels.
 channel_axisint, optional
This parameter indicates which axis of the array corresponds to channels.
 Returns
 out(…, 3, …) ndarray
The image in RGB format. Same dimensions as input.
 Raises
 ValueError
If xyz is not at least 2D with shape (…, 3, …).
Notes
The CIE XYZ color space is derived from the CIE RGB color space. Note however that this function converts to sRGB.
References
Examples
>>> from skimage import data >>> from cucim.skimage.color import rgb2xyz, xyz2rgb >>> img = cp.array(data.astronaut()) >>> img_xyz = rgb2xyz(img) >>> img_rgb = xyz2rgb(img_xyz)
 cucim.skimage.color.ycbcr2rgb(ycbcr, *, channel_axis= 1)#
YCbCr to RGB color space conversion.
 Parameters
 ycbcr(…, 3, …) array_like
The image in YCbCr format. By default, the final dimension denotes channels.
 channel_axisint, optional
This parameter indicates which axis of the array corresponds to channels.
 Returns
 out(…, 3, …) ndarray
The image in RGB format. Same dimensions as input.
 Raises
 ValueError
If ycbcr is not at least 2D with shape (…, 3, …).
Notes
Y is between 16 and 235. This is the color space commonly used by video codecs; it is sometimes incorrectly called “YUV”.
References
 cucim.skimage.color.ydbdr2rgb(ydbdr, *, channel_axis= 1)#
YDbDr to RGB color space conversion.
 Parameters
 ydbdr(…, 3, …) array_like
The image in YDbDr format. By default, the final dimension denotes channels.
 channel_axisint, optional
This parameter indicates which axis of the array corresponds to channels.
 Returns
 out(…, 3, …) ndarray
The image in RGB format. Same dimensions as input.
 Raises
 ValueError
If ydbdr is not at least 2D with shape (…, 3, …).
Notes
This is the color space commonly used by video codecs, also called the reversible color transform in JPEG2000.
References
 cucim.skimage.color.yiq2rgb(yiq, *, channel_axis= 1)#
YIQ to RGB color space conversion.
 Parameters
 yiq(…, 3, …) array_like
The image in YIQ format. By default, the final dimension denotes channels.
 channel_axisint, optional
This parameter indicates which axis of the array corresponds to channels.
 Returns
 out(…, 3, …) ndarray
The image in RGB format. Same dimensions as input.
 Raises
 ValueError
If yiq is not at least 2D with shape (…, 3, …).
 cucim.skimage.color.ypbpr2rgb(ypbpr, *, channel_axis= 1)#
YPbPr to RGB color space conversion.
 Parameters
 ypbpr(…, 3, …) array_like
The image in YPbPr format. By default, the final dimension denotes channels.
 channel_axisint, optional
This parameter indicates which axis of the array corresponds to channels.
 Returns
 out(…, 3) ndarray
The image in RGB format. Same dimensions as input.
 Raises
 ValueError
If ypbpr is not at least 2D with shape (…, 3).
References
 cucim.skimage.color.yuv2rgb(yuv, *, channel_axis= 1)#
YUV to RGB color space conversion.
 Parameters
 yuv(…, 3, …) array_like
The image in YUV format. By default, the final dimension denotes channels.
 Returns
 out(…, 3, …) ndarray
The image in RGB format. Same dimensions as input.
 Raises
 ValueError
If yuv is not at least 2D with shape (…, 3, …).
References
data#
 cucim.skimage.data.binary_blobs(length=512, blob_size_fraction=0.1, n_dim=2, volume_fraction=0.5, seed=None)#
Generate synthetic binary image with several rounded bloblike objects.
 Parameters
 lengthint, optional
Linear size of output image.
 blob_size_fractionfloat, optional
Typical linear size of blob, as a fraction of
length
, should be smaller than 1. n_dimint, optional
Number of dimensions of output image.
 volume_fractionfloat, default 0.5
Fraction of image pixels covered by the blobs (where the output is 1). Should be in [0, 1].
 seed{None, int, cupy.random.Generator}, optional
If seed is None the cupy.random.Generator singleton is used. If seed is an int, a new
Generator
instance is used, seeded with seed. If seed is already aGenerator
instance then that instance is used.
 Returns
 blobsndarray of bools
Output binary image
Notes
Warning: CuPy does not give identical randomly generated numbers as NumPy, so using a specific seed here will not give an identical pattern to the scikitimage implementation.
The behavior for a given random seed may also change across CuPy major versions. See: https://docs.cupy.dev/en/stable/reference/random.html
Examples
>>> from cucim.skimage import data >>> # tiny size (5, 5) >>> blobs = data.binary_blobs(length=5, blob_size_fraction=0.2, seed=1) >>> # larger size >>> blobs = data.binary_blobs(length=256, blob_size_fraction=0.1) >>> # Finer structures >>> blobs = data.binary_blobs(length=256, blob_size_fraction=0.05) >>> # Blobs cover a smaller volume fraction of the image >>> blobs = data.binary_blobs(length=256, volume_fraction=0.3)
exposure#
 cucim.skimage.exposure.adjust_gamma(image, gamma=1, gain=1)#
Performs Gamma Correction on the input image.
Also known as Power Law Transform. This function transforms the input image pixelwise according to the equation
O = I**gamma
after scaling each pixel to the range 0 to 1. Parameters
 imagendarray
Input image.
 gammafloat, optional
Non negative real number. Default value is 1.
 gainfloat, optional
The constant multiplier. Default value is 1.
 Returns
 outndarray
Gamma corrected output image.
See also
Notes
For gamma greater than 1, the histogram will shift towards left and the output image will be darker than the input image.
For gamma less than 1, the histogram will shift towards right and the output image will be brighter than the input image.
References
Examples
>>> from skimage import data >>> from cucim.skimage import exposure, img_as_float >>> image = img_as_float(cp.array(data.moon())) >>> gamma_corrected = exposure.adjust_gamma(image, 2) >>> # Output is darker for gamma > 1 >>> image.mean() > gamma_corrected.mean() array(True)
 cucim.skimage.exposure.adjust_log(image, gain=1, inv=False)#
Performs Logarithmic correction on the input image.
This function transforms the input image pixelwise according to the equation
O = gain*log(1 + I)
after scaling each pixel to the range 0 to 1.For inverse logarithmic correction, the equation is
O = gain*(2**I  1)
. Parameters
 imagendarray
Input image.
 gainfloat, optional
The constant multiplier. Default value is 1.
 invfloat, optional
If True, it performs inverse logarithmic correction, else correction will be logarithmic. Defaults to False.
 Returns
 outndarray
Logarithm corrected output image.
See also
References
 cucim.skimage.exposure.adjust_sigmoid(image, cutoff=0.5, gain=10, inv=False)#
Performs Sigmoid Correction on the input image.
Also known as Contrast Adjustment. This function transforms the input image pixelwise according to the equation
O = 1/(1 + exp*(gain*(cutoff  I)))
after scaling each pixel to the range 0 to 1. Parameters
 imagendarray
Input image.
 cutofffloat, optional
Cutoff of the sigmoid function that shifts the characteristic curve in horizontal direction. Default value is 0.5.
 gainfloat, optional
The constant multiplier in exponential’s power of sigmoid function. Default value is 10.
 invbool, optional
If True, returns the negative sigmoid correction. Defaults to False.
 Returns
 outndarray
Sigmoid corrected output image.
See also
References
 1
Gustav J. Braun, “Image Lightness Rescaling Using Sigmoidal Contrast Enhancement Functions”, http://markfairchild.org/PDFs/PAP07.pdf
 cucim.skimage.exposure.cumulative_distribution(image, nbins=256)#
Return cumulative distribution function (cdf) for the given image.
 Parameters
 imagearray
Image array.
 nbinsint, optional
Number of bins for image histogram.
 Returns
 img_cdfarray
Values of cumulative distribution function.
 bin_centersarray
Centers of bins.
See also
References
Examples
>>> import cupy as cp >>> from skimage import data >>> from cucim.skimage import exposure, img_as_float >>> image = img_as_float(cp.array(data.camera())) >>> hi = exposure.histogram(image) >>> cdf = exposure.cumulative_distribution(image) >>> cp.alltrue(cdf[0] == cp.cumsum(hi[0])/float(image.size)) array(True)
 cucim.skimage.exposure.equalize_adapthist(image, kernel_size=None, clip_limit=0.01, nbins=256)#
Contrast Limited Adaptive Histogram Equalization (CLAHE).
An algorithm for local contrast enhancement, that uses histograms computed over different tile regions of the image. Local details can therefore be enhanced even in regions that are darker or lighter than most of the image.
 Parameters
 image(N1, …,NN[, C]) ndarray
Input image.
 kernel_sizeint or array_like, optional
Defines the shape of contextual regions used in the algorithm. If iterable is passed, it must have the same number of elements as
image.ndim
(without color channel). If integer, it is broadcasted to each image dimension. By default,kernel_size
is 1/8 ofimage
height by 1/8 of its width. clip_limitfloat, optional
Clipping limit, normalized between 0 and 1 (higher values give more contrast).
 nbinsint, optional
Number of gray bins for histogram (“data range”).
 Returns
 out(N1, …,NN[, C]) ndarray
Equalized image with float64 dtype.
See also
Notes
 For color images, the following steps are performed:
The image is converted to HSV color space
The CLAHE algorithm is run on the V (Value) channel
The image is converted back to RGB space and returned
For RGBA images, the original alpha channel is removed.
Changed in version 0.17: The values returned by this function are slightly shifted upwards because of an internal change in rounding behavior.
References
 cucim.skimage.exposure.equalize_hist(image, nbins=256, mask=None)#
Return image after histogram equalization.
 Parameters
 imagearray
Image array.
 nbinsint, optional
Number of bins for image histogram. Note: this argument is ignored for integer images, for which each integer is its own bin.
 mask: ndarray of bools or 0s and 1s, optional
Array of same shape as image. Only points at which mask == True are used for the equalization, which is applied to the whole image.
 Returns
 outfloat array
Image array after histogram equalization.
Notes
This function is adapted from [1] with the author’s permission.
References
 cucim.skimage.exposure.histogram(image, nbins=256, source_range='image', normalize=False, *, channel_axis=None)#
Return histogram of image.
Unlike numpy.histogram, this function returns the centers of bins and does not rebin integer arrays. For integer arrays, each integer value has its own bin, which improves speed and intensityresolution.
If channel_axis is not set, the histogram is computed on the flattened image. For color or multichannel images, set
channel_axis
to use a common binning for all channels. Alternatively, one may apply the function separately on each channel to obtain a histogram for each color channel with separate binning. Parameters
 imagearray
Input image.
 nbinsint, optional
Number of bins used to calculate histogram. This value is ignored for integer arrays.
 source_rangestring, optional
‘image’ (default) determines the range from the input image. ‘dtype’ determines the range from the expected range of the images of that data type.
 normalizebool, optional
If True, normalize the histogram by the sum of its values.
 channel_axisint or None, optional
If None, the image is assumed to be a grayscale (single channel) image. Otherwise, this parameter indicates which axis of the array corresponds to channels.
 Returns
 histarray
The values of the histogram. When
channel_axis
is not None, hist will be a 2D array where the first axis corresponds to channels. bin_centersarray
The values at the center of the bins.
See also
Examples
>>> import cupy as cp >>> from skimage import data >>> from cucim.skimage import exposure, img_as_float >>> image = img_as_float(cp.array(data.camera())) >>> cp.histogram(image, bins=2) (array([ 93585, 168559]), array([0. , 0.5, 1. ])) >>> exposure.histogram(image, nbins=2) (array([ 93585, 168559]), array([0.25, 0.75]))
 cucim.skimage.exposure.is_low_contrast(image, fraction_threshold=0.05, lower_percentile=1, upper_percentile=99, method='linear')#
Determine if an image is low contrast.
 Parameters
 imagearraylike
The image under test.
 fraction_thresholdfloat, optional
The low contrast fraction threshold. An image is considered low contrast when its range of brightness spans less than this fraction of its data type’s full range. [1]
 lower_percentilefloat, optional
Disregard values below this percentile when computing image contrast.
 upper_percentilefloat, optional
Disregard values above this percentile when computing image contrast.
 methodstr, optional
The contrast determination method. Right now the only available option is “linear”.
 Returns
 outbool
True when the image is determined to be low contrast.
Notes
For boolean images, this function returns False only if all values are the same (the method, threshold, and percentile arguments are ignored).
References
Examples
>>> import cupy as cp >>> image = cp.linspace(0, 0.04, 100) >>> is_low_contrast(image) array(True) >>> image[1] = 1 >>> is_low_contrast(image) array(True) >>> is_low_contrast(image, upper_percentile=100) array(False)
 cucim.skimage.exposure.match_histograms(image, reference, *, channel_axis=None, multichannel=False)#
Adjust an image so that its cumulative histogram matches that of another.
The adjustment is applied separately for each channel.
 Parameters
 imagendarray
Input image. Can be grayscale or in color.
 referencendarray
Image to match histogram of. Must have the same number of channels as image.
 channel_axisint or None, optional
If None, the image is assumed to be a grayscale (single channel) image. Otherwise, this parameter indicates which axis of the array corresponds to channels.
 multichannelbool, optional
Apply the matching separately for each channel. This argument is deprecated: specify channel_axis instead.
 Returns
 matchedndarray
Transformed input image.
 Other Parameters
 multichannelDEPRECATED
Deprecated in favor of channel_axis.
Deprecated since version 0.19.
 Raises
 ValueError
Thrown when the number of channels in the input image and the reference differ.
References
 cucim.skimage.exposure.rescale_intensity(image, in_range='image', out_range='dtype')#
Return image after stretching or shrinking its intensity levels.
The desired intensity range of the input and output, in_range and out_range respectively, are used to stretch or shrink the intensity range of the input image. See examples below.
 Parameters
 imagearray
Image array.
 in_range, out_rangestr or 2tuple, optional
Min and max intensity values of input and output image. The possible values for this parameter are enumerated below.
 ‘image’
Use image min/max as the intensity range.
 ‘dtype’
Use min/max of the image’s dtype as the intensity range.
 dtypename
Use intensity range based on desired dtype. Must be valid key in DTYPE_RANGE.
 2tuple
Use range_values as explicit min/max intensities.
 Returns
 outarray
Image array after rescaling its intensity. This image is the same dtype as the input image.
See also
Notes
Changed in version 0.17: The dtype of the output array has changed to match the output dtype, or float if the output range is specified by a pair of floats.
Examples
By default, the min/max intensities of the input image are stretched to the limits allowed by the image’s dtype, since in_range defaults to ‘image’ and out_range defaults to ‘dtype’:
>>> image = cp.array([51, 102, 153], dtype=np.uint8) >>> rescale_intensity(image) array([ 0, 127, 255], dtype=uint8)
It’s easy to accidentally convert an image dtype from uint8 to float:
>>> 1.0 * image array([ 51., 102., 153.])
Use rescale_intensity to rescale to the proper range for float dtypes:
>>> image_float = 1.0 * image >>> rescale_intensity(image_float) array([0. , 0.5, 1. ])
To maintain the low contrast of the original, use the in_range parameter:
>>> rescale_intensity(image_float, in_range=(0, 255)) array([0.2, 0.4, 0.6])
If the min/max value of in_range is more/less than the min/max image intensity, then the intensity levels are clipped:
>>> rescale_intensity(image_float, in_range=(0, 102)) array([0.5, 1. , 1. ])
If you have an image with signed integers but want to rescale the image to just the positive range, use the out_range parameter. In that case, the output dtype will be float:
>>> image = cp.asarray([10, 0, 10], dtype=np.int8) >>> rescale_intensity(image, out_range=(0, 127)) array([ 0. , 63.5, 127. ])
To get the desired range with a specific dtype, use
.astype()
:>>> rescale_intensity(image, out_range=(0, 127)).astype(np.int8) array([ 0, 63, 127], dtype=int8)
If the input image is constant, the output will be clipped directly to the output range: >>> image = cp.asarray([130, 130, 130], dtype=np.int32) >>> rescale_intensity(image, out_range=(0, 127)).astype(np.int32) array([127, 127, 127], dtype=int32)
feature#
 cucim.skimage.feature.canny(image, sigma=1.0, low_threshold=None, high_threshold=None, mask=None, use_quantiles=False, *, mode='constant', cval=0.0)#
Edge filter an image using the Canny algorithm.
 Parameters
 image2D array
Grayscale input image to detect edges on; can be of any dtype.
 sigmafloat, optional
Standard deviation of the Gaussian filter.
 low_thresholdfloat, optional
Lower bound for hysteresis thresholding (linking edges). If None, low_threshold is set to 10% of dtype’s max.
 high_thresholdfloat, optional
Upper bound for hysteresis thresholding (linking edges). If None, high_threshold is set to 20% of dtype’s max.
 maskarray, dtype=bool, optional
Mask to limit the application of Canny to a certain area.
 use_quantilesbool, optional
If
True
then treat low_threshold and high_threshold as quantiles of the edge magnitude image, rather than absolute edge magnitude values. IfTrue
then the thresholds must be in the range [0, 1]. modestr, {‘reflect’, ‘constant’, ‘nearest’, ‘mirror’, ‘wrap’}
The
mode
parameter determines how the array borders are handled during Gaussian filtering, wherecval
is the value when mode is equal to ‘constant’. cvalfloat, optional
Value to fill past edges of input if mode is ‘constant’.
 Returns
 output2D array (image)
The binary edge map.
See also
skimage.sobel
Notes
The steps of the algorithm are as follows:
Smooth the image using a Gaussian with
sigma
width.Apply the horizontal and vertical Sobel operators to get the gradients within the image. The edge strength is the norm of the gradient.
Thin potential edges to 1pixel wide curves. First, find the normal to the edge at each point. This is done by looking at the signs and the relative magnitude of the XSobel and YSobel to sort the points into 4 categories: horizontal, vertical, diagonal and antidiagonal. Then look in the normal and reverse directions to see if the values in either of those directions are greater than the point in question. Use interpolation to get a mix of points instead of picking the one that’s the closest to the normal.
Perform a hysteresis thresholding: first label all points above the high threshold as edges. Then recursively label any point above the low threshold that is 8connected to a labeled point as an edge.
References
 1
Canny, J., A Computational Approach To Edge Detection, IEEE Trans. Pattern Analysis and Machine Intelligence, 8:679714, 1986 DOI:10.1109/TPAMI.1986.4767851
 2
William Green’s Canny tutorial https://en.wikipedia.org/wiki/Canny_edge_detector
Examples
>>> import cupy as cp >>> from cucim.skimage import feature >>> # Generate noisy image of a square >>> im = cp.zeros((256, 256)) >>> im[64:64, 64:64] = 1 >>> im += 0.2 * cp.random.rand(*im.shape) >>> # First trial with the Canny filter, with the default smoothing >>> edges1 = feature.canny(im) >>> # Increase the smoothing for better results >>> edges2 = feature.canny(im, sigma=3)
 cucim.skimage.feature.corner_foerstner(image, sigma=1)#
Compute Foerstner corner measure response image.
This corner detector uses information from the autocorrelation matrix A:
A = [(imx**2) (imx*imy)] = [Axx Axy] [(imx*imy) (imy**2)] [Axy Ayy]
Where imx and imy are first derivatives, averaged with a gaussian filter. The corner measure is then defined as:
w = det(A) / trace(A) (size of error ellipse) q = 4 * det(A) / trace(A)**2 (roundness of error ellipse)
 Parameters
 image(M, N) ndarray
Input image.
 sigmafloat, optional
Standard deviation used for the Gaussian kernel, which is used as weighting function for the autocorrelation matrix.
 Returns
 wndarray
Error ellipse sizes.
 qndarray
Roundness of error ellipse.
References
 1
Förstner, W., & Gülch, E. (1987, June). A fast operator for detection and precise location of distinct points, corners and centres of circular features. In Proc. ISPRS intercommission conference on fast processing of photogrammetric data (pp. 281305). https://cseweb.ucsd.edu/classes/sp02/cse252/foerstner/foerstner.pdf
 2
Examples
>>> from cucim.skimage.feature import corner_foerstner, corner_peaks >>> square = cp.zeros([10, 10]) >>> square[2:8, 2:8] = 1 >>> square.astype(int) array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 1, 1, 1, 1, 1, 0, 0], [0, 0, 1, 1, 1, 1, 1, 1, 0, 0], [0, 0, 1, 1, 1, 1, 1, 1, 0, 0], [0, 0, 1, 1, 1, 1, 1, 1, 0, 0], [0, 0, 1, 1, 1, 1, 1, 1, 0, 0], [0, 0, 1, 1, 1, 1, 1, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]) >>> w, q = corner_foerstner(square) >>> accuracy_thresh = 0.5 >>> roundness_thresh = 0.3 >>> foerstner = (q > roundness_thresh) * (w > accuracy_thresh) * w >>> corner_peaks(foerstner, min_distance=1) array([[2, 2], [2, 7], [7, 2], [7, 7]])
 cucim.skimage.feature.corner_harris(image, method='k', k=0.05, eps=1e06, sigma=1)#
Compute Harris corner measure response image.
This corner detector uses information from the autocorrelation matrix A:
A = [(imx**2) (imx*imy)] = [Axx Axy] [(imx*imy) (imy**2)] [Axy Ayy]
Where imx and imy are first derivatives, averaged with a gaussian filter. The corner measure is then defined as:
det(A)  k * trace(A)**2
or:
2 * det(A) / (trace(A) + eps)
 Parameters
 image(M, N) ndarray
Input image.
 method{‘k’, ‘eps’}, optional
Method to compute the response image from the autocorrelation matrix.
 kfloat, optional
Sensitivity factor to separate corners from edges, typically in range [0, 0.2]. Small values of k result in detection of sharp corners.
 epsfloat, optional
Normalisation factor (Noble’s corner measure).
 sigmafloat, optional
Standard deviation used for the Gaussian kernel, which is used as weighting function for the autocorrelation matrix.
 Returns
 responsendarray
Harris response image.
References
Examples
>>> from cucim.skimage.feature import corner_harris, corner_peaks >>> square = cp.zeros([10, 10]) >>> square[2:8, 2:8] = 1 >>> square.astype(int) array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 1, 1, 1, 1, 1, 0, 0], [0, 0, 1, 1, 1, 1, 1, 1, 0, 0], [0, 0, 1, 1, 1, 1, 1, 1, 0, 0], [0, 0, 1, 1, 1, 1, 1, 1, 0, 0], [0, 0, 1, 1, 1, 1, 1, 1, 0, 0], [0, 0, 1, 1, 1, 1, 1, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]) >>> corner_peaks(corner_harris(square), min_distance=1) array([[2, 2], [2, 7], [7, 2], [7, 7]])
 cucim.skimage.feature.corner_kitchen_rosenfeld(image, mode='constant', cval=0)#
Compute Kitchen and Rosenfeld corner measure response image.
The corner measure is calculated as follows:
(imxx * imy**2 + imyy * imx**2  2 * imxy * imx * imy) / (imx**2 + imy**2)
Where imx and imy are the first and imxx, imxy, imyy the second derivatives.
 Parameters
 image(M, N) ndarray
Input image.
 mode{‘constant’, ‘reflect’, ‘wrap’, ‘nearest’, ‘mirror’}, optional
How to handle values outside the image borders.
 cvalfloat, optional
Used in conjunction with mode ‘constant’, the value outside the image boundaries.
 Returns
 responsendarray
Kitchen and Rosenfeld response image.
References
 1
Kitchen, L., & Rosenfeld, A. (1982). Graylevel corner detection. Pattern recognition letters, 1(2), 95102. DOI:10.1016/01678655(82)900204
 cucim.skimage.feature.corner_peaks(image, min_distance=1, threshold_abs=None, threshold_rel=None, exclude_border=True, indices=True, num_peaks=inf, footprint=None, labels=None, *, num_peaks_per_label=inf, p_norm=inf)#
Find peaks in corner measure response image.
This differs from skimage.feature.peak_local_max in that it suppresses multiple connected peaks with the same accumulator value.
 Parameters
 image(M, N) ndarray
Input image.
 min_distanceint, optional
The minimal allowed distance separating peaks.
 **
See
skimage.feature.peak_local_max()
. p_normfloat
Which Minkowski pnorm to use. Should be in the range [1, inf]. A finite large p may cause a ValueError if overflow can occur.
inf
corresponds to the Chebyshev distance and 2 to the Euclidean distance.
 Returns
 outputndarray or ndarray of bools
If indices = True : (row, column, …) coordinates of peaks.
If indices = False : Boolean array shaped like image, with peaks represented by True values.
See also
skimage.feature.peak_local_max
Notes
Changed in version 0.18: The default value of threshold_rel has changed to None, which corresponds to letting skimage.feature.peak_local_max decide on the default. This is equivalent to threshold_rel=0.
The num_peaks limit is applied before suppression of connected peaks. To limit the number of peaks after suppression, set num_peaks=np.inf and postprocess the output of this function.
Examples
>>> from cucim.skimage.feature import peak_local_max >>> response = cp.zeros((5, 5)) >>> response[2:4, 2:4] = 1 >>> response array([[0., 0., 0., 0., 0.], [0., 0., 0., 0., 0.], [0., 0., 1., 1., 0.], [0., 0., 1., 1., 0.], [0., 0., 0., 0., 0.]]) >>> peak_local_max(response) array([[2, 2], [2, 3], [3, 2], [3, 3]]) >>> corner_peaks(response) array([[2, 2]])
 cucim.skimage.feature.corner_shi_tomasi(image, sigma=1)#
Compute ShiTomasi (KanadeTomasi) corner measure response image.
This corner detector uses information from the autocorrelation matrix A:
A = [(imx**2) (imx*imy)] = [Axx Axy] [(imx*imy) (imy**2)] [Axy Ayy]
Where imx and imy are first derivatives, averaged with a gaussian filter. The corner measure is then defined as the smaller eigenvalue of A:
((Axx + Ayy)  sqrt((Axx  Ayy)**2 + 4 * Axy**2)) / 2
 Parameters
 image(M, N) ndarray
Input image.
 sigmafloat, optional
Standard deviation used for the Gaussian kernel, which is used as weighting function for the autocorrelation matrix.
 Returns
 responsendarray
ShiTomasi response image.
References
Examples
>>> from cucim.skimage.feature import corner_shi_tomasi, corner_peaks >>> square = cp.zeros([10, 10]) >>> square[2:8, 2:8] = 1 >>> square.astype(int) array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 1, 1, 1, 1, 1, 0, 0], [0, 0, 1, 1, 1, 1, 1, 1, 0, 0], [0, 0, 1, 1, 1, 1, 1, 1, 0, 0], [0, 0, 1, 1, 1, 1, 1, 1, 0, 0], [0, 0, 1, 1, 1, 1, 1, 1, 0, 0], [0, 0, 1, 1, 1, 1, 1, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]) >>> corner_peaks(corner_shi_tomasi(square), ... min_distance=1) array([[2, 2], [2, 7], [7, 2], [7, 7]])
 cucim.skimage.feature.daisy(image, step=4, radius=15, rings=3, histograms=8, orientations=8, normalization='l1', sigmas=None, ring_radii=None, visualize=False)#
Extract DAISY feature descriptors densely for the given image.
DAISY is a feature descriptor similar to SIFT formulated in a way that allows for fast dense extraction. Typically, this is practical for bagoffeatures image representations.
The implementation follows Tola et al. [1] but deviate on the following points:
Histogram bin contribution are smoothed with a circular Gaussian window over the tonal range (the angular range).
The sigma values of the spatial Gaussian smoothing in this code do not match the sigma values in the original code by Tola et al. [2]. In their code, spatial smoothing is applied to both the input image and the center histogram. However, this smoothing is not documented in [1] and, therefore, it is omitted.
 Parameters
 image(M, N) array
Input image (grayscale).
 stepint, optional
Distance between descriptor sampling points.
 radiusint, optional
Radius (in pixels) of the outermost ring.
 ringsint, optional
Number of rings.
 histogramsint, optional
Number of histograms sampled per ring.
 orientationsint, optional
Number of orientations (bins) per histogram.
 normalization[ ‘l1’  ‘l2’  ‘daisy’  ‘off’ ], optional
How to normalize the descriptors
‘l1’: L1normalization of each descriptor.
‘l2’: L2normalization of each descriptor.
‘daisy’: L2normalization of individual histograms.
‘off’: Disable normalization.
 sigmas1D array of float, optional
Standard deviation of spatial Gaussian smoothing for the center histogram and for each ring of histograms. The array of sigmas should be sorted from the center and out. I.e. the first sigma value defines the spatial smoothing of the center histogram and the last sigma value defines the spatial smoothing of the outermost ring. Specifying sigmas overrides the following parameter.
rings = len(sigmas)  1
 ring_radii1D array of int, optional
Radius (in pixels) for each ring. Specifying ring_radii overrides the following two parameters.
rings = len(ring_radii)
radius = ring_radii[1]
If both sigmas and ring_radii are given, they must satisfy the following predicate since no radius is needed for the center histogram.
len(ring_radii) == len(sigmas) + 1
 visualizebool, optional
Generate a visualization of the DAISY descriptors
 Returns
 descsarray
Grid of DAISY descriptors for the given image as an array dimensionality (P, Q, R) where
P = ceil((M  radius*2) / step)
Q = ceil((N  radius*2) / step)
R = (rings * histograms + 1) * orientations
 descs_img(M, N, 3) array (only if visualize==True)
Visualization of the DAISY descriptors.
References
 cucim.skimage.feature.hessian_matrix(image, sigma=1, mode='constant', cval=0, order='rc')#
Compute the Hessian matrix.
In 2D, the Hessian matrix is defined as:
H = [Hrr Hrc] [Hrc Hcc]
which is computed by convolving the image with the second derivatives of the Gaussian kernel in the respective r and cdirections.
The implementation here also supports ndimensional data.
 Parameters
 imagendarray
Input image.
 sigmafloat
Standard deviation used for the Gaussian kernel, which is used as weighting function for the autocorrelation matrix.
 mode{‘constant’, ‘reflect’, ‘wrap’, ‘nearest’, ‘mirror’}, optional
How to handle values outside the image borders.
 cvalfloat, optional
Used in conjunction with mode ‘constant’, the value outside the image boundaries.
 order{‘rc’, ‘xy’}, optional
This parameter allows for the use of reverse or forward order of the image axes in gradient computation. ‘rc’ indicates the use of the first axis initially (Hrr, Hrc, Hcc), whilst ‘xy’ indicates the usage of the last axis initially (Hxx, Hxy, Hyy)
 Returns
 H_elemslist of ndarray
Upperdiagonal elements of the hessian matrix for each pixel in the input image. In 2D, this will be a three element list containing [Hrr, Hrc, Hcc]. In nD, the list will contain
(n**2 + n) / 2
arrays.
Examples
>>> import cupy as cp >>> from cucim.skimage.feature import hessian_matrix >>> square = cp.zeros((5, 5)) >>> square[2, 2] = 4 >>> Hrr, Hrc, Hcc = hessian_matrix(square, sigma=0.1, order='rc') >>> Hrc array([[ 0., 0., 0., 0., 0.], [ 0., 1., 0., 1., 0.], [ 0., 0., 0., 0., 0.], [ 0., 1., 0., 1., 0.], [ 0., 0., 0., 0., 0.]])
 cucim.skimage.feature.hessian_matrix_det(image, sigma=1, approximate=True)#
Compute the approximate Hessian Determinant over an image.
The 2D approximate method uses box filters over integral images to compute the approximate Hessian Determinant.
 Parameters
 imagendarray
The image over which to compute the Hessian Determinant.
 sigmafloat, optional
Standard deviation of the Gaussian kernel used for the Hessian matrix.
 approximatebool, optional
If
True
and the image is 2D, use a much faster approximate computation. This argument has no effect on 3D and higher images.
 Returns
 outarray
The array of the Determinant of Hessians.
Notes
For 2D images when
approximate=True
, the running time of this method only depends on size of the image. It is independent of sigma as one would expect. The downside is that the result for sigma less than 3 is not accurate, i.e., not similar to the result obtained if someone computed the Hessian and took its determinant.References
 1
Herbert Bay, Andreas Ess, Tinne Tuytelaars, Luc Van Gool, “SURF: Speeded Up Robust Features” ftp://ftp.vision.ee.ethz.ch/publications/articles/eth_biwi_00517.pdf
 cucim.skimage.feature.hessian_matrix_eigvals(H_elems)#
Compute eigenvalues of Hessian matrix.
 Parameters
 H_elemslist of ndarray
The upperdiagonal elements of the Hessian matrix, as returned by hessian_matrix.
 Returns
 eigsndarray
The eigenvalues of the Hessian matrix, in decreasing order. The eigenvalues are the leading dimension. That is,
eigs[i, j, k]
contains the ithlargest eigenvalue at position (j, k).
Examples
>>> import cupy as cp >>> from cucim.skimage.feature import (hessian_matrix, ... hessian_matrix_eigvals) >>> square = cp.zeros((5, 5)) >>> square[2, 2] = 4 >>> H_elems = hessian_matrix(square, sigma=0.1, order='rc') >>> hessian_matrix_eigvals(H_elems)[0] array([[ 0., 0., 2., 0., 0.], [ 0., 1., 0., 1., 0.], [ 2., 0., 2., 0., 2.], [ 0., 1., 0., 1., 0.], [ 0., 0., 2., 0., 0.]])
 cucim.skimage.feature.masked_register_translation(src_image, target_image, src_mask, target_mask=None, overlap_ratio=0.3)#
Deprecated function. Use
cucim.skimage.registration.phase_cross_correlation
instead.
 cucim.skimage.feature.match_template(image, template, pad_input=False, mode='constant', constant_values=0)#
Match a template to a 2D or 3D image using normalized correlation.
The output is an array with values between 1.0 and 1.0. The value at a given position corresponds to the correlation coefficient between the image and the template.
For pad_input=True matches correspond to the center and otherwise to the topleft corner of the template. To find the best match you must search for peaks in the response (output) image.
 Parameters
 image(M, N[, D]) array
2D or 3D input image.
 template(m, n[, d]) array
Template to locate. It must be (m <= M, n <= N[, d <= D]).
 pad_inputbool
If True, pad image so that output is the same size as the image, and output values correspond to the template center. Otherwise, the output is an array with shape (M  m + 1, N  n + 1) for an (M, N) image and an (m, n) template, and matches correspond to origin (topleft corner) of the template.
 modesee numpy.pad, optional
Padding mode.
 constant_valuessee numpy.pad, optional
Constant values used in conjunction with
mode='constant'
.
 Returns
 outputarray
Response image with correlation coefficients.
Notes
Details on the crosscorrelation are presented in [1]. This implementation uses FFT convolutions of the image and the template. Reference [2] presents similar derivations but the approximation presented in this reference is not used in our implementation.
This CuPy implementation does not force the image to float64 internally, but will use float32 for singleprecision inputs.
References
 1
J. P. Lewis, “Fast Normalized CrossCorrelation”, Industrial Light and Magic.
 2
Briechle and Hanebeck, “Template Matching using Fast Normalized Cross Correlation”, Proceedings of the SPIE (2001). DOI:10.1117/12.421129
Examples
>>> import cupy as cp >>> template = cp.zeros((3, 3)) >>> template[1, 1] = 1 >>> template array([[0., 0., 0.], [0., 1., 0.], [0., 0., 0.]]) >>> image = cp.zeros((6, 6)) >>> image[1, 1] = 1 >>> image[4, 4] = 1 >>> image array([[ 0., 0., 0., 0., 0., 0.], [ 0., 1., 0., 0., 0., 0.], [ 0., 0., 0., 0., 0., 0.], [ 0., 0., 0., 0., 0., 0.], [ 0., 0., 0., 0., 1., 0.], [ 0., 0., 0., 0., 0., 0.]]) >>> result = match_template(image, template) >>> cp.round(result, 3) array([[ 1. , 0.125, 0. , 0. ], [0.125, 0.125, 0. , 0. ], [ 0. , 0. , 0.125, 0.125], [ 0. , 0. , 0.125, 1. ]]) >>> result = match_template(image, template, pad_input=True) >>> cp.round(result, 3) array([[0.125, 0.125, 0.125, 0. , 0. , 0. ], [0.125, 1. , 0.125, 0. , 0. , 0. ], [0.125, 0.125, 0.125, 0. , 0. , 0. ], [ 0. , 0. , 0. , 0.125, 0.125, 0.125], [ 0. , 0. , 0. , 0.125, 1. , 0.125], [ 0. , 0. , 0. , 0.125, 0.125, 0.125]])
 cucim.skimage.feature.multiscale_basic_features(image, multichannel=False, intensity=True, edges=True, texture=True, sigma_min=0.5, sigma_max=16, num_sigma=None, num_workers=None, *, channel_axis=None)#
Local features for a single or multichannel nd image.
Intensity, gradient intensity and local structure are computed at different scales thanks to Gaussian blurring.
 Parameters
 imagendarray
Input image, which can be grayscale or multichannel.
 multichannelbool, default False
True if the last dimension corresponds to color channels. This argument is deprecated: specify channel_axis instead.
 intensitybool, default True
If True, pixel intensities averaged over the different scales are added to the feature set.
 edgesbool, default True
If True, intensities of local gradients averaged over the different scales are added to the feature set.
 texturebool, default True
If True, eigenvalues of the Hessian matrix after Gaussian blurring at different scales are added to the feature set.
 sigma_minfloat, optional
Smallest value of the Gaussian kernel used to average local neighbourhoods before extracting features.
 sigma_maxfloat, optional
Largest value of the Gaussian kernel used to average local neighbourhoods before extracting features.
 num_sigmaint, optional
Number of values of the Gaussian kernel between sigma_min and sigma_max. If None, sigma_min multiplied by powers of 2 are used.
 num_workersint or None, optional
The number of parallel threads to use. If set to
None
, the full set of available cores are used. channel_axisint or None, optional
If None, the image is assumed to be a grayscale (single channel) image. Otherwise, this parameter indicates which axis of the array corresponds to channels.
 Returns
 featuresnp.ndarray
Array of shape
image.shape + (n_features,)
. When channel_axis is not None, all channels are concatenated along the features dimension. (i.e.n_features == n_features_singlechannel * n_channels
)
 Other Parameters
 multichannelDEPRECATED
Deprecated in favor of channel_axis.
Deprecated since version 0.19.
 cucim.skimage.feature.peak_local_max(image, min_distance=1, threshold_abs=None, threshold_rel=None, exclude_border=True, indices=True, num_peaks=inf, footprint=None, labels=None, num_peaks_per_label=inf, p_norm=inf)#
Find peaks in an image as coordinate list or boolean mask.
Peaks are the local maxima in a region of 2 * min_distance + 1 (i.e. peaks are separated by at least min_distance).
If both threshold_abs and threshold_rel are provided, the maximum of the two is chosen as the minimum intensity threshold of peaks.
Changed in version 0.18: Prior to version 0.18, peaks of the same height within a radius of min_distance were all returned, but this could cause unexpected behaviour. From 0.18 onwards, an arbitrary peak within the region is returned. See issue gh2592.
 Parameters
 imagendarray
Input image.
 min_distanceint, optional
The minimal allowed distance separating peaks. To find the maximum number of peaks, use min_distance=1.
 threshold_absfloat or None, optional
Minimum intensity of peaks. By default, the absolute threshold is the minimum intensity of the image.
 threshold_relfloat or None, optional
Minimum intensity of peaks, calculated as
max(image) * threshold_rel
. exclude_borderint, tuple of ints, or bool, optional
If positive integer, exclude_border excludes peaks from within exclude_borderpixels of the border of the image. If tuple of nonnegative ints, the length of the tuple must match the input array’s dimensionality. Each element of the tuple will exclude peaks from within exclude_borderpixels of the border of the image along that dimension. If True, takes the min_distance parameter as value. If zero or False, peaks are identified regardless of their distance from the border.
 indicesbool, optional
If True, the output will be an array representing peak coordinates. The coordinates are sorted according to peaks values (Larger first). If False, the output will be a boolean array shaped as image.shape with peaks present at True elements.
indices
is deprecated and will be removed in version 0.20. Default behavior will be to always return peak coordinates. You can obtain a mask as shown in the example below. num_peaksint, optional
Maximum number of peaks. When the number of peaks exceeds num_peaks, return num_peaks peaks based on highest peak intensity.
 footprintndarray of bools, optional
If provided, footprint == 1 represents the local region within which to search for peaks at every point in image.
 labelsndarray of ints, optional
If provided, each unique region labels == value represents a unique region to search for peaks. Zero is reserved for background.
 num_peaks_per_labelint, optional
Maximum number of peaks for each label.
 p_normfloat
Which Minkowski pnorm to use. Should be in the range [1, inf]. A finite large p may cause a ValueError if overflow can occur.
inf
corresponds to the Chebyshev distance and 2 to the Euclidean distance.
 Returns
 outputndarray or ndarray of bools
If indices = True : (row, column, …) coordinates of peaks.
If indices = False : Boolean array shaped like image, with peaks represented by True values.
See also
skimage.feature.corner_peaks
Notes
The peak local maximum function returns the coordinates of local peaks (maxima) in an image. Internally, a maximum filter is used for finding local maxima. This operation dilates the original image. After comparison of the dilated and original image, this function returns the coordinates or a mask of the peaks where the dilated image equals the original image.
Examples
>>> import cupy as cp >>> img1 = cp.zeros((7, 7)) >>> img1[3, 4] = 1 >>> img1[3, 2] = 1.5 >>> img1 array([[0. , 0. , 0. , 0. , 0. , 0. , 0. ], [0. , 0. , 0. , 0. , 0. , 0. , 0. ], [0. , 0. , 0. , 0. , 0. , 0. , 0. ], [0. , 0. , 1.5, 0. , 1. , 0. , 0. ], [0. , 0. , 0. , 0. , 0. , 0. , 0. ], [0. , 0. , 0. , 0. , 0. , 0. , 0. ], [0. , 0. , 0. , 0. , 0. , 0. , 0. ]])
>>> peak_local_max(img1, min_distance=1) array([[3, 2], [3, 4]])
>>> peak_local_max(img1, min_distance=2) array([[3, 2]])
>>> img2 = cp.zeros((20, 20, 20)) >>> img2[10, 10, 10] = 1 >>> img2[15, 15, 15] = 1 >>> peak_idx = peak_local_max(img2, exclude_border=0) >>> peak_idx array([[10, 10, 10], [15, 15, 15]])
>>> peak_mask = cp.zeros_like(img2, dtype=bool) >>> peak_mask[tuple(peak_idx.T)] = True >>> np.argwhere(peak_mask) array([[10, 10, 10], [15, 15, 15]])
 cucim.skimage.feature.register_translation(src_image, target_image, upsample_factor=1, space='real', return_error=True)#
Deprecated function. Use
cucim.skimage.registration.phase_cross_correlation
instead.
 cucim.skimage.feature.shape_index(image, sigma=1, mode='constant', cval=0)#
Compute the shape index.
The shape index, as defined by Koenderink & van Doorn [1], is a single valued measure of local curvature, assuming the image as a 3D plane with intensities representing heights.
It is derived from the eigenvalues of the Hessian, and its value ranges from 1 to 1 (and is undefined (=NaN) in flat regions), with following ranges representing following shapes:
# Interval (s in …)
Shape
[ 1, 7/8)
Spherical cup
[7/8, 5/8)
Through
[5/8, 3/8)
Rut
[3/8, 1/8)
Saddle rut
[1/8, +1/8)
Saddle
[+1/8, +3/8)
Saddle ridge
[+3/8, +5/8)
Ridge
[+5/8, +7/8)
Dome
[+7/8, +1]
Spherical cap
 Parameters
 image(M, N) ndarray
Input image.
 sigmafloat, optional
Standard deviation used for the Gaussian kernel, which is used for smoothing the input data before Hessian eigen value calculation.
 mode{‘constant’, ‘reflect’, ‘wrap’, ‘nearest’, ‘mirror’}, optional
How to handle values outside the image borders
 cvalfloat, optional
Used in conjunction with mode ‘constant’, the value outside the image boundaries.
 Returns
 sndarray
Shape index
References
 1
Koenderink, J. J. & van Doorn, A. J., “Surface shape and curvature scales”, Image and Vision Computing, 1992, 10, 557564. DOI:10.1016/02628856(92)90076F
Examples
>>> from cucim.skimage.feature import shape_index >>> square = cp.zeros((5, 5)) >>> square[2, 2] = 4 >>> s = shape_index(square, sigma=0.1) >>> s array([[ nan, nan, 0.5, nan, nan], [ nan, 0. , nan, 0. , nan], [0.5, nan, 1. , nan, 0.5], [ nan, 0. , nan, 0. , nan], [ nan, nan, 0.5, nan, nan]])
 cucim.skimage.feature.structure_tensor(image, sigma=1, mode='constant', cval=0, order=None)#
Compute structure tensor using sum of squared differences.
The (2dimensional) structure tensor A is defined as:
A = [Arr Arc] [Arc Acc]
which is approximated by the weighted sum of squared differences in a local window around each pixel in the image. This formula can be extended to a larger number of dimensions (see [1]).
 Parameters
 imagendarray
Input image.
 sigmafloat or arraylike of float, optional
Standard deviation used for the Gaussian kernel, which is used as a weighting function for the local summation of squared differences. If sigma is an iterable, its length must be equal to image.ndim and each element is used for the Gaussian kernel applied along its respective axis.
 mode{‘constant’, ‘reflect’, ‘wrap’, ‘nearest’, ‘mirror’}, optional
How to handle values outside the image borders.
 cvalfloat, optional
Used in conjunction with mode ‘constant’, the value outside the image boundaries.
 order{‘rc’, ‘xy’}, optional
NOTE: Only applies in 2D. Higher dimensions must always use ‘rc’ order. This parameter allows for the use of reverse or forward order of the image axes in gradient computation. ‘rc’ indicates the use of the first axis initially (Arr, Arc, Acc), whilst ‘xy’ indicates the usage of the last axis initially (Axx, Axy, Ayy).
 Returns
 A_elemslist of ndarray
Upperdiagonal elements of the structure tensor for each pixel in the input image.
See also
References
Examples
>>> import cupy as cp >>> from cucim.skimage.feature import structure_tensor >>> square = cp.zeros((5, 5)) >>> square[2, 2] = 1 >>> Arr, Arc, Acc = structure_tensor(square, sigma=0.1, order="rc") >>> Acc array([[0., 0., 0., 0., 0.], [0., 1., 0., 1., 0.], [0., 4., 0., 4., 0.], [0., 1., 0., 1., 0.], [0., 0., 0., 0., 0.]])
 cucim.skimage.feature.structure_tensor_eigenvalues(A_elems)#
Compute eigenvalues of structure tensor.
 Parameters
 A_elemslist of ndarray
The upperdiagonal elements of the structure tensor, as returned by structure_tensor.
 Returns
 ndarray
The eigenvalues of the structure tensor, in decreasing order. The eigenvalues are the leading dimension. That is, the coordinate [i, j, k] corresponds to the ithlargest eigenvalue at position (j, k).
See also
Examples
>>> import cupy as cp >>> from cucim.skimage.feature import structure_tensor >>> from cucim.skimage.feature import structure_tensor_eigenvalues >>> square = cp.zeros((5, 5)) >>> square[2, 2] = 1 >>> A_elems = structure_tensor(square, sigma=0.1, order='rc') >>> structure_tensor_eigenvalues(A_elems)[0] array([[0., 0., 0., 0., 0.], [0., 2., 4., 2., 0.], [0., 4., 0., 4., 0.], [0., 2., 4., 2., 0.], [0., 0., 0., 0., 0.]])
filters#
 class cucim.skimage.filters.LPIFilter2D(impulse_response, **filter_params)#
Linear PositionInvariant Filter (2dimensional)
Methods
__call__
(data)Apply the filter to the given data.
 cucim.skimage.filters.apply_hysteresis_threshold(image, low, high)#
Apply hysteresis thresholding to
image
.This algorithm finds regions where
image
is greater thanhigh
ORimage
is greater thanlow
and that region is connected to a region greater thanhigh
. Parameters
 imagearray, shape (M,[ N, …, P])
Grayscale input image.
 lowfloat, or array of same shape as
image
Lower threshold.
 highfloat, or array of same shape as
image
Higher threshold.
 Returns
 thresholdedarray of bool, same shape as
image
Array in which
True
indicates the locations whereimage
was above the hysteresis threshold.
 thresholdedarray of bool, same shape as
References
 1
J. Canny. A computational approach to edge detection. IEEE Transactions on Pattern Analysis and Machine Intelligence. 1986; vol. 8, pp.679698. DOI:10.1109/TPAMI.1986.4767851
Examples
>>> import cupy as cp >>> from cucim.skimage.filters import apply_hysteresis_threshold >>> image = cp.asarray([1, 2, 3, 2, 1, 2, 1, 3, 2]) >>> apply_hysteresis_threshold(image, 1.5, 2.5).astype(int) array([0, 1, 1, 1, 0, 0, 0, 1, 1])
 cucim.skimage.filters.butterworth(image, cutoff_frequency_ratio=0.005, high_pass=True, order=2.0, channel_axis=None)#
Apply a Butterworth filter to enhance high or low frequency features.
This filter is defined in the Fourier domain.
 Parameters
 image(M[, N[, …, P]][, C]) ndarray
Input image.
 cutoff_frequency_ratiofloat, optional
Determines the position of the cutoff relative to the shape of the FFT.
 high_passbool, optional
Whether to perform a high pass filter. If False, a low pass filter is performed.
 orderfloat, optional
Order of the filter which affects the slope near the cutoff. Higher order means steeper slope in frequency space.
 channel_axisint, optional
If there is a channel dimension, provide the index here. If None (default) then all axes are assumed to be spatial dimensions.
 Returns
 resultndarray
The Butterworthfiltered image.
Notes
A bandpass filter can be achieved by combining a high pass and low pass filter.
The literature contains multiple conventions for the functional form of the Butterworth filter. Here it is implemented as the ndimensional form of
\[\frac{1}{1  \left(\frac{f}{c*f_{max}}\right)^{2*n}}\]with \(f\) the absolute value of the spatial frequency, \(c\) the
cutoff_frequency_ratio
and \(n\) theorder
modeled after [2]References
 1
Butterworth, Stephen. “On the theory of filter amplifiers.” Wireless Engineer 7.6 (1930): 536541.
 2
Russ, John C., et al. “The image processing handbook.” Computers in Physics 8.2 (1994): 177178.
Examples
Apply a high pass and low pass Butterworth filter to a grayscale and color image respectively:
>>> import cupy as cp >>> from skimage.data import camera, astronaut >>> from cucim.skimage.filters import butterworth >>> cam = cp.asarray(camera()) >>> astro = cp.asarray(astronaut()) >>> high_pass = butterworth(cam, 0.07, True, 8) >>> low_pass = butterworth(astro, 0.01, False, 4, channel_axis=1)
 cucim.skimage.filters.correlate_sparse(image, kernel, mode='reflect')#
Compute valid crosscorrelation of padded_array and kernel.
This function is fast when kernel is large with many zeros.
See
scipy.ndimage.correlate
for a description of crosscorrelation. Parameters
 imagendarray, dtype float, shape (M, N,[ …,] P)
The input array. If mode is ‘valid’, this array should already be padded, as a margin of the same shape as kernel will be stripped off.
 kernelndarray, dtype float shape (Q, R,[ …,] S)
The kernel to be correlated. Must have the same number of dimensions as padded_array. For high performance, it should be sparse (few nonzero entries).
 modestring, optional
See scipy.ndimage.correlate for valid modes. Additionally, mode ‘valid’ is accepted, in which case no padding is applied and the result is the result for the smaller image for which the kernel is entirely inside the original data.
 Returns
 resultarray of float, shape (M, N,[ …,] P)
The result of crosscorrelating image with kernel. If mode ‘valid’ is used, the resulting shape is (MQ+1, NR+1,[ …,] PS+1).
 cucim.skimage.filters.difference_of_gaussians(image, low_sigma, high_sigma=None, *, mode='nearest', cval=0, channel_axis=None, truncate=4.0, multichannel=False)#
Find features between
low_sigma
andhigh_sigma
in size.This function uses the Difference of Gaussians method for applying bandpass filters to multidimensional arrays. The input array is blurred with two Gaussian kernels of differing sigmas to produce two intermediate, filtered images. The moreblurred image is then subtracted from the lessblurred image. The final output image will therefore have had highfrequency components attenuated by the smallersigma Gaussian, and low frequency components will have been removed due to their presence in the moreblurred intermediate.
 Parameters
 imagendarray
Input array to filter.
 low_sigmascalar or sequence of scalars
Standard deviation(s) for the Gaussian kernel with the smaller sigmas across all axes. The standard deviations are given for each axis as a sequence, or as a single number, in which case the single number is used as the standard deviation value for all axes.
 high_sigmascalar or sequence of scalars, optional (default is None)
Standard deviation(s) for the Gaussian kernel with the larger sigmas across all axes. The standard deviations are given for each axis as a sequence, or as a single number, in which case the single number is used as the standard deviation value for all axes. If None is given (default), sigmas for all axes are calculated as 1.6 * low_sigma.
 mode{‘reflect’, ‘constant’, ‘nearest’, ‘mirror’, ‘wrap’}, optional
The
mode
parameter determines how the array borders are handled, wherecval
is the value when mode is equal to ‘constant’. Default is ‘nearest’. cvalscalar, optional
Value to fill past edges of input if
mode
is ‘constant’. Default is 0.0 channel_axisint or None, optional
If None, the image is assumed to be a grayscale (single channel) image. Otherwise, this parameter indicates which axis of the array corresponds to channels.
 truncatefloat, optional (default is 4.0)
Truncate the filter at this many standard deviations.
 multichannelbool, optional (default: False)
Whether the last axis of the image is to be interpreted as multiple channels. If True, each channel is filtered separately (channels are not mixed together). This argument is deprecated: specify channel_axis instead.
 Returns
 filtered_imagendarray
the filtered array.
 Other Parameters
 multichannelDEPRECATED
Deprecated in favor of channel_axis.
Deprecated since version 0.19.
See also
skimage.feature.blog_dog()
Notes
This function will subtract an array filtered with a Gaussian kernel with sigmas given by
high_sigma
from an array filtered with a Gaussian kernel with sigmas provided bylow_sigma
. The values forhigh_sigma
must always be greater than or equal to the corresponding values inlow_sigma
, or aValueError
will be raised.When
high_sigma
is none, the values forhigh_sigma
will be calculated as 1.6x the corresponding values inlow_sigma
. This ratio was originally proposed by Marr and Hildreth (1980) [1] and is commonly used when approximating the inverted Laplacian of Gaussian, which is used in edge and blob detection.Input image is converted according to the conventions of
img_as_float
.Except for sigma values, all parameters are used for both filters.
References
 1
Marr, D. and Hildreth, E. Theory of Edge Detection. Proc. R. Soc. Lond. Series B 207, 187217 (1980). https://doi.org/10.1098/rspb.1980.0020
Examples
Apply a simple Difference of Gaussians filter to a color image:
>>> from skimage.data import astronaut >>> from cucim.skimage.filters import difference_of_gaussians >>> astro = cp.asarray(astronaut()) >>> filtered_image = difference_of_gaussians(astro, 2, 10, ... multichannel=True)
Apply a Laplacian of Gaussian filter as approximated by the Difference of Gaussians filter:
>>> filtered_image = difference_of_gaussians(astro, 2, ... multichannel=True)
Apply a Difference of Gaussians filter to a grayscale image using different sigma values for each axis:
>>> from skimage.data import camera >>> cam = cp.array(camera()) >>> filtered_image = difference_of_gaussians(cam, (2,5), (3,20))
 cucim.skimage.filters.farid(image, *, mask=None)#
Find the edge magnitude using the Farid transform.
 Parameters
 image2D array
Image to process.
 mask2D array, optional
An optional mask to limit the application to a certain area. Note that pixels surrounding masked regions are also masked to prevent masked regions from affecting the result.
 Returns
 output2D array
The Farid edge map.
See also
Notes
Take the square root of the sum of the squares of the horizontal and vertical derivatives to get a magnitude that is somewhat insensitive to direction. Similar to the Scharr operator, this operator is designed with a rotation invariance constraint.
References
 1
Farid, H. and Simoncelli, E. P., “Differentiation of discrete multidimensional signals”, IEEE Transactions on Image Processing 13(4): 496508, 2004. DOI:10.1109/TIP.2004.823819
 2
Wikipedia, “Farid and Simoncelli Derivatives.” Available at: <https://en.wikipedia.org/wiki/Image_derivatives#Farid_and_Simoncelli_Derivatives>
Examples
>>> import cupy as cp >>> from skimage import data >>> camera = cp.array(data.camera()) >>> from cucim.skimage import filters >>> edges = filters.farid(camera)
 cucim.skimage.filters.farid_h(image, *, mask=None)#
Find the horizontal edges of an image using the Farid transform.
 Parameters
 image2D array
Image to process.
 mask2D array, optional
An optional mask to limit the application to a certain area. Note that pixels surrounding masked regions are also masked to prevent masked regions from affecting the result.
 Returns
 output2D array
The Farid edge map.
Notes
The kernel was constructed using the 5tap weights from [1].
References
 1
Farid, H. and Simoncelli, E. P., “Differentiation of discrete multidimensional signals”, IEEE Transactions on Image Processing 13(4): 496508, 2004. DOI:10.1109/TIP.2004.823819
 2
Farid, H. and Simoncelli, E. P. “Optimally rotationequivariant directional derivative kernels”, In: 7th International Conference on Computer Analysis of Images and Patterns, Kiel, Germany. Sep, 1997.
 cucim.skimage.filters.farid_v(image, *, mask=None)#
Find the vertical edges of an image using the Farid transform.
 Parameters
 image2D array
Image to process.
 mask2D array, optional
An optional mask to limit the application to a certain area. Note that pixels surrounding masked regions are also masked to prevent masked regions from affecting the result.
 Returns
 output2D array
The Farid edge map.
Notes
The kernel was constructed using the 5tap weights from [1].
References
 1
Farid, H. and Simoncelli, E. P., “Differentiation of discrete multidimensional signals”, IEEE Transactions on Image Processing 13(4): 496508, 2004. DOI:10.1109/TIP.2004.823819
 cucim.skimage.filters.frangi(image, sigmas=range(1, 10, 2), scale_range=None, scale_step=None, alpha=0.5, beta=0.5, gamma=15, black_ridges=True, mode='reflect', cval=0)#
Filter an image with the Frangi vesselness filter.
This filter can be used to detect continuous ridges, e.g. vessels, wrinkles, rivers. It can be used to calculate the fraction of the whole image containing such objects.
Defined only for 2D and 3D images. Calculates the eigenvectors of the Hessian to compute the similarity of an image region to vessels, according to the method described in [1].
 Parameters
 image(N, M[, P]) ndarray
Array with input image data.
 sigmasiterable of floats, optional
Sigmas used as scales of filter, i.e., np.arange(scale_range[0], scale_range[1], scale_step)
 scale_range2tuple of floats, optional
The range of sigmas used.
 scale_stepfloat, optional
Step size between sigmas.
 alphafloat, optional
Frangi correction constant that adjusts the filter’s sensitivity to deviation from a platelike structure.
 betafloat, optional
Frangi correction constant that adjusts the filter’s sensitivity to deviation from a bloblike structure.
 gammafloat, optional
Frangi correction constant that adjusts the filter’s sensitivity to areas of high variance/texture/structure.
 black_ridgesboolean, optional
When True (the default), the filter detects black ridges; when False, it detects white ridges.
 mode{‘constant’, ‘reflect’, ‘wrap’, ‘nearest’, ‘mirror’}, optional
How to handle values outside the image borders.
 cvalfloat, optional
Used in conjunction with mode ‘constant’, the value outside the image boundaries.
 Returns
 out(N, M[, P]) ndarray
Filtered image (maximum of pixels across all scales).
Notes
Written by Marc Schrijver, November 2001 ReWritten by D. J. Kroon, University of Twente, May 2009, [2] Adoption of 3D version from D. G. Ellis, Januar 20017, [3]
References
 1
Frangi, A. F., Niessen, W. J., Vincken, K. L., & Viergever, M. A. (1998,). Multiscale vessel enhancement filtering. In International Conference on Medical Image Computing and ComputerAssisted Intervention (pp. 130137). Springer Berlin Heidelberg. DOI:10.1007/BFb0056195
 2
Kroon, D. J.: Hessian based Frangi vesselness filter.
 3
Ellis, D. G.: https://github.com/ellisdg/frangi3d/tree/master/frangi
 cucim.skimage.filters.gabor(image, frequency, theta=0, bandwidth=1, sigma_x=None, sigma_y=None, n_stds=3, offset=0, mode='reflect', cval=0)#
Return real and imaginary responses to Gabor filter.
The real and imaginary parts of the Gabor filter kernel are applied to the image and the response is returned as a pair of arrays.
Gabor filter is a linear filter with a Gaussian kernel which is modulated by a sinusoidal plane wave. Frequency and orientation representations of the Gabor filter are similar to those of the human visual system. Gabor filter banks are commonly used in computer vision and image processing. They are especially suitable for edge detection and texture classification.
 Parameters
 image2D array
Input image.
 frequencyfloat
Spatial frequency of the harmonic function. Specified in pixels.
 thetafloat, optional
Orientation in radians. If 0, the harmonic is in the xdirection.
 bandwidthfloat, optional
The bandwidth captured by the filter. For fixed bandwidth,
sigma_x
andsigma_y
will decrease with increasing frequency. This value is ignored ifsigma_x
andsigma_y
are set by the user. sigma_x, sigma_yfloat, optional
Standard deviation in x and ydirections. These directions apply to the kernel before rotation. If theta = pi/2, then the kernel is rotated 90 degrees so that
sigma_x
controls the vertical direction. n_stdsscalar, optional
The linear size of the kernel is n_stds (3 by default) standard deviations.
 offsetfloat, optional
Phase offset of harmonic function in radians.
 mode{‘constant’, ‘nearest’, ‘reflect’, ‘mirror’, ‘wrap’}, optional
Mode used to convolve image with a kernel, passed to ndi.convolve
 cvalscalar, optional
Value to fill past edges of input if
mode
of convolution is ‘constant’. The parameter is passed to ndi.convolve.
 Returns
 real, imagarrays
Filtered images using the real and imaginary parts of the Gabor filter kernel. Images are of the same dimensions as the input one.
References
Examples
>>> import cupy as cp >>> from cucim.skimage.filters import gabor >>> from skimage import data, io >>> from matplotlib import pyplot as plt
>>> image = cp.array(data.coins()) >>> # detecting edges in a coin image >>> filt_real, filt_imag = gabor(image, frequency=0.6) >>> plt.figure() >>> io.imshow(cp.asnumpy(filt_real)) >>> io.show()
>>> # less sensitivity to finer details with the lower frequency kernel >>> filt_real, filt_imag = gabor(image, frequency=0.1) >>> plt.figure() >>> io.imshow(cp.asnumpy(filt_real) >>> io.show()
 cucim.skimage.filters.gabor_kernel(frequency, theta=0, bandwidth=1, sigma_x=None, sigma_y=None, n_stds=3, offset=0, dtype=None, *, float_dtype=None)#
Return complex 2D Gabor filter kernel.
Gabor kernel is a Gaussian kernel modulated by a complex harmonic function. Harmonic function consists of an imaginary sine function and a real cosine function. Spatial frequency is inversely proportional to the wavelength of the harmonic and to the standard deviation of a Gaussian kernel. The bandwidth is also inversely proportional to the standard deviation.
 Parameters
 frequencyfloat
Spatial frequency of the harmonic function. Specified in pixels.
 thetafloat, optional
Orientation in radians. If 0, the harmonic is in the xdirection.
 bandwidthfloat, optional
The bandwidth captured by the filter. For fixed bandwidth,
sigma_x
andsigma_y
will decrease with increasing frequency. This value is ignored ifsigma_x
andsigma_y
are set by the user. sigma_x, sigma_yfloat, optional
Standard deviation in x and ydirections. These directions apply to the kernel before rotation. If theta = pi/2, then the kernel is rotated 90 degrees so that
sigma_x
controls the vertical direction. n_stdsscalar, optional
The linear size of the kernel is n_stds (3 by default) standard deviations
 offsetfloat, optional
Phase offset of harmonic function in radians.
 dtype{np.complex64, np.complex128}
Specifies if the filter is single or double precision complex.
 Returns
 gcomplex array
Complex filter kernel.
References
Examples
>>> import cupy as cp >>> from cucim.skimage.filters import gabor_kernel >>> from skimage import io >>> from matplotlib import pyplot as plt
>>> gk = gabor_kernel(frequency=0.2) >>> plt.figure() >>> io.imshow(cp.asnumpy(gk.real)) >>> io.show()
>>> # more ripples (equivalent to increasing the size of the >>> # Gaussian spread) >>> gk = gabor_kernel(frequency=0.2, bandwidth=0.1) >>> plt.figure() >>> io.imshow(cp.asnumpy(gk.real)) >>> io.show()
 cucim.skimage.filters.gaussian(image, sigma=1, output=None, mode='nearest', cval=0, multichannel=None, preserve_range=False, truncate=4.0, *, channel_axis=None)#
Multidimensional Gaussian filter.
 Parameters
 imagearraylike
Input image (grayscale or color) to filter.
 sigmascalar or sequence of scalars, optional
Standard deviation for Gaussian kernel. The standard deviations of the Gaussian filter are given for each axis as a sequence, or as a single number, in which case it is equal for all axes.
 outputarray, optional
The
output
parameter passes an array in which to store the filter output. mode{‘reflect’, ‘constant’, ‘nearest’, ‘mirror’, ‘wrap’}, optional
The
mode
parameter determines how the array borders are handled, wherecval
is the value when mode is equal to ‘constant’. Default is ‘nearest’. cvalscalar, optional
Value to fill past edges of input if
mode
is ‘constant’. Default is 0.0 multichannelbool, optional (default: None)
Whether the last axis of the image is to be interpreted as multiple channels. If True, each channel is filtered separately (channels are not mixed together). Only 3 channels are supported. If
None
, the function will attempt to guess this, and raise a warning if ambiguous, when the array has shape (M, N, 3). This argument is deprecated: specify channel_axis instead. preserve_rangebool, optional
Whether to keep the original range of values. Otherwise, the input image is converted according to the conventions of
img_as_float
. Also see https://scikitimage.org/docs/dev/user_guide/data_types.html truncatefloat, optional
Truncate the filter at this many standard deviations.
 channel_axisint or None, optional
If None, the image is assumed to be a grayscale (single channel) image. Otherwise, this parameter indicates which axis of the array corresponds to channels.
 Returns
 filtered_imagendarray
the filtered array
 Other Parameters
 multichannelDEPRECATED
Deprecated in favor of channel_axis.
Deprecated since version 0.19.
Notes
This function is a wrapper around
scipy.ndi.gaussian_filter()
.Integer arrays are converted to float.
The
output
should be floating point data type since gaussian converts to float providedimage
. Ifoutput
is not provided, another array will be allocated and returned as the result.The multidimensional filter is implemented as a sequence of onedimensional convolution filters. The intermediate arrays are stored in the same data type as the output. Therefore, for output types with a limited precision, the results may be imprecise because intermediate results may be stored with insufficient precision.
Examples
>>> import cupy as cp >>> a = cp.zeros((3, 3)) >>> a[1, 1] = 1 >>> a array([[0., 0., 0.], [0., 1., 0.], [0., 0., 0.]]) >>> gaussian(a, sigma=0.4) # mild smoothing array([[0.00163116, 0.03712502, 0.00163116], [0.03712502, 0.84496158, 0.03712502], [0.00163116, 0.03712502, 0.00163116]]) >>> gaussian(a, sigma=1) # more smoothing array([[0.05855018, 0.09653293, 0.05855018], [0.09653293, 0.15915589, 0.09653293], [0.05855018, 0.09653293, 0.05855018]]) >>> # Several modes are possible for handling boundaries >>> gaussian(a, sigma=1, mode='reflect') array([[0.08767308, 0.12075024, 0.08767308], [0.12075024, 0.16630671, 0.12075024], [0.08767308, 0.12075024, 0.08767308]]) >>> # For RGB images, each is filtered separately >>> from skimage.data import astronaut >>> image = cp.array(astronaut()) >>> filtered_img = gaussian(image, sigma=1, channel_axis=1)
 cucim.skimage.filters.hessian(image, sigmas=range(1, 10, 2), scale_range=None, scale_step=None, alpha=0.5, beta=0.5, gamma=15, black_ridges=True, mode='reflect', cval=0)#
Filter an image with the Hybrid Hessian filter.
This filter can be used to detect continuous edges, e.g. vessels, wrinkles, rivers. It can be used to calculate the fraction of the whole image containing such objects.
Defined only for 2D and 3D images. Almost equal to Frangi filter, but uses alternative method of smoothing. Refer to [1] to find the differences between Frangi and Hessian filters.
 Parameters
 image(N, M[, P]) ndarray
Array with input image data.
 sigmasiterable of floats, optional
Sigmas used as scales of filter, i.e., np.arange(scale_range[0], scale_range[1], scale_step)
 scale_range2tuple of floats, optional
The range of sigmas used.
 scale_stepfloat, optional
Step size between sigmas.
 betafloat, optional
Frangi correction constant that adjusts the filter’s sensitivity to deviation from a bloblike structure.
 gammafloat, optional
Frangi correction constant that adjusts the filter’s sensitivity to areas of high variance/texture/structure.
 black_ridgesboolean, optional
When True (the default), the filter detects black ridges; when False, it detects white ridges.
 mode{‘constant’, ‘reflect’, ‘wrap’, ‘nearest’, ‘mirror’}, optional
How to handle values outside the image borders.
 cvalfloat, optional
Used in conjunction with mode ‘constant’, the value outside the image boundaries.
 Returns
 out(N, M[, P]) ndarray
Filtered image (maximum of pixels across all scales).
Notes
Written by Marc Schrijver (November 2001) ReWritten by D. J. Kroon University of Twente (May 2009) [2]
References
 1
Ng, C. C., Yap, M. H., Costen, N., & Li, B. (2014,). Automatic wrinkle detection using hybrid Hessian filter. In Asian Conference on Computer Vision (pp. 609622). Springer International Publishing. DOI:10.1007/9783319168111_40
 2
Kroon, D. J.: Hessian based Frangi vesselness filter.
 cucim.skimage.filters.inverse(data, impulse_response=None, filter_params={}, max_gain=2, predefined_filter=None)#
Apply the filter in reverse to the given data.
 Parameters
 data(M,N) ndarray
Input data.
 impulse_responsecallable f(r, c, **filter_params)
Impulse response of the filter. See LPIFilter2D.__init__.
 filter_paramsdict
Additional keyword parameters to the impulse_response function.
 max_gainfloat
Limit the filter gain. Often, the filter contains zeros, which would cause the inverse filter to have infinite gain. High gain causes amplification of artefacts, so a conservative limit is recommended.
 Other Parameters
 predefined_filterLPIFilter2D
If you need to apply the same filter multiple times over different images, construct the LPIFilter2D and specify it here.
 cucim.skimage.filters.laplace(image, ksize=3, mask=None)#
Find the edges of an image using the Laplace operator.
 Parameters
 imagendarray
Image to process.
 ksizeint, optional
Define the size of the discrete Laplacian operator such that it will have a size of (ksize,) * image.ndim.
 maskndarray, optional
An optional mask to limit the application to a certain area. Note that pixels surrounding masked regions are also masked to prevent masked regions from affecting the result.
 Returns
 outputndarray
The Laplace edge map.
Notes
The Laplacian operator is generated using the function skimage.restoration.uft.laplacian().
 cucim.skimage.filters.median(image, footprint=None, out=None, mode='nearest', cval=0.0, behavior='ndimage')#
Return local median of an image.
 Parameters
 imagearraylike
Input image.
 footprintndarray, optional
If
behavior=='rank'
,footprint
is a 2D array of 1’s and 0’s. Ifbehavior=='ndimage'
,footprint
is a ND array of 1’s and 0’s with the same number of dimension thanimage
. If None,footprint
will be a ND array with 3 elements for each dimension (e.g., vector, square, cube, etc.) outndarray, (same dtype as image), optional
If None, a new array is allocated.
 mode{‘reflect’, ‘constant’, ‘nearest’, ‘mirror’,’‘wrap’}, optional
The mode parameter determines how the array borders are handled, where
cval
is the value when mode is equal to ‘constant’. Default is ‘nearest’.New in version 0.15:
mode
is used whenbehavior='ndimage'
. cvalscalar, optional
Value to fill past edges of input if mode is ‘constant’. Default is 0.0
New in version 0.15:
cval
was added in 0.15 is used whenbehavior='ndimage'
. behavior{‘ndimage’, ‘rank’}, optional
Either to use the old behavior (i.e., < 0.15) or the new behavior. The old behavior will call the
skimage.filters.rank.median()
. The new behavior will call thescipy.ndimage.median_filter()
. Default is ‘ndimage’.New in version 0.15:
behavior
is introduced in 0.15Changed in version 0.16: Default
behavior
has been changed from ‘rank’ to ‘ndimage’
 Returns
 out2D array (same dtype as input image)
Output image.
 Other Parameters
 selemDEPRECATED
Deprecated in favor of footprint.
Deprecated since version 0.19.
See also
skimage.filters.rank.median()
Rankbased implementation of the median filtering offering more flexibility with additional parameters but dedicated for unsigned integer images.
Examples
>>> import cupy as cp >>> from skimage import data >>> from cucim.skimage.morphology import disk >>> from cucim.skimage.filters import median >>> img = cp.array(data.camera()) >>> med = median(img, disk(5))
 cucim.skimage.filters.meijering(image, sigmas=range(1, 10, 2), alpha=None, black_ridges=True, mode='reflect', cval=0)#
Filter an image with the Meijering neuriteness filter.
This filter can be used to detect continuous ridges, e.g. neurites, wrinkles, rivers. It can be used to calculate the fraction of the whole image containing such objects.
Calculates the eigenvectors of the Hessian to compute the similarity of an image region to neurites, according to the method described in [1].
 Parameters
 image(N, M[, …, P]) ndarray
Array with input image data.
 sigmasiterable of floats, optional
Sigmas used as scales of filter
 alphafloat, optional
Frangi correction constant that adjusts the filter’s sensitivity to deviation from a platelike structure.
 black_ridgesboolean, optional
When True (the default), the filter detects black ridges; when False, it detects white ridges.
 mode{‘constant’, ‘reflect’, ‘wrap’, ‘nearest’, ‘mirror’}, optional
How to handle values outside the image borders.
 cvalfloat, optional
Used in conjunction with mode ‘constant’, the value outside the image boundaries.
 Returns
 out(N, M[, …, P]) ndarray
Filtered image (maximum of pixels across all scales).
References
 1
Meijering, E., Jacob, M., Sarria, J. C., Steiner, P., Hirling, H., Unser, M. (2004). Design and validation of a tool for neurite tracing and analysis in fluorescence microscopy images. Cytometry Part A, 58(2), 167176. DOI:10.1002/cyto.a.20022
 cucim.skimage.filters.prewitt(image, mask=None, *, axis=None, mode='reflect', cval=0.0)#
Find the edge magnitude using the Prewitt transform.
 Parameters
 imagearray
The input image.
 maskarray of bool, optional
Clip the output image to this mask. (Values where mask=0 will be set to 0.)
 axisint or sequence of int, optional
Compute the edge filter along this axis. If not provided, the edge magnitude is computed. This is defined as:
prw_mag = np.sqrt(sum([prewitt(image, axis=i)**2 for i in range(image.ndim)]) / image.ndim)
The magnitude is also computed if axis is a sequence.
 modestr or sequence of str, optional
The boundary mode for the convolution. See scipy.ndimage.convolve for a description of the modes. This can be either a single boundary mode or one boundary mode per axis.
 cvalfloat, optional
When mode is
'constant'
, this is the constant used in values outside the boundary of the image data.
 Returns
 outputarray of float
The Prewitt edge map.
See also
Notes
The edge magnitude depends slightly on edge directions, since the approximation of the gradient operator by the Prewitt operator is not completely rotation invariant. For a better rotation invariance, the Scharr operator should be used. The Sobel operator has a better rotation invariance than the Prewitt operator, but a worse rotation invariance than the Scharr operator.
Examples
>>> import cupy as cp >>> from skimage import data >>> from cucim.skimage import filters >>> camera = cp.array(data.camera()) >>> edges = filters.prewitt(camera)
 cucim.skimage.filters.prewitt_h(image, mask=None)#
Find the horizontal edges of an image using the Prewitt transform.
 Parameters
 image2D array
Image to process.
 mask2D array, optional
An optional mask to limit the application to a certain area. Note that pixels surrounding masked regions are also masked to prevent masked regions from affecting the result.
 Returns
 output2D array
The Prewitt edge map.
Notes
We use the following kernel:
1/3 1/3 1/3 0 0 0 1/3 1/3 1/3
 cucim.skimage.filters.prewitt_v(image, mask=None)#
Find the vertical edges of an image using the Prewitt transform.
 Parameters
 image2D array
Image to process.
 mask2D array, optional
An optional mask to limit the application to a certain area. Note that pixels surrounding masked regions are also masked to prevent masked regions from affecting the result.
 Returns
 output2D array
The Prewitt edge map.
Notes
We use the following kernel:
1/3 0 1/3 1/3 0 1/3 1/3 0 1/3
 cucim.skimage.filters.rank_order(image)#
Return an image of the same shape where each pixel is the index of the pixel value in the ascending order of the unique values of
image
, aka the rankorder value. Parameters
 imagendarray
 Returns
 labelsndarray of type np.uint32, of shape image.shape
New array where each pixel has the rankorder value of the corresponding pixel in
image
. Pixel values are between 0 and n  1, where n is the number of distinct unique values inimage
. original_values1D ndarray
Unique original values of
image
Examples
>>> a = cp.asarray([[1, 4, 5], [4, 4, 1], [5, 1, 1]]) >>> a array([[1, 4, 5], [4, 4, 1], [5, 1, 1]]) >>> rank_order(a) (array([[0, 1, 2], [1, 1, 0], [2, 0, 0]], dtype=uint32), array([1, 4, 5])) >>> b = cp.asarray([1., 2.5, 3.1, 2.5]) >>> rank_order(b) (array([0, 1, 2, 1], dtype=uint32), array([1. , 2.5, 3.1]))
 cucim.skimage.filters.roberts(image, mask=None)#
Find the edge magnitude using Roberts’ cross operator.
 Parameters
 image2D array
Image to process.
 mask2D array, optional
An optional mask to limit the application to a certain area. Note that pixels surrounding masked regions are also masked to prevent masked regions from affecting the result.
 Returns
 output2D array
The Roberts’ Cross edge map.
See also
roberts_pos_diag
,roberts_neg_diag
diagonal edge detection.
sobel
,scharr
,prewitt
,cucim.skimage.feature.canny
Examples
>>> import cupy as cp >>> from skimage import data >>> camera = cp.array(data.camera()) >>> from cucim.skimage import filters >>> edges = filters.roberts(camera)
 cucim.skimage.filters.roberts_neg_diag(image, mask=None)#
Find the cross edges of an image using the Roberts’ Cross operator.
The kernel is applied to the input image to produce separate measurements of the gradient component one orientation.
 Parameters
 image2D array
Image to process.
 mask2D array, optional
An optional mask to limit the application to a certain area. Note that pixels surrounding masked regions are also masked to prevent masked regions from affecting the result.
 Returns
 output2D array
The Robert’s edge map.
Notes
We use the following kernel:
0 1 1 0
 cucim.skimage.filters.roberts_pos_diag(image, mask=None)#
Find the cross edges of an image using Roberts’ cross operator.
The kernel is applied to the input image to produce separate measurements of the gradient component one orientation.
 Parameters
 image2D array
Image to process.
 mask2D array, optional
An optional mask to limit the application to a certain area. Note that pixels surrounding masked regions are also masked to prevent masked regions from affecting the result.
 Returns
 output2D array
The Robert’s edge map.
Notes
We use the following kernel:
1 0 0 1
 cucim.skimage.filters.sato(image, sigmas=range(1, 10, 2), black_ridges=True, mode='reflect', cval=0)#
Filter an image with the Sato tubeness filter.
This filter can be used to detect continuous ridges, e.g. tubes, wrinkles, rivers. It can be used to calculate the fraction of the whole image containing such objects.
Defined only for 2D and 3D images. Calculates the eigenvectors of the Hessian to compute the similarity of an image region to tubes, according to the method described in [1].
 Parameters
 image(N, M[, P]) ndarray
Array with input image data.
 sigmasiterable of floats, optional
Sigmas used as scales of filter.
 black_ridgesboolean, optional
When True (the default), the filter detects black ridges; when False, it detects white ridges.
 mode{‘constant’, ‘reflect’, ‘wrap’, ‘nearest’, ‘mirror’}, optional
How to handle values outside the image borders.
 cvalfloat, optional
Used in conjunction with mode ‘constant’, the value outside the image boundaries.
 Returns
 out(N, M[, P]) ndarray
Filtered image (maximum of pixels across all scales).
References
 1
Sato, Y., Nakajima, S., Shiraga, N., Atsumi, H., Yoshida, S., Koller, T., …, Kikinis, R. (1998). Threedimensional multiscale line filter for segmentation and visualization of curvilinear structures in medical images. Medical image analysis, 2(2), 143168. DOI:10.1016/S13618415(98)800091
 cucim.skimage.filters.scharr(image, mask=None, *, axis=None, mode='reflect', cval=0.0)#
Find the edge magnitude using the Scharr transform.
 Parameters
 imagearray
The input image.
 maskarray of bool, optional
Clip the output image to this mask. (Values where mask=0 will be set to 0.)
 axisint or sequence of int, optional
Compute the edge filter along this axis. If not provided, the edge magnitude is computed. This is defined as:
sch_mag = np.sqrt(sum([scharr(image, axis=i)**2 for i in range(image.ndim)]) / image.ndim)
The magnitude is also computed if axis is a sequence.
 modestr or sequence of str, optional
The boundary mode for the convolution. See scipy.ndimage.convolve for a description of the modes. This can be either a single boundary mode or one boundary mode per axis.
 cvalfloat, optional
When mode is
'constant'
, this is the constant used in values outside the boundary of the image data.
 Returns
 outputarray of float
The Scharr edge map.
See also
Notes
The Scharr operator has a better rotation invariance than other edge filters such as the Sobel or the Prewitt operators.
References
 1
D. Kroon, 2009, Short Paper University Twente, Numerical Optimization of Kernel Based Image Derivatives.
 2
https://en.wikipedia.org/wiki/Sobel_operator#Alternative_operators
Examples
>>> import cupy as cp >>> from skimage import data >>> from cucim.skimage import filters >>> camera = cp.array(data.camera()) >>> edges = filters.scharr(camera)
 cucim.skimage.filters.scharr_h(image, mask=None)#
Find the horizontal edges of an image using the Scharr transform.
 Parameters
 image2D array
Image to process.
 mask2D array, optional
An optional mask to limit the application to a certain area. Note that pixels surrounding masked regions are also masked to prevent masked regions from affecting the result.
 Returns
 output2D array
The Scharr edge map.
Notes
We use the following kernel:
3 10 3 0 0 0 3 10 3
References
 1
D. Kroon, 2009, Short Paper University Twente, Numerical Optimization of Kernel Based Image Derivatives.
 cucim.skimage.filters.scharr_v(image, mask=None)#
Find the vertical edges of an image using the Scharr transform.
 Parameters
 image2D array
Image to process
 mask2D array, optional
An optional mask to limit the application to a certain area. Note that pixels surrounding masked regions are also masked to prevent masked regions from affecting the result.
 Returns
 output2D array
The Scharr edge map.
Notes
We use the following kernel:
3 0 3 10 0 10 3 0 3
References
 1
D. Kroon, 2009, Short Paper University Twente, Numerical Optimization of Kernel Based Image Derivatives.
 cucim.skimage.filters.sobel(image, mask=None, *, axis=None, mode='reflect', cval=0.0)#
Find edges in an image using the Sobel filter.
 Parameters
 imagearray
The input image.
 maskarray of bool, optional
Clip the output image to this mask. (Values where mask=0 will be set to 0.)
 axisint or sequence of int, optional
Compute the edge filter along this axis. If not provided, the edge magnitude is computed. This is defined as:
sobel_mag = np.sqrt(sum([sobel(image, axis=i)**2 for i in range(image.ndim)]) / image.ndim)
The magnitude is also computed if axis is a sequence.
 modestr or sequence of str, optional
The boundary mode for the convolution. See scipy.ndimage.convolve for a description of the modes. This can be either a single boundary mode or one boundary mode per axis.
 cvalfloat, optional
When mode is
'constant'
, this is the constant used in values outside the boundary of the image data.
 Returns
 outputarray of float
The Sobel edge map.
See also
References
 1
D. Kroon, 2009, Short Paper University Twente, Numerical Optimization of Kernel Based Image Derivatives.
 2
Examples
>>> import cupy as cp >>> from skimage import data >>> from cucim.skimage import filters >>> camera = cp.array(data.camera()) >>> edges = filters.sobel(camera)
 cucim.skimage.filters.sobel_h(image, mask=None)#
Find the horizontal edges of an image using the Sobel transform.
 Parameters
 image2D array
Image to process.
 mask2D array, optional
An optional mask to limit the application to a certain area. Note that pixels surrounding masked regions are also masked to prevent masked regions from affecting the result.
 Returns
 output2D array
The Sobel edge map.
Notes
We use the following kernel:
1 2 1 0 0 0 1 2 1
 cucim.skimage.filters.sobel_v(image, mask=None)#
Find the vertical edges of an image using the Sobel transform.
 Parameters
 image2D array
Image to process.
 mask2D array, optional
An optional mask to limit the application to a certain area. Note that pixels surrounding masked regions are also masked to prevent masked regions from affecting the result.
 Returns
 output2D array
The Sobel edge map.
Notes
We use the following kernel:
1 0 1 2 0 2 1 0 1
 cucim.skimage.filters.threshold_isodata(image=None, nbins=256, return_all=False, *, hist=None)#
Return threshold value(s) based on ISODATA method.
Histogrambased threshold, known as RidlerCalvard method or intermeans. Threshold values returned satisfy the following equality:
threshold = (image[image <= threshold].mean() + image[image > threshold].mean()) / 2.0
That is, returned thresholds are intensities that separate the image into two groups of pixels, where the threshold intensity is midway between the mean intensities of these groups.
For integer images, the above equality holds to within one; for floating point images, the equality holds to within the histogram binwidth.
Either image or hist must be provided. In case hist is given, the actual histogram of the image is ignored.
 Parameters
 image(N, M[, …, P]) ndarray
Grayscale input image.
 nbinsint, optional
Number of bins used to calculate histogram. This value is ignored for integer arrays.
 return_allbool, optional
If False (default), return only the lowest threshold that satisfies the above equality. If True, return all valid thresholds.
 histarray, or 2tuple of arrays, optional
Histogram to determine the threshold from and a corresponding array of bin center intensities. Alternatively, only the histogram can be passed.
 Returns
 thresholdfloat or int or array
Threshold value(s).
References
 1
Ridler, TW & Calvard, S (1978), “Picture thresholding using an iterative selection method” IEEE Transactions on Systems, Man and Cybernetics 8: 630632, DOI:10.1109/TSMC.1978.4310039
 2
Sezgin M. and Sankur B. (2004) “Survey over Image Thresholding Techniques and Quantitative Performance Evaluation” Journal of Electronic Imaging, 13(1): 146165, http://www.busim.ee.boun.edu.tr/~sankur/SankurFolder/Threshold_survey.pdf DOI:10.1117/1.1631315
 3
ImageJ AutoThresholder code, http://fiji.sc/wiki/index.php/Auto_Threshold
Examples
>>> from skimage.data import coins >>> image = cp.array(coins()) >>> thresh = threshold_isodata(image) >>> binary = image > thresh
 cucim.skimage.filters.threshold_li(image, *, tolerance=None, initial_guess=None, iter_callback=None)#
Compute threshold value by Li’s iterative Minimum Cross Entropy method.
 Parameters
 image(N, M[, …, P]) ndarray
Grayscale input image.
 tolerancefloat, optional
Finish the computation when the change in the threshold in an iteration is less than this value. By default, this is half the smallest difference between intensity values in
image
. initial_guessfloat or Callable[[array[float]], float], optional
Li’s iterative method uses gradient descent to find the optimal threshold. If the image intensity histogram contains more than two modes (peaks), the gradient descent could get stuck in a local optimum. An initial guess for the iteration can help the algorithm find the globallyoptimal threshold. A float value defines a specific start point, while a callable should take in an array of image intensities and return a float value. Example valid callables include
numpy.mean
(default),lambda arr: numpy.quantile(arr, 0.95)
, or evenskimage.filters.threshold_otsu()
. iter_callbackCallable[[float], Any], optional
A function that will be called on the threshold at every iteration of the algorithm.
 Returns
 thresholdfloat
Upper threshold value. All pixels with an intensity higher than this value are assumed to be foreground.
References
 1
Li C.H. and Lee C.K. (1993) “Minimum Cross Entropy Thresholding” Pattern Recognition, 26(4): 617625 DOI:10.1016/00313203(93)90115D
 2
Li C.H. and Tam P.K.S. (1998) “An Iterative Algorithm for Minimum Cross Entropy Thresholding” Pattern Recognition Letters, 18(8): 771776 DOI:10.1016/S01678655(98)000579
 3
Sezgin M. and Sankur B. (2004) “Survey over Image Thresholding Techniques and Quantitative Performance Evaluation” Journal of Electronic Imaging, 13(1): 146165 DOI:10.1117/1.1631315
 4
ImageJ AutoThresholder code, http://fiji.sc/wiki/index.php/Auto_Threshold
Examples
>>> from skimage.data import camera >>> image = cp.array(camera()) >>> thresh = threshold_li(image) >>> binary = image > thresh
 cucim.skimage.filters.threshold_local(image, block_size=3, method='gaussian', offset=0, mode='reflect', param=None, cval=0)#
Compute a threshold mask image based on local pixel neighborhood.
Also known as adaptive or dynamic thresholding. The threshold value is the weighted mean for the local neighborhood of a pixel subtracted by a constant. Alternatively the threshold can be determined dynamically by a given function, using the ‘generic’ method.
 Parameters
 image(N, M[, …, P]) ndarray
Grayscale input image.
 block_sizeint or sequence of int
Odd size of pixel neighborhood which is used to calculate the threshold value (e.g. 3, 5, 7, …, 21, …).
 method{‘generic’, ‘gaussian’, ‘mean’, ‘median’}, optional
Method used to determine adaptive threshold for local neighbourhood in weighted mean image.
‘generic’: use custom function (see
param
parameter)‘gaussian’: apply gaussian filter (see
param
parameter for custom sigma value)‘mean’: apply arithmetic mean filter
‘median’: apply median rank filter
By default the ‘gaussian’ method is used.
 offsetfloat, optional
Constant subtracted from weighted mean of neighborhood to calculate the local threshold value. Default offset is 0.
 mode{‘reflect’, ‘constant’, ‘nearest’, ‘mirror’, ‘wrap’}, optional
The mode parameter determines how the array borders are handled, where cval is the value when mode is equal to ‘constant’. Default is ‘reflect’.
 param{int, function}, optional
Either specify sigma for ‘gaussian’ method or function object for ‘generic’ method. This functions takes the flat array of local neighbourhood as a single argument and returns the calculated threshold for the centre pixel.
 cvalfloat, optional
Value to fill past edges of input if mode is ‘constant’.
 Returns
 threshold(N, M[, …, P]) ndarray
Threshold image. All pixels in the input image higher than the corresponding pixel in the threshold image are considered foreground.
References
 1
Gonzalez, R. C. and Wood, R. E. “Digital Image Processing (2nd Edition).” PrenticeHall Inc., 2002: 600–612. ISBN: 0201180758
Examples
>>> import cupy as cp >>> from skimage.data import camera >>> image = cp.array(camera()[:50, :50]) >>> binary_image1 = image > threshold_local(image, 15, 'mean')
 cucim.skimage.filters.threshold_mean(image)#
Return threshold value based on the mean of grayscale values.
 Parameters
 image(N, M[, …, P]) ndarray
Grayscale input image.
 Returns
 thresholdfloat
Upper threshold value. All pixels with an intensity higher than this value are assumed to be foreground.
References
 1
C. A. Glasbey, “An analysis of histogrambased thresholding algorithms,” CVGIP: Graphical Models and Image Processing, vol. 55, pp. 532537, 1993. DOI:10.1006/cgip.1993.1040
Examples
>>> from skimage.data import camera >>> image = cp.array(camera()) >>> thresh = threshold_mean(image) >>> binary = image > thresh
 cucim.skimage.filters.threshold_minimum(image=None, nbins=256, max_num_iter=10000, *, hist=None)#
Return threshold value based on minimum method.
The histogram of the input
image
is computed if not provided and smoothed until there are only two maxima. Then the minimum in between is the threshold value.Either image or hist must be provided. In case hist is given, the actual histogram of the image is ignored.
 Parameters
 image(N, M[, …, P]) ndarray, optional
Grayscale input image.
 nbinsint, optional
Number of bins used to calculate histogram. This value is ignored for integer arrays.
 max_num_iterint, optional
Maximum number of iterations to smooth the histogram.
 histarray, or 2tuple of arrays, optional
Histogram to determine the threshold from and a corresponding array of bin center intensities. Alternatively, only the histogram can be passed.
 Returns
 thresholdfloat
Upper threshold value. All pixels with an intensity higher than this value are assumed to be foreground.
 Other Parameters
 max_iterDEPRECATED
Deprecated in favor of max_num_iter.
Deprecated since version 0.19.
 Raises
 RuntimeError
If unable to find two local maxima in the histogram or if the smoothing takes more than 1e4 iterations.
References
 1
C. A. Glasbey, “An analysis of histogrambased thresholding algorithms,” CVGIP: Graphical Models and Image Processing, vol. 55, pp. 532537, 1993.
 2
Prewitt, JMS & Mendelsohn, ML (1966), “The analysis of cell images”, Annals of the New York Academy of Sciences 128: 10351053 DOI:10.1111/j.17496632.1965.tb11715.x
Examples
>>> from skimage.data import camera >>> image = cp.array(camera()) >>> thresh = threshold_minimum(image) >>> binary = image > thresh
 cucim.skimage.filters.threshold_multiotsu(image=None, classes=3, nbins=256, *, hist=None)#
Generate classes1 threshold values to divide gray levels in image, following Otsu’s method for multiple classes.
The threshold values are chosen to maximize the total sum of pairwise variances between the thresholded graylevel classes. See Notes and [1] for more details.
Either image or hist must be provided. If hist is provided, the actual histogram of the image is ignored.
 Parameters
 image(N, M[, …, P]) ndarray, optional
Grayscale input image.
 classesint, optional
Number of classes to be thresholded, i.e. the number of resulting regions.
 nbinsint, optional
Number of bins used to calculate the histogram. This value is ignored for integer arrays.
 histarray, or 2tuple of arrays, optional
Histogram from which to determine the threshold, and optionally a corresponding array of bin center intensities. If no hist provided, this function will compute it from the image (see notes).
 Returns
 thresharray
Array containing the threshold values for the desired classes.
 Raises
 ValueError
If
image
contains less grayscale value then the desired number of classes.
Notes
This implementation relies on a Cython function whose complexity is \(O\left(\frac{Ch^{C1}}{(C1)!}\right)\), where \(h\) is the number of histogram bins and \(C\) is the number of classes desired.
If no hist is given, this function will make use of skimage.exposure.histogram, which behaves differently than np.histogram. While both allowed, use the former for consistent behaviour.
The input image must be grayscale.
References
 1
Liao, PS., Chen, TS. and Chung, PC., “A fast algorithm for multilevel thresholding”, Journal of Information Science and Engineering 17 (5): 713727, 2001. Available at: <https://ftp.iis.sinica.edu.tw/JISE/2001/200109_01.pdf> DOI:10.6688/JISE.2001.17.5.1
 2
Tosa, Y., “MultiOtsu Threshold”, a java plugin for ImageJ. Available at: <http://imagej.net/plugins/download/Multi_OtsuThreshold.java>
Examples
>>> import cupy as cp >>> from cucim.skimage.color import label2rgb >>> from skimage import data >>> image = cp.asarray(data.camera()) >>> thresholds = threshold_multiotsu(image) >>> regions = cp.digitize(image, bins=thresholds) >>> regions_colorized = label2rgb(regions)
 cucim.skimage.filters.threshold_niblack(image, window_size=15, k=0.2)#
Applies Niblack local threshold to an array.
A threshold T is calculated for every pixel in the image using the following formula:
T = m(x,y)  k * s(x,y)
where m(x,y) and s(x,y) are the mean and standard deviation of pixel (x,y) neighborhood defined by a rectangular window with size w times w centered around the pixel. k is a configurable parameter that weights the effect of standard deviation.
 Parameters
 image(N, M[, …, P]) ndarray
Grayscale input image.
 window_sizeint, or iterable of int, optional
Window size specified as a single odd integer (3, 5, 7, …), or an iterable of length
image.ndim
containing only odd integers (e.g.(1, 5, 5)
). kfloat, optional
Value of parameter k in threshold formula.
 Returns
 threshold(N, M) ndarray
Threshold mask. All pixels with an intensity higher than this value are assumed to be foreground.
Notes
This algorithm is originally designed for text recognition.
The Bradley threshold is a particular case of the Niblack one, being equivalent to
>>> from skimage import data >>> image = cp.array(data.page()) >>> q = 1 >>> threshold_image = threshold_niblack(image, k=0) * q
for some value
q
. By default, Bradley and Roth useq=1
.References
 1
W. Niblack, An introduction to Digital Image Processing, PrenticeHall, 1986.
 2
D. Bradley and G. Roth, “Adaptive thresholding using Integral Image”, Journal of Graphics Tools 12(2), pp. 1321, 2007. DOI:10.1080/2151237X.2007.10129236
Examples
>>> from skimage import data >>> image = cp.array(data.page()) >>> threshold_image = threshold_niblack(image, window_size=7, k=0.1)
 cucim.skimage.filters.threshold_otsu(image=None, nbins=256, *, hist=None)#
Return threshold value based on Otsu’s method.
Either image or hist must be provided. If hist is provided, the actual histogram of the image is ignored.
 Parameters
 image(N, M[, …, P]) ndarray, optional
Grayscale input image.
 nbinsint, optional
Number of bins used to calculate histogram. This value is ignored for integer arrays.
 histarray, or 2tuple of arrays, optional
Histogram from which to determine the threshold, and optionally a corresponding array of bin center intensities. If no hist provided, this function will compute it from the image.
 Returns
 thresholdfloat
Upper threshold value. All pixels with an intensity higher than this value are assumed to be foreground.
Notes
The input image must be grayscale.
References
 1
Wikipedia, https://en.wikipedia.org/wiki/Otsu’s_Method
Examples
>>> from skimage.data import camera >>> image = cp.array(camera()) >>> thresh = threshold_otsu(image) >>> binary = image <= thresh
 cucim.skimage.filters.threshold_sauvola(image, window_size=15, k=0.2, r=None)#
Applies Sauvola local threshold to an array. Sauvola is a modification of Niblack technique.
In the original method a threshold T is calculated for every pixel in the image using the following formula:
T = m(x,y) * (1 + k * ((s(x,y) / R)  1))
where m(x,y) and s(x,y) are the mean and standard deviation of pixel (x,y) neighborhood defined by a rectangular window with size w times w centered around the pixel. k is a configurable parameter that weights the effect of standard deviation. R is the maximum standard deviation of a grayscale image.
 Parameters
 image(N, M[, …, P]) ndarray
Grayscale input image.
 window_sizeint, or iterable of int, optional
Window size specified as a single odd integer (3, 5, 7, …), or an iterable of length
image.ndim
containing only odd integers (e.g.(1, 5, 5)
). kfloat, optional
Value of the positive parameter k.
 rfloat, optional
Value of R, the dynamic range of standard deviation. If None, set to the half of the image dtype range.
 Returns
 threshold(N, M) ndarray
Threshold mask. All pixels with an intensity higher than this value are assumed to be foreground.
Notes
This algorithm is originally designed for text recognition.
References
 1
J. Sauvola and M. Pietikainen, “Adaptive document image binarization,” Pattern Recognition 33(2), pp. 225236, 2000. DOI:10.1016/S00313203(99)000552
Examples
>>> from skimage import data >>> image = cp.array(data.page()) >>> t_sauvola = threshold_sauvola(image, window_size=15, k=0.2) >>> binary_image = image > t_sauvola
 cucim.skimage.filters.threshold_triangle(image, nbins=256)#
Return threshold value based on the triangle algorithm.
 Parameters
 image(N, M[, …, P]) ndarray
Grayscale input image.
 nbinsint, optional
Number of bins used to calculate histogram. This value is ignored for integer arrays.
 Returns
 thresholdfloat
Upper threshold value. All pixels with an intensity higher than this value are assumed to be foreground.
References
 1
Zack, G. W., Rogers, W. E. and Latt, S. A., 1977, Automatic Measurement of Sister Chromatid Exchange Frequency, Journal of Histochemistry and Cytochemistry 25 (7), pp. 741753 DOI:10.1177/25.7.70454
 2
ImageJ AutoThresholder code, http://fiji.sc/wiki/index.php/Auto_Threshold
Examples
>>> from skimage.data import camera >>> image = cp.array(camera()) >>> thresh = threshold_triangle(image) >>> binary = image > thresh
 cucim.skimage.filters.threshold_yen(image=None, nbins=256, *, hist=None)#
Return threshold value based on Yen’s method. Either image or hist must be provided. In case hist is given, the actual histogram of the image is ignored.
 Parameters
 image(N, M[, …, P]) ndarray
Grayscale input image.
 nbinsint, optional
Number of bins used to calculate histogram. This value is ignored for integer arrays.
 histarray, or 2tuple of arrays, optional
Histogram from which to determine the threshold, and optionally a corresponding array of bin center intensities. An alternative use of this function is to pass it only hist.
 Returns
 thresholdfloat
Upper threshold value. All pixels with an intensity higher than this value are assumed to be foreground.
References
 1
Yen J.C., Chang F.J., and Chang S. (1995) “A New Criterion for Automatic Multilevel Thresholding” IEEE Trans. on Image Processing, 4(3): 370378. DOI:10.1109/83.366472
 2
Sezgin M. and Sankur B. (2004) “Survey over Image Thresholding Techniques and Quantitative Performance Evaluation” Journal of Electronic Imaging, 13(1): 146165, DOI:10.1117/1.1631315 http://www.busim.ee.boun.edu.tr/~sankur/SankurFolder/Threshold_survey.pdf
 3
ImageJ AutoThresholder code, http://fiji.sc/wiki/index.php/Auto_Threshold
Examples
>>> from skimage.data import camera >>> image = cp.array(camera()) >>> thresh = threshold_yen(image) >>> binary = image <= thresh
 cucim.skimage.filters.try_all_threshold(image, figsize=(8, 5), verbose=True)#
Returns a figure comparing the outputs of different thresholding methods.
 Parameters
 image(N, M) ndarray
Input image.
 figsizetuple, optional
Figure size (in inches).
 verbosebool, optional
Print function name for each method.
 Returns
 fig, axtuple
Matplotlib figure and axes.
Notes
The following algorithms are used:
isodata
li
mean
minimum
otsu
triangle
yen
Examples
>>> from skimage.data import text >>> text_img = cp.array(text()) >>> fig, ax = try_all_threshold(text_img, figsize=(10, 6), verbose=False)
 cucim.skimage.filters.unsharp_mask(image, radius=1.0, amount=1.0, multichannel=False, preserve_range=False, *, channel_axis=None)#
Unsharp masking filter.
The sharp details are identified as the difference between the original image and its blurred version. These details are then scaled, and added back to the original image.
 Parameters
 image[P, …, ]M[, N][, C] ndarray
Input image.
 radiusscalar or sequence of scalars, optional
If a scalar is given, then its value is used for all dimensions. If sequence is given, then there must be exactly one radius for each dimension except the last dimension for multichannel images. Note that 0 radius means no blurring, and negative values are not allowed.
 amountscalar, optional
The details will be amplified with this factor. The factor could be 0 or negative. Typically, it is a small positive number, e.g. 1.0.
 multichannelbool, optional
If True, the last
image
dimension is considered as a color channel, otherwise as spatial. Color channels are processed individually. This argument is deprecated: specify channel_axis instead. preserve_rangebool, optional
Whether to keep the original range of values. Otherwise, the input image is converted according to the conventions of
img_as_float
. Also see https://scikitimage.org/docs/dev/user_guide/data_types.html channel_axisint or None, optional
If None, the image is assumed to be a grayscale (single channel) image. Otherwise, this parameter indicates which axis of the array corresponds to channels.
 Returns
 output[P, …, ]M[, N][, C] ndarray of float
Image with unsharp mask applied.
 Other Parameters
 multichannelDEPRECATED
Deprecated in favor of channel_axis.
Deprecated since version 0.19.
Notes
Unsharp masking is an image sharpening technique. It is a linear image operation, and numerically stable, unlike deconvolution which is an illposed problem. Because of this stability, it is often preferred over deconvolution.
The main idea is as follows: sharp details are identified as the difference between the original image and its blurred version. These details are added back to the original image after a scaling step:
enhanced image = original + amount * (original  blurred)
When applying this filter to several color layers independently, color bleeding may occur. More visually pleasing result can be achieved by processing only the brightness/lightness/intensity channel in a suitable color space such as HSV, HSL, YUV, or YCbCr.
Unsharp masking is described in most introductory digital image processing books. This implementation is based on [1].
References
 1
Maria Petrou, Costas Petrou “Image Processing: The Fundamentals”, (2010), ed ii., page 357, ISBN 13: 9781119994398 DOI:10.1002/9781119994398
 2
Wikipedia. Unsharp masking https://en.wikipedia.org/wiki/Unsharp_masking
Examples
>>> import cupy as cp >>> array = cp.ones(shape=(5,5), dtype=cp.uint8)*100 >>> array[2,2] = 120 >>> array array([[100, 100, 100, 100, 100], [100, 100, 100, 100, 100], [100, 100, 120, 100, 100], [100, 100, 100, 100, 100], [100, 100, 100, 100, 100]], dtype=uint8) >>> cp.around(unsharp_mask(array, radius=0.5, amount=2),2) array([[0.39, 0.39, 0.39, 0.39, 0.39], [0.39, 0.39, 0.38, 0.39, 0.39], [0.39, 0.38, 0.53, 0.38, 0.39], [0.39, 0.39, 0.38, 0.39, 0.39], [0.39, 0.39, 0.39, 0.39, 0.39]])
>>> array = cp.ones(shape=(5,5), dtype=cp.int8)*100 >>> array[2,2] = 127 >>> cp.around(unsharp_mask(array, radius=0.5, amount=2),2) array([[0.79, 0.79, 0.79, 0.79, 0.79], [0.79, 0.78, 0.75, 0.78, 0.79], [0.79, 0.75, 1. , 0.75, 0.79], [0.79, 0.78, 0.75, 0.78, 0.79], [0.79, 0.79, 0.79, 0.79, 0.79]])
>>> cp.around(unsharp_mask(array, radius=0.5, amount=2, ... preserve_range=True), ... 2) array([[100. , 100. , 99.99, 100. , 100. ], [100. , 99.39, 95.48, 99.39, 100. ], [ 99.99, 95.48, 147.59, 95.48, 99.99], [100. , 99.39, 95.48, 99.39, 100. ], [100. , 100. , 99.99, 100. , 100. ]])
 cucim.skimage.filters.wiener(data, impulse_response=None, filter_params={}, K=0.25, predefined_filter=None)#
Minimum Mean Square Error (Wiener) inverse filter.
 Parameters
 data(M,N) ndarray
Input data.
 Kfloat or (M,N) ndarray
Ratio between power spectrum of noise and undegraded image.
 impulse_responsecallable f(r, c, **filter_params)
Impulse response of the filter. See LPIFilter2D.__init__.
 filter_paramsdict
Additional keyword parameters to the impulse_response function.
 Other Parameters
 predefined_filterLPIFilter2D
If you need to apply the same filter multiple times over different images, construct the LPIFilter2D and specify it here.
 cucim.skimage.filters.window(window_type, shape, warp_kwargs=None)#
Return an ndimensional window of a given size and dimensionality.
 Parameters
 window_typestring, float, or tuple
The type of window to be created. Any window type supported by
scipy.signal.get_window
is allowed here. See notes below for a current list, or the SciPy documentation for the version of SciPy on your machine. shapetuple of int or int
The shape of the window along each axis. If an integer is provided, a 1D window is generated.
 warp_kwargsdict
Keyword arguments passed to skimage.transform.warp (e.g.,
warp_kwargs={'order':3}
to change interpolation method).
 Returns
 nd_windowndarray
A window of the specified
shape
.dtype
isnp.double
.
Notes
This function is based on
scipy.signal.get_window
and thus can access all of the window types available to that function (e.g.,"hann"
,"boxcar"
). Note that certain window types require parameters that have to be supplied with the window name as a tuple (e.g.,("tukey", 0.8)
). If only a float is supplied, it is interpreted as the beta parameter of the Kaiser window.See https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.windows.get_window.html for more details.
Note that this function generates a double precision array of the specified
shape
and can thus generate very large arrays that consume a large amount of available memory.The approach taken here to create nD windows is to first calculate the Euclidean distance from the center of the intended nD window to each position in the array. That distance is used to sample, with interpolation, from a 1D window returned from
scipy.signal.get_window
. The method of interpolation can be changed with theorder
keyword argument passed to skimage.transform.warp.Some coordinates in the output window will be outside of the original signal; these will be filled in with zeros.
Window types:  boxcar  triang  blackman  hamming  hann  bartlett  flattop  parzen  bohman  blackmanharris  nuttall  barthann  kaiser (needs beta)  gaussian (needs standard deviation)  general_gaussian (needs power, width)  slepian (needs width)  dpss (needs normalized halfbandwidth)  chebwin (needs attenuation)  exponential (needs decay scale)  tukey (needs taper fraction)
References
 1
Twodimensional window design, Wikipedia, https://en.wikipedia.org/wiki/Two_dimensional_window_design
Examples
Return a Hann window with shape (512, 512):
>>> from cucim.skimage.filters import window >>> w = window('hann', (512, 512))
Return a Kaiser window with beta parameter of 16 and shape (256, 256, 35):
>>> w = window(16, (256, 256, 35))
Return a Tukey window with an alpha parameter of 0.8 and shape (100, 300):
>>> w = window(('tukey', 0.8), (100, 300))
measure#
 cucim.skimage.measure.approximate_polygon(coords, tolerance)#
Approximate a polygonal chain with the specified tolerance.
It is based on the DouglasPeucker algorithm.
Note that the approximated polygon is always within the convex hull of the original polygon.
 Parameters
 coords(N, 2) array
Coordinate array.
 tolerancefloat
Maximum distance from original points of polygon to approximated polygonal chain. If tolerance is 0, the original coordinate array is returned.
 Returns
 coords(M, 2) array
Approximated polygonal chain where M <= N.
References
 cucim.skimage.measure.block_reduce(image, block_size=2, func=<function sum>, cval=0, func_kwargs=None)#
Downsample image by applying function func to local blocks.
This function is useful for max and mean pooling, for example.
 Parameters
 imagendarray
Ndimensional input image.
 block_sizearray_like or int
Array containing downsampling integer factor along each axis. Default block_size is 2.
 funccallable
Function object which is used to calculate the return value for each local block. This function must implement an
axis
parameter. Primary functions arenumpy.sum
,numpy.min
,numpy.max
,numpy.mean
andnumpy.median
. See also func_kwargs. cvalfloat
Constant padding value if image is not perfectly divisible by the block size.
 func_kwargsdict
Keyword arguments passed to func. Notably useful for passing dtype argument to
np.mean
. Takes dictionary of inputs, e.g.:func_kwargs={'dtype': np.float16})
.
 Returns
 imagendarray
Downsampled image with same number of dimensions as input image.
Examples
>>> import cupy as cp >>> from cucim.skimage.measure import block_reduce >>> image = cp.arange(3*3*4).reshape(3, 3, 4) >>> image array([[[ 0, 1, 2, 3], [ 4, 5, 6, 7], [ 8, 9, 10, 11]], [[12, 13, 14, 15], [16, 17, 18, 19], [20, 21, 22, 23]], [[24, 25, 26, 27], [28, 29, 30, 31], [32, 33, 34, 35]]]) >>> block_reduce(image, block_size=(3, 3, 1), func=cp.mean) array([[[16., 17., 18., 19.]]]) >>> image_max1 = block_reduce(image, block_size=(1, 3, 4), func=cp.max) >>> image_max1 array([[[11]], [[23]], [[35]]]) >>> image_max2 = block_reduce(image, block_size=(3, 1, 4), func=cp.max) >>> image_max2 array([[[27], [31], [35]]])
 cucim.skimage.measure.blur_effect(image, h_size=11, channel_axis=None, reduce_func=<builtin function max>)#
Compute a metric that indicates the strength of blur in an image (0 for no blur, 1 for maximal blur).
 Parameters
 imagendarray
RGB or grayscale nD image. The input image is converted to grayscale before computing the blur metric.
 h_sizeint, optional
Size of the reblurring filter.
 channel_axisint or None, optional
If None, the image is assumed to be grayscale (singlechannel). Otherwise, this parameter indicates which axis of the array corresponds to color channels.
 reduce_funccallable, optional
Function used to calculate the aggregation of blur metrics along all axes. If set to None, the entire list is returned, where the ith element is the blur metric along the ith axis. This function should be a host function that operates on standard python floats.
 Returns
 blurfloat (0 to 1) or list of floats
Blur metric: by default, the maximum of blur metrics along all axes.
Notes
h_size must keep the same value in order to compare results between images. Most of the time, the default size (11) is enough. This means that the metric can clearly discriminate blur up to an average 11x11 filter; if blur is higher, the metric still gives good results but its values tend towards an asymptote.
References
 1
Frederique Crete, Thierry Dolmiere, Patricia Ladret, and Marina Nicolas “The blur effect: perception and estimation with a new noreference perceptual blur metric” Proc. SPIE 6492, Human Vision and Electronic Imaging XII, 64920I (2007) https://hal.archivesouvertes.fr/hal00232709 DOI:10.1117/12.702790
 cucim.skimage.measure.centroid(image)#
Return the (weighted) centroid of an image.
 Parameters
 imagearray
The input image.
 Returns
 centertuple of float, length
image.ndim
The centroid of the (nonzero) pixels in
image
.
 centertuple of float, length
Examples
>>> import cupy as cp >>> from cucim.skimage.measure import centroid >>> image = cp.zeros((20, 20), dtype=np.float64) >>> image[13:17, 13:17] = 0.5 >>> image[10:12, 10:12] = 1 >>> centroid(image) array([13.16666667, 13.16666667])
 cucim.skimage.measure.inertia_tensor(image, mu=None, *, xp=<module 'cupy' from '/opt/conda/envs/rapids/lib/python3.9/sitepackages/cupy/__init__.py'>)#
Compute the inertia tensor of the input image.
 Parameters
 imagearray
The input image.
 muarray, optional
The precomputed central moments of
image
. The inertia tensor computation requires the central moments of the image. If an application requires both the central moments and the inertia tensor (for example, skimage.measure.regionprops), then it is more efficient to precompute them and pass them to the inertia tensor call.
 Returns
 Tarray, shape
(image.ndim, image.ndim)
The inertia tensor of the input image. \(T_{i, j}\) contains the covariance of image intensity along axes \(i\) and \(j\).
 Tarray, shape
References
 1
https://en.wikipedia.org/wiki/Moment_of_inertia#Inertia_tensor
 2
Bernd Jähne. SpatioTemporal Image Processing: Theory and Scientific Applications. (Chapter 8: Tensor Methods) Springer, 1993.
 cucim.skimage.measure.inertia_tensor_eigvals(image, mu=None, T=None, *, xp=<module 'cupy' from '/opt/conda/envs/rapids/lib/python3.9/sitepackages/cupy/__init__.py'>)#
Compute the eigenvalues of the inertia tensor of the image.
The inertia tensor measures covariance of the image intensity along the image axes. (See inertia_tensor.) The relative magnitude of the eigenvalues of the tensor is thus a measure of the elongation of a (bright) object in the image.
 Parameters
 imagearray
The input image.
 muarray, optional
The precomputed central moments of
image
. Tarray, shape
(image.ndim, image.ndim)
The precomputed inertia tensor. If
T
is given,mu
andimage
are ignored.
 Returns
 eigvalslist of float, length
image.ndim
The eigenvalues of the inertia tensor of
image
, in descending order.
 eigvalslist of float, length
Notes
Computing the eigenvalues requires the inertia tensor of the input image. This is much faster if the central moments (
mu
) are provided, or, alternatively, one can provide the inertia tensor (T
) directly.
 cucim.skimage.measure.label(label_image, background=None, return_num=False, connectivity=None)#
Label connected regions of an integer array.
Two pixels are connected when they are neighbors and have the same value. In 2D, they can be neighbors either in a 1 or 2connected sense. The value refers to the maximum number of orthogonal hops to consider a pixel/voxel a neighbor:
1connectivity 2connectivity diagonal connection closeup [ ] [ ] [ ] [ ] [ ]  \  /  < hop 2 [ ][x][ ] [ ][x][ ] [x][ ]  /  \ hop 1 [ ] [ ] [ ] [ ]
 Parameters
 label_imagendarray of dtype int
Image to label.
 backgroundint, optional
Consider all pixels with this value as background pixels, and label them as 0. By default, 0valued pixels are considered as background pixels.
 return_numbool, optional
Whether to return the number of assigned labels.
 connectivityint, optional
Maximum number of orthogonal hops to consider a pixel/voxel as a neighbor. Accepted values are ranging from 1 to input.ndim. If
None
, a full connectivity ofinput.ndim
is used.
 Returns
 labelsndarray of dtype int
Labeled array, where all connected regions are assigned the same integer value.
 numint, optional
Number of labels, which equals the maximum label index and is only returned if return_num is True.
 Other Parameters
 inputDEPRECATED
Deprecated in favor of label_image.
Deprecated since version 0.19.
See also
Notes
Currently the cucim implementation of this function always uses 32bit integers for the label array. This is done for performance. In the future 64bit integer support may also be added for better skimage compatibility.
References
 1
Christophe Fiorio and Jens Gustedt, “Two linear time UnionFind strategies for image processing”, Theoretical Computer Science 154 (1996), pp. 165181.
 2
Kensheng Wu, Ekow Otoo and Arie Shoshani, “Optimizing connected component labeling algorithms”, Paper LBNL56864, 2005, Lawrence Berkeley National Laboratory (University of California), http://repositories.cdlib.org/lbnl/LBNL56864
Examples
>>> import cupy as cp >>> x = cp.eye(3).astype(int) >>> print(x) [[1 0 0] [0 1 0] [0 0 1]] >>> print(label(x, connectivity=1)) [[1 0 0] [0 2 0] [0 0 3]] >>> print(label(x, connectivity=2)) [[1 0 0] [0 1 0] [0 0 1]] >>> print(label(x, background=1)) [[1 2 2] [2 1 2] [2 2 1]] >>> x = cp.asarray([[1, 0, 0], ... [1, 1, 5], ... [0, 0, 0]]) >>> print(label(x)) [[1 0 0] [1 1 2] [0 0 0]]
 cucim.skimage.measure.moments(image, order=3)#
Calculate all raw image moments up to a certain order.
 The following properties can be calculated from raw image moments:
Area as:
M[0, 0]
.Centroid as: {
M[1, 0] / M[0, 0]
,M[0, 1] / M[0, 0]
}.
Note that raw moments are neither translation, scale nor rotation invariant.
 Parameters
 imagenD double or uint8 array
Rasterized shape as image.
 orderint, optional
Maximum order of moments. Default is 3.
 Returns
 m(
order + 1
,order + 1
) array Raw image moments.
 m(
References
 1
Wilhelm Burger, Mark Burge. Principles of Digital Image Processing: Core Algorithms. SpringerVerlag, London, 2009.
 2
B. Jähne. Digital Image Processing. SpringerVerlag, BerlinHeidelberg, 6. edition, 2005.
 3
T. H. Reiss. Recognizing Planar Objects Using Invariant Image Features, from Lecture notes in computer science, p. 676. Springer, Berlin, 1993.
 4
Examples
>>> import cupy as cp >>> from cucim.skimage.measure import moments >>> image = cp.zeros((20, 20), dtype=cp.float64) >>> image[13:17, 13:17] = 1 >>> M = moments(image) >>> centroid = (M[1, 0] / M[0, 0], M[0, 1] / M[0, 0]) >>> centroid (array(14.5), array(14.5))
 cucim.skimage.measure.moments_central(image, center=None, order=3, **kwargs)#
Calculate all central image moments up to a certain order.
The center coordinates (cr, cc) can be calculated from the raw moments as: {
M[1, 0] / M[0, 0]
,M[0, 1] / M[0, 0]
}.Note that central moments are translation invariant but not scale and rotation invariant.
 Parameters
 imagenD double or uint8 array
Rasterized shape as image.
 centertuple of float, optional
Coordinates of the image centroid. This will be computed if it is not provided.
 orderint, optional
The maximum order of moments computed.
 Returns
 mu(
order + 1
,order + 1
) array Central image moments.
 mu(
References
 1
Wilhelm Burger, Mark Burge. Principles of Digital Image Processing: Core Algorithms. SpringerVerlag, London, 2009.
 2
B. Jähne. Digital Image Processing. SpringerVerlag, BerlinHeidelberg, 6. edition, 2005.
 3
T. H. Reiss. Recognizing Planar Objects Using Invariant Image Features, from Lecture notes in computer science, p. 676. Springer, Berlin, 1993.
 4
Examples
>>> import cupy as cp >>> from cucim.skimage.measure import moments, moments_central >>> image = cp.zeros((20, 20), dtype=cp.float64) >>> image[13:17, 13:17] = 1 >>> M = moments(image) >>> centroid = (M[1, 0] / M[0, 0], M[0, 1] / M[0, 0]) >>> moments_central(image, centroid) array([[16., 0., 20., 0.], [ 0., 0., 0., 0.], [20., 0., 25., 0.], [ 0., 0., 0., 0.]])
 cucim.skimage.measure.moments_coords(coords, order=3)#
Calculate all raw image moments up to a certain order.
 The following properties can be calculated from raw image moments:
Area as:
M[0, 0]
.Centroid as: {
M[1, 0] / M[0, 0]
,M[0, 1] / M[0, 0]
}.
Note that raw moments are neither translation, scale nor rotation invariant.
 Parameters
 coords(N, D) double or uint8 array
Array of N points that describe an image of D dimensionality in Cartesian space.
 orderint, optional
Maximum order of moments. Default is 3.
 Returns
 M(
order + 1
,order + 1
, …) array Raw image moments. (D dimensions)
 M(
References
 1
Johannes Kilian. Simple Image Analysis By Moments. Durham University, version 0.2, Durham, 2001.
Examples
>>> import cupy as cp >>> from cucim.skimage.measure import moments_coords >>> coords = cp.array([[row, col] ... for row in range(13, 17) ... for col in range(14, 18)], dtype=cp.float64) >>> M = moments_coords(coords) >>> centroid = (M[1, 0] / M[0, 0], M[0, 1] / M[0, 0]) >>> centroid (array(14.5), array(15.5))
 cucim.skimage.measure.moments_coords_central(coords, center=None, order=3)#
Calculate all central image moments up to a certain order.
 The following properties can be calculated from raw image moments:
Area as:
M[0, 0]
.Centroid as: {
M[1, 0] / M[0, 0]
,M[0, 1] / M[0, 0]
}.
Note that raw moments are neither translation, scale nor rotation invariant.
 Parameters
 coords(N, D) double or uint8 array
Array of N points that describe an image of D dimensionality in Cartesian space. A tuple of coordinates as returned by
cp.nonzero
is also accepted as input. centertuple of float, optional
Coordinates of the image centroid. This will be computed if it is not provided.
 orderint, optional
Maximum order of moments. Default is 3.
 Returns
 Mc(
order + 1
,order + 1
, …) array Central image moments. (D dimensions)
 Mc(
References
 1
Johannes Kilian. Simple Image Analysis By Moments. Durham University, version 0.2, Durham, 2001.
Examples
>>> import cupy as cp >>> from cucim.skimage.measure import moments_coords_central >>> coords = cp.array([[row, col] ... for row in range(13, 17) ... for col in range(14, 18)]) >>> moments_coords_central(coords) array([[16., 0., 20., 0.], [ 0., 0., 0., 0.], [20., 0., 25., 0.], [ 0., 0., 0., 0.]])
As seen above, for symmetric objects, oddorder moments (columns 1 and 3, rows 1 and 3) are zero when centered on the centroid, or center of mass, of the object (the default). If we break the symmetry by adding a new point, this no longer holds:
>>> coords2 = cp.concatenate((coords, cp.array([[17, 17]])), axis=0) >>> cp.round(moments_coords_central(coords2), ... decimals=2) array([[17. , 0. , 22.12, 2.49], [ 0. , 3.53, 1.73, 7.4 ], [25.88, 6.02, 36.63, 8.83], [ 4.15, 19.17, 14.8 , 39.6 ]])
Image moments and central image moments are equivalent (by definition) when the center is (0, 0):
>>> cp.allclose(moments_coords(coords), ... moments_coords_central(coords, (0, 0))) array(True)
 cucim.skimage.measure.moments_hu(nu)#
Calculate Hu’s set of image moments (2Donly).
Note that this set of moments is proofed to be translation, scale and rotation invariant.
 Parameters
 nu(M, M) array
Normalized central image moments, where M must be >= 4.
 Returns
 nu(7,) array
Hu’s set of image moments.
Notes
Due to the small array sizes, this function will be faster on the CPU. Consider transfering
nu
to the host and runningskimage.measure.moments_hu
if the moments are not needed on the device.References
 1
M. K. Hu, “Visual Pattern Recognition by Moment Invariants”, IRE Trans. Info. Theory, vol. IT8, pp. 179187, 1962
 2
Wilhelm Burger, Mark Burge. Principles of Digital Image Processing: Core Algorithms. SpringerVerlag, London, 2009.
 3
B. Jähne. Digital Image Processing. SpringerVerlag, BerlinHeidelberg, 6. edition, 2005.
 4
T. H. Reiss. Recognizing Planar Objects Using Invariant Image Features, from Lecture notes in computer science, p. 676. Springer, Berlin, 1993.
 5
Examples
>>> import cupy as cp >>> from cucim.skimage.measure import (moments_central, moments_hu, ... moments_normalized) >>> image = cp.zeros((20, 20), dtype=np.float64) >>> image[13:17, 13:17] = 0.5 >>> image[10:12, 10:12] = 1 >>> mu = moments_central(image) >>> nu = moments_normalized(mu) >>> moments_hu(nu) array([7.45370370e01, 3.51165981e01, 1.04049179e01, 4.06442107e02, 2.64312299e03, 2.40854582e02, 6.50521303e19])
 cucim.skimage.measure.moments_normalized(mu, order=3)#
Calculate all normalized central image moments up to a certain order.
Note that normalized central moments are translation and scale invariant but not rotation invariant.
 Parameters
 mu(M,[ …,] M) array
Central image moments, where M must be greater than or equal to
order
. orderint, optional
Maximum order of moments. Default is 3.
 Returns
 nu(
order + 1
,[ …,]order + 1
) array Normalized central image moments.
 nu(
Notes
Due to the small array sizes, this function should be faster on the CPU. Consider transfering
mu
to the host and runningskimage.measure.moments_normalized
.References
 1
Wilhelm Burger, Mark Burge. Principles of Digital Image Processing: Core Algorithms. SpringerVerlag, London, 2009.
 2
B. Jähne. Digital Image Processing. SpringerVerlag, BerlinHeidelberg, 6. edition, 2005.
 3
T. H. Reiss. Recognizing Planar Objects Using Invariant Image Features, from Lecture notes in computer science, p. 676. Springer, Berlin, 1993.
 4
Examples
>>> import cupy as cp >>> from cucim.skimage.measure import (moments, moments_central, ... moments_normalized) >>> image = cp.zeros((20, 20), dtype=cp.float64) >>> image[13:17, 13:17] = 1 >>> m = moments(image) >>> centroid = (m[0, 1] / m[0, 0], m[1, 0] / m[0, 0]) >>> mu = moments_central(image, centroid) >>> moments_normalized(mu) array([[ nan, nan, 0.078125 , 0. ], [ nan, 0. , 0. , 0. ], [0.078125 , 0. , 0.00610352, 0. ], [0. , 0. , 0. , 0. ]])
 cucim.skimage.measure.perimeter(image, neighbourhood=4)#
Calculate total perimeter of all objects in binary image.
 Parameters
 image(N, M) ndarray
2D binary image.
 neighbourhood4 or 8, optional
Neighborhood connectivity for border pixel determination. It is used to compute the contour. A higher neighbourhood widens the border on which the perimeter is computed.
 Returns
 perimeterfloat
Total perimeter of all objects in binary image.
References
 1
K. Benkrid, D. Crookes. Design and FPGA Implementation of a Perimeter Estimator. The Queen’s University of Belfast. http://www.cs.qub.ac.uk/~d.crookes/webpubs/papers/perimeter.doc
Examples
>>> import cupy as cp >>> from skimage import data >>> from cucim.skimage import util >>> from cucim.skimage.measure import label >>> # coins image (binary) >>> img_coins = cp.array(data.coins() > 110) >>> # total perimeter of all objects in the image >>> perimeter(img_coins, neighbourhood=4) array(7796.86799644) >>> perimeter(img_coins, neighbourhood=8) array(8806.26807333)
 cucim.skimage.measure.profile_line(image, src, dst, linewidth=1, order=None, mode='reflect', cval=0.0, *, reduce_func=<function mean>)#
Return the intensity profile of an image measured along a scan line.
 Parameters
 imagendarray, shape (M, N[, C])
The image, either grayscale (2D array) or multichannel (3D array, where the final axis contains the channel information).
 srcarray_like, shape (2, )
The coordinates of the start point of the scan line.
 dstarray_like, shape (2, )
The coordinates of the end point of the scan line. The destination point is included in the profile, in contrast to standard numpy indexing.
 linewidthint, optional
Width of the scan, perpendicular to the line
 orderint in {0, 1, 2, 3, 4, 5}, optional
The order of the spline interpolation, default is 0 if image.dtype is bool and 1 otherwise. The order has to be in the range 05. See skimage.transform.warp for detail.
 mode{‘constant’, ‘nearest’, ‘reflect’, ‘mirror’, ‘wrap’}, optional
How to compute any values falling outside of the image.
 cvalfloat, optional
If mode is ‘constant’, what constant value to use outside the image.
 reduce_funccallable, optional
Function used to calculate the aggregation of pixel values perpendicular to the profile_line direction when linewidth > 1. If set to None the unreduced array will be returned.
 Returns
 return_valuearray
The intensity profile along the scan line. The length of the profile is the ceil of the computed length of the scan line.
Examples
>>> import cupy as cp >>> x = cp.asarray([[1, 1, 1, 2, 2, 2]]) >>> img = cp.vstack([cp.zeros_like(x), x, x, x, cp.zeros_like(x)]) >>> img array([[0, 0, 0, 0, 0, 0], [1, 1, 1, 2, 2, 2], [1, 1, 1, 2, 2, 2], [1, 1, 1, 2, 2, 2], [0, 0, 0, 0, 0, 0]]) >>> profile_line(img, (2, 1), (2, 4)) array([1., 1., 2., 2.]) >>> profile_line(img, (1, 0), (1, 6), cval=4) array([1., 1., 1., 2., 2., 2., 2.])
The destination point is included in the profile, in contrast to standard numpy indexing. For example:
>>> profile_line(img, (1, 0), (1, 6)) # The final point is out of bounds array([1., 1., 1., 2., 2., 2., 2.]) >>> profile_line(img, (1, 0), (1, 5)) # This accesses the full first row array([1., 1., 1., 2., 2., 2.])
For different reduce_func inputs:
>>> profile_line(img, (1, 0), (1, 3), linewidth=3, reduce_func=cp.mean) array([0.66666667, 0.66666667, 0.66666667, 1.33333333]) >>> profile_line(img, (1, 0), (1, 3), linewidth=3, reduce_func=cp.max) array([1, 1, 1, 2]) >>> profile_line(img, (1, 0), (1, 3), linewidth=3, reduce_func=cp.sum) array([2, 2, 2, 4])
The unreduced array will be returned when reduce_func is None or when reduce_func acts on each pixel value individually.
>>> profile_line(img, (1, 2), (4, 2), linewidth=3, order=0, ... reduce_func=None) array([[1, 1, 2], [1, 1, 2], [1, 1, 2], [0, 0, 0]]) >>> profile_line(img, (1, 0), (1, 3), linewidth=3, reduce_func=cp.sqrt) array([[1. , 1. , 0. ], [1. , 1. , 0. ], [1. , 1. , 0. ], [1.41421356, 1.41421356, 0. ]])
 cucim.skimage.measure.regionprops(label_image, intensity_image=None, cache=True, coordinates=None, *, extra_properties=None)#
Measure properties of labeled image regions.
 Parameters
 label_image(M, N[, P]) ndarray
Labeled input image. Labels with value 0 are ignored.
Changed in version 0.14.1: Previously,
label_image
was processed bynumpy.squeeze
and so any number of singleton dimensions was allowed. This resulted in inconsistent handling of images with singleton dimensions. To recover the old behaviour, useregionprops(np.squeeze(label_image), ...)
. intensity_image(M, N[, P][, C]) ndarray, optional
Intensity (i.e., input) image with same size as labeled image, plus optionally an extra dimension for multichannel data. Currently, this extra channel dimension, if present, must be the last axis. Default is None.
Changed in version 0.18.0: The ability to provide an extra dimension for channels was added.
 cachebool, optional
Determine whether to cache calculated properties. The computation is much faster for cached properties, whereas the memory consumption increases.
 coordinatesDEPRECATED
This argument is deprecated and will be removed in a future version of scikitimage.
See Coordinate conventions for more details.
Deprecated since version 0.16.0: Use “rc” coordinates everywhere. It may be sufficient to call
numpy.transpose
on your label image to get the same values as 0.15 and earlier. However, for some properties, the transformation will be less trivial. For example, the new orientation is \(\frac{\pi}{2}\) plus the old orientation. extra_propertiesIterable of callables
Add extra property computation functions that are not included with skimage. The name of the property is derived from the function name, the dtype is inferred by calling the function on a small sample. If the name of an extra property clashes with the name of an existing property the extra property wil not be visible and a UserWarning is issued. A property computation function must take a region mask as its first argument. If the property requires an intensity image, it must accept the intensity image as the second argument.
 Returns
 propertieslist of RegionProperties
Each item describes one labeled region, and can be accessed using the attributes listed below.
See also
Notes
The following properties can be accessed as attributes or keys:
 areaint
Number of pixels of the region.
 area_bboxint
Number of pixels of bounding box.
 area_convexint
Number of pixels of convex hull image, which is the smallest convex polygon that encloses the region.
 area_filledint
Number of pixels of the region will all the holes filled in. Describes the area of the image_filled.
 axis_major_lengthfloat
The length of the major axis of the ellipse that has the same normalized second central moments as the region.
 axis_minor_lengthfloat
The length of the minor axis of the ellipse that has the same normalized second central moments as the region.
 bboxtuple
Bounding box
(min_row, min_col, max_row, max_col)
. Pixels belonging to the bounding box are in the halfopen interval[min_row; max_row)
and[min_col; max_col)
. centroidarray
Centroid coordinate tuple
(row, col)
. centroid_localarray
Centroid coordinate tuple
(row, col)
, relative to region bounding box. centroid_weightedarray
Centroid coordinate tuple
(row, col)
weighted with intensity image. centroid_weighted_localarray
Centroid coordinate tuple
(row, col)
, relative to region bounding box, weighted with intensity image. coords(N, 2) ndarray
Coordinate list
(row, col)
of the region. eccentricityfloat
Eccentricity of the ellipse that has the same secondmoments as the region. The eccentricity is the ratio of the focal distance (distance between focal points) over the major axis length. The value is in the interval [0, 1). When it is 0, the ellipse becomes a circle.
 equivalent_diameter_areafloat
The diameter of a circle with the same area as the region.
 euler_numberint
Euler characteristic of the set of nonzero pixels. Computed as number of connected components subtracted by number of holes (input.ndim connectivity). In 3D, number of connected components plus number of holes subtracted by number of tunnels.
 extentfloat
Ratio of pixels in the region to pixels in the total bounding box. Computed as
area / (rows * cols)
 feret_diameter_maxfloat
Maximum Feret’s diameter computed as the longest distance between points around a region’s convex hull contour as determined by
find_contours
. [5] image(H, J) ndarray
Sliced binary region image which has the same size as bounding box.
 image_convex(H, J) ndarray
Binary convex hull image which has the same size as bounding box.
 image_filled(H, J) ndarray
Binary region image with filled holes which has the same size as bounding box.
 image_intensityndarray
Image inside region bounding box.
 inertia_tensorndarray
Inertia tensor of the region for the rotation around its mass.
 inertia_tensor_eigvalstuple
The eigenvalues of the inertia tensor in decreasing order.
 intensity_maxfloat
Value with the greatest intensity in the region.
 intensity_meanfloat
Value with the mean intensity in the region.
 intensity_minfloat
Value with the least intensity in the region.
 labelint
The label in the labeled input image.
 moments(3, 3) ndarray
Spatial moments up to 3rd order:
m_ij = sum{ array(row, col) * row^i * col^j }
where the sum is over the row, col coordinates of the region.
 moments_central(3, 3) ndarray
Central moments (translation invariant) up to 3rd order:
mu_ij = sum{ array(row, col) * (row  row_c)^i * (col  col_c)^j }
where the sum is over the row, col coordinates of the region, and row_c and col_c are the coordinates of the region’s centroid.
 moments_hutuple
Hu moments (translation, scale and rotation invariant).
 moments_normalized(3, 3) ndarray
Normalized moments (translation and scale invariant) up to 3rd order:
nu_ij = mu_ij / m_00^[(i+j)/2 + 1]
where m_00 is the zeroth spatial moment.
 moments_weighted(3, 3) ndarray
Spatial moments of intensity image up to 3rd order:
wm_ij = sum{ array(row, col) * row^i * col^j }
where the sum is over the row, col coordinates of the region.
 moments_weighted_central(3, 3) ndarray
Central moments (translation invariant) of intensity image up to 3rd order:
wmu_ij = sum{ array(row, col) * (row  row_c)^i * (col  col_c)^j }
where the sum is over the row, col coordinates of the region, and row_c and col_c are the coordinates of the region’s weighted centroid.
 moments_weighted_hutuple
Hu moments (translation, scale and rotation invariant) of intensity image.
 moments_weighted_normalized(3, 3) ndarray
Normalized moments (translation and scale invariant) of intensity image up to 3rd order:
wnu_ij = wmu_ij / wm_00^[(i+j)/2 + 1]
where
wm_00
is the zeroth spatial moment (intensityweighted area). orientationfloat
Angle between the 0th axis (rows) and the major axis of the ellipse that has the same second moments as the region, ranging from pi/2 to pi/2 counterclockwise.
 perimeterfloat
Perimeter of object which approximates the contour as a line through the centers of border pixels using a 4connectivity.
 perimeter_croftonfloat
Perimeter of object approximated by the Crofton formula in 4 directions.
 slicetuple of slices
A slice to extract the object from the source image.
 solidityfloat
Ratio of pixels in the region to pixels of the convex hull image.
Each region also supports iteration, so that you can do:
for prop in region: print(prop, region[prop])
References
 1
Wilhelm Burger, Mark Burge. Principles of Digital Image Processing: Core Algorithms. SpringerVerlag, London, 2009.
 2
B. Jähne. Digital Image Processing. SpringerVerlag, BerlinHeidelberg, 6. edition, 2005.
 3
T. H. Reiss. Recognizing Planar Objects Using Invariant Image Features, from Lecture notes in computer science, p. 676. Springer, Berlin, 1993.
 4
 5
W. Pabst, E. Gregorová. Characterization of particles and particle systems, pp. 2728. ICT Prague, 2007. https://old.vscht.cz/sil/keramika/Characterization_of_particles/CPPS%20_English%20version_.pdf
Examples
>>> from skimage import data, util >>> from cucim.skimage.measure import label, regionprops >>> img = cp.asarray(util.img_as_ubyte(data.coins()) > 110) >>> label_img = label(img, connectivity=img.ndim) >>> props = regionprops(label_img) >>> # centroid of first labeled object >>> props[0].centroid (22.72987986048314, 81.91228523446583) >>> # centroid of first labeled object >>> props[0]['centroid'] (22.72987986048314, 81.91228523446583)
Add custom measurements by passing functions as
extra_properties
>>> from skimage import data, util >>> from cucim.skimage.measure import label, regionprops >>> import numpy as np >>> img = cp.asarray(util.img_as_ubyte(data.coins()) > 110) >>> label_img = label(img, connectivity=img.ndim) >>> def pixelcount(regionmask): ... return np.sum(regionmask) >>> props = regionprops(label_img, extra_properties=(pixelcount,)) >>> props[0].pixelcount array(7741) >>> props[1]['pixelcount'] array(42)
 cucim.skimage.measure.regionprops_table(label_image, intensity_image=None, properties=('label', 'bbox'), *, cache=True, separator='', extra_properties=None)#
Compute image properties and return them as a pandascompatible table.
The table is a dictionary mapping column names to value arrays. See Notes section below for details.
New in version 0.16.
 Parameters
 label_image(N, M[, P]) ndarray
Labeled input image. Labels with value 0 are ignored.
 intensity_image(M, N[, P][, C]) ndarray, optional
Intensity (i.e., input) image with same size as labeled image, plus optionally an extra dimension for multichannel data. Currently, this extra channel dimension, if present, must be the last axis. Default is None.
Changed in version 0.18.0: The ability to provide an extra dimension for channels was added.
 propertiestuple or list of str, optional
Properties that will be included in the resulting dictionary For a list of available properties, please see
regionprops()
. Users should remember to add “label” to keep track of region identities. cachebool, optional
Determine whether to cache calculated properties. The computation is much faster for cached properties, whereas the memory consumption increases.
 separatorstr, optional
For nonscalar properties not listed in OBJECT_COLUMNS, each element will appear in its own column, with the index of that element separated from the property name by this separator. For example, the inertia tensor of a 2D region will appear in four columns:
inertia_tensor00
,inertia_tensor01
,inertia_tensor10
, andinertia_tensor11
(where the separator is
).Object columns are those that cannot be split in this way because the number of columns would change depending on the object. For example,
image
andcoords
. extra_propertiesIterable of callables
Add extra property computation functions that are not included with skimage. The name of the property is derived from the function name, the dtype is inferred by calling the function on a small sample. If the name of an extra property clashes with the name of an existing property the extra property wil not be visible and a UserWarning is issued. A property computation function must take a region mask as its first argument. If the property requires an intensity image, it must accept the intensity image as the second argument.
 Returns
 out_dictdict
Dictionary mapping property names to an array of values of that property, one value per region. This dictionary can be used as input to pandas
DataFrame
to map property names to columns in the frame and regions to rows. If the image has no regions, the arrays will have length 0, but the correct type.
Notes
Each column contains either a scalar property, an object property, or an element in a multidimensional array.
Properties with scalar values for each region, such as “eccentricity”, will appear as a float or int array with that property name as key.
Multidimensional properties of fixed size for a given image dimension, such as “centroid” (every centroid will have three elements in a 3D image, no matter the region size), will be split into that many columns, with the name {property_name}{separator}{element_num} (for 1D properties), {property_name}{separator}{elem_num0}{separator}{elem_num1} (for 2D properties), and so on.
For multidimensional properties that don’t have a fixed size, such as “image” (the image of a region varies in size depending on the region size), an object array will be used, with the corresponding property name as the key.
Examples
>>> from skimage import data, util, measure >>> image = data.coins() >>> label_image = measure.label(image > 110, connectivity=image.ndim) >>> props = measure.regionprops_table(label_image, image, ... properties=['label', 'inertia_tensor', ... 'inertia_tensor_eigvals']) >>> props {'label': array([ 1, 2, ...]), ... 'inertia_tensor00': array([ 4.012...e+03, 8.51..., ...]), ... ..., 'inertia_tensor_eigvals1': array([ 2.67...e+02, 2.83..., ...])}
The resulting dictionary can be directly passed to pandas, if installed, to obtain a clean DataFrame:
>>> import pandas as pd >>> data = pd.DataFrame(props) >>> data.head() label inertia_tensor00 ... inertia_tensor_eigvals1 0 1 4012.909888 ... 267.065503 1 2 8.514739 ... 2.834806 2 3 0.666667 ... 0.000000 3 4 0.000000 ... 0.000000 4 5 0.222222 ... 0.111111
[5 rows x 7 columns]
If we want to measure a feature that does not come as a builtin property, we can define custom functions and pass them as
extra_properties
. For example, we can create a custom function that measures the intensity quartiles in a region:>>> from skimage import data, util, measure >>> import numpy as np >>> def quartiles(regionmask, intensity): ... return np.percentile(intensity[regionmask], q=(25, 50, 75)) >>> >>> image = data.coins() >>> label_image = measure.label(image > 110, connectivity=image.ndim) >>> props = measure.regionprops_table(label_image, intensity_image=image, ... properties=('label',), ... extra_properties=(quartiles,)) >>> import pandas as pd >>> pd.DataFrame(props).head() label quartiles0 quartiles1 quartiles2 0 1 117.00 123.0 130.0 1 2 111.25 112.0 114.0 2 3 111.00 111.0 111.0 3 4 111.00 111.5 112.5 4 5 112.50 113.0 114.0
 cucim.skimage.measure.shannon_entropy(image, base=2)#
Calculate the Shannon entropy of an image.
The Shannon entropy is defined as S = sum(pk * log(pk)), where pk are frequency/probability of pixels of value k.
 Parameters
 image(N, M) ndarray
Grayscale input image.
 basefloat, optional
The logarithmic base to use.
 Returns
 entropy0dimensional float cupy.ndarray
Notes
The returned value is measured in bits or shannon (Sh) for base=2, natural unit (nat) for base=np.e and hartley (Hart) for base=10.
References
 1
https://en.wikipedia.org/wiki/Entropy_(information_theory) <https://en.wikipedia.org/wiki/Entropy_(information_theory)>`_ # noqa
 2
Examples
>>> import cupy as cp >>> from skimage import data >>> from cucim.skimage.measure import shannon_entropy >>> shannon_entropy(cp.array(data.camera())) array(7.23169501)
 cucim.skimage.measure.subdivide_polygon(coords, degree=2, preserve_ends=False)#
Subdivision of polygonal curves using BSplines.
Note that the resulting curve is always within the convex hull of the original polygon. Circular polygons stay closed after subdivision.
 Parameters
 coords(N, 2) array
Coordinate array.
 degree{1, 2, 3, 4, 5, 6, 7}, optional
Degree of BSpline. Default is 2.
 preserve_endsbool, optional
Preserve first and last coordinate of noncircular polygon. Default is False.
 Returns
 coords(M, 2) array
Subdivided coordinate array.
References
metrics#
 cucim.skimage.metrics.mean_squared_error(image0, image1)#
Compute the meansquared error between two images.
 Parameters
 image0, image1ndarray
Images. Any dimensionality, must have same shape.
 Returns
 msefloat
The meansquared error (MSE) metric.
Notes
Changed in version 0.16: This function was renamed from
skimage.measure.compare_mse
toskimage.metrics.mean_squared_error
.
 cucim.skimage.metrics.normalized_mutual_information(image0, image1, *, bins=100)#
Compute the normalized mutual information (NMI).
The normalized mutual information of \(A\) and \(B\) is given by:
..math::
Y(A, B) = frac{H(A) + H(B)}{H(A, B)}
where \(H(X) :=  \sum_{x \in X}{x \log x}\) is the entropy.
It was proposed to be useful in registering images by Colin Studholme and colleagues [1]. It ranges from 1 (perfectly uncorrelated image values) to 2 (perfectly correlated image values, whether positively or negatively).
 Parameters
 image0, image1ndarray
Images to be compared. The two input images must have the same number of dimensions.
 binsint or sequence of int, optional
The number of bins along each axis of the joint histogram.
 Returns
 nmifloat
The normalized mutual information between the two arrays, computed at the granularity given by
bins
. Higher NMI implies more similar input images.
 Raises
 ValueError
If the images don’t have the same number of dimensions.
Notes
If the two input images are not the same shape, the smaller image is padded with zeros.
References
 1
C. Studholme, D.L.G. Hill, & D.J. Hawkes (1999). An overlap invariant entropy measure of 3D medical image alignment. Pattern Recognition 32(1):7186 DOI:10.1016/S00313203(98)000910
 cucim.skimage.metrics.normalized_root_mse(image_true, image_test, *, normalization='euclidean')#
Compute the normalized root meansquared error (NRMSE) between two images.
 Parameters
 image_truendarray
Groundtruth image, same shape as im_test.
 image_testndarray
Test image.
 normalization{‘euclidean’, ‘minmax’, ‘mean’}, optional
Controls the normalization method to use in the denominator of the NRMSE. There is no standard method of normalization across the literature [1]. The methods available here are as follows:
‘euclidean’ : normalize by the averaged Euclidean norm of
im_true
:NRMSE = RMSE * sqrt(N) /  im_true 
where  .  denotes the Frobenius norm and
N = im_true.size
. This result is equivalent to:NRMSE =  im_true  im_test  /  im_true .
‘minmax’ : normalize by the intensity range of
im_true
.‘mean’ : normalize by the mean of
im_true
 Returns
 nrmsefloat
The NRMSE metric.
Notes
Changed in version 0.16: This function was renamed from
skimage.measure.compare_nrmse
toskimage.metrics.normalized_root_mse
.References
 cucim.skimage.metrics.peak_signal_noise_ratio(image_true, image_test, *, data_range=None)#
Compute the peak signal to noise ratio (PSNR) for an image.
 Parameters
 image_truendarray
Groundtruth image, same shape as im_test.
 image_testndarray
Test image.
 data_rangeint, optional
The data range of the input image (distance between minimum and maximum possible values). By default, this is estimated from the image datatype.
 Returns
 psnrfloat
The PSNR metric.
Notes
Changed in version 0.16: This function was renamed from
skimage.measure.compare_psnr
toskimage.metrics.peak_signal_noise_ratio
.References
 cucim.skimage.metrics.structural_similarity(im1, im2, *, win_size=None, gradient=False, data_range=None, channel_axis=None, multichannel=False, gaussian_weights=False, full=False, **kwargs)#
Compute the mean structural similarity index between two images.
 Parameters
 im1, im2ndarray
Images. Any dimensionality with same shape.
 win_sizeint or None, optional
The sidelength of the sliding window used in comparison. Must be an odd value. If gaussian_weights is True, this is ignored and the window size will depend on sigma.
 gradientbool, optional
If True, also return the gradient with respect to im2.
 data_rangefloat, optional
The data range of the input image (distance between minimum and maximum possible values). By default, this is estimated from the image datatype.
 channel_axisint or None, optional
If None, the image is assumed to be a grayscale (single channel) image. Otherwise, this parameter indicates which axis of the array corresponds to channels.
 multichannelbool, optional
If True, treat the last dimension of the array as channels. Similarity calculations are done independently for each channel then averaged. This argument is deprecated: specify channel_axis instead.
 gaussian_weightsbool, optional
If True, each patch has its mean and variance spatially weighted by a normalized Gaussian kernel of width sigma=1.5.
 fullbool, optional
If True, also return the full structural similarity image.
 Returns
 mssimfloat
The mean structural similarity index over the image.
 gradndarray
The gradient of the structural similarity between im1 and im2 [2]. This is only returned if gradient is set to True.
 Sndarray
The full SSIM image. This is only returned if full is set to True.
 Other Parameters
 use_sample_covariancebool
If True, normalize covariances by N1 rather than, N where N is the number of pixels within the sliding window.
 K1float
Algorithm parameter, K1 (small constant, see [1]).
 K2float
Algorithm parameter, K2 (small constant, see [1]).
 sigmafloat
Standard deviation for the Gaussian when gaussian_weights is True.
 multichannelDEPRECATED
Deprecated in favor of channel_axis.
Deprecated since version 0.19.
Notes
To match the implementation of Wang et. al. [1], set gaussian_weights to True, sigma to 1.5, and use_sample_covariance to False.
Changed in version 0.16: This function was renamed from
skimage.measure.compare_ssim
toskimage.metrics.structural_similarity
.References
 1(1,2,3)
Wang, Z., Bovik, A. C., Sheikh, H. R., & Simoncelli, E. P. (2004). Image quality assessment: From error visibility to structural similarity. IEEE Transactions on Image Processing, 13, 600612. https://ece.uwaterloo.ca/~z70wang/publications/ssim.pdf, DOI:10.1109/TIP.2003.819861
 2
Avanaki, A. N. (2009). Exact global histogram specification optimized for structural similarity. Optical Review, 16, 613621. arXiv:0901.0065 DOI:10.1007/s100430090119z
morphology#
 cucim.skimage.morphology.ball(radius, dtype=<class 'numpy.uint8'>)#
Generates a ballshaped footprint.
This is the 3D equivalent of a disk. A pixel is within the neighborhood if the Euclidean distance between it and the origin is no greater than radius.
 Parameters
 radiusint
The radius of the ballshaped footprint.
 Returns
 footprintndarray
The footprint where elements of the neighborhood are 1 and 0 otherwise.
 Other Parameters
 dtypedatatype
The data type of the footprint.
 cucim.skimage.morphology.binary_closing(image, footprint=None, out=None)#
Return fast binary morphological closing of an image.
This function returns the same result as grayscale closing but performs faster for binary images.
The morphological closing on an image is defined as a dilation followed by an erosion. Closing can remove small dark spots (i.e. “pepper”) and connect small bright cracks. This tends to “close” up (dark) gaps between (bright) features.
 Parameters
 imagendarray
Binary input image.
 footprintndarray, optional
The neighborhood expressed as a 2D array of 1’s and 0’s. If None, use a crossshaped footprint (connectivity=1).
 outndarray of bool, optional
The array to store the result of the morphology. If None, is passed, a new array will be allocated.
 Returns
 closingndarray of bool
The result of the morphological closing.
 Other Parameters
 selemDEPRECATED
Deprecated in favor of footprint.
Deprecated since version 0.19.
 cucim.skimage.morphology.binary_dilation(image, footprint=None, out=None)#
Return fast binary morphological dilation of an image.
This function returns the same result as grayscale dilation but performs faster for binary images.
Morphological dilation sets a pixel at
(i,j)
to the maximum over all pixels in the neighborhood centered at(i,j)
. Dilation enlarges bright regions and shrinks dark regions. Parameters
 imagendarray
Binary input image.
 footprintndarray, optional
The neighborhood expressed as a 2D array of 1’s and 0’s. If None, use a crossshaped footprint (connectivity=1).
 outndarray of bool, optional
The array to store the result of the morphology. If None is passed, a new array will be allocated.
 Returns
 dilatedndarray of bool or uint
The result of the morphological dilation with values in
[False, True]
.
 Other Parameters
 selemDEPRECATED
Deprecated in favor of footprint.
Deprecated since version 0.19.
 cucim.skimage.morphology.binary_erosion(image, footprint=None, out=None)#
Return fast binary morphological erosion of an image.
This function returns the same result as grayscale erosion but performs faster for binary images.
Morphological erosion sets a pixel at
(i,j)
to the minimum over all pixels in the neighborhood centered at(i,j)
. Erosion shrinks bright regions and enlarges dark regions. Parameters
 imagendarray
Binary input image.
 footprintndarray, optional
The neighborhood expressed as a 2D array of 1’s and 0’s. If None, use a crossshaped footprint (connectivity=1).
 outndarray of bool, optional
The array to store the result of the morphology. If None is passed, a new array will be allocated.
 Returns
 erodedndarray of bool or uint
The result of the morphological erosion taking values in
[False, True]
.
 Other Parameters
 selemDEPRECATED
Deprecated in favor of footprint.
Deprecated since version 0.19.
 cucim.skimage.morphology.binary_opening(image, footprint=None, out=None)#
Return fast binary morphological opening of an image.
This function returns the same result as grayscale opening but performs faster for binary images.
The morphological opening on an image is defined as an erosion followed by a dilation. Opening can remove small bright spots (i.e. “salt”) and connect small dark cracks. This tends to “open” up (dark) gaps between (bright) features.
 Parameters
 imagendarray
Binary input image.
 footprintndarray, optional
The neighborhood expressed as a 2D array of 1’s and 0’s. If None, use a crossshaped footprint (connectivity=1).
 outndarray of bool, optional
The array to store the result of the morphology. If None is passed, a new array will be allocated.
 Returns
 openingndarray of bool
The result of the morphological opening.
 Other Parameters
 selemDEPRECATED
Deprecated in favor of footprint.
Deprecated since version 0.19.
 cucim.skimage.morphology.black_tophat(image, footprint=None, out=None)#
Return black top hat of an image.
The black top hat of an image is defined as its morphological closing minus the original image. This operation returns the dark spots of the image that are smaller than the footprint. Note that dark spots in the original image are bright spots after the black top hat.
 Parameters
 imagendarray
Image array.
 footprintndarray, optional
The neighborhood expressed as a 2D array of 1’s and 0’s. If None, use crossshaped footprint (connectivity=1).
 outndarray, optional
The array to store the result of the morphology. If None is passed, a new array will be allocated.
 Returns
 outarray, same shape and type as image
The result of the morphological black top hat.
 Other Parameters
 selemDEPRECATED
Deprecated in favor of footprint.
Deprecated since version 0.19.
See also
References
Examples
>>> # Change dark peak to bright peak and subtract background >>> import cupy as cp >>> from cucim.skimage.morphology import square >>> dark_on_grey = cp.asarray([[7, 6, 6, 6, 7], ... [6, 5, 4, 5, 6], ... [6, 4, 0, 4, 6], ... [6, 5, 4, 5, 6], ... [7, 6, 6, 6, 7]], dtype=cp.uint8) >>> black_tophat(dark_on_grey, square(3)) array([[0, 0, 0, 0, 0], [0, 0, 1, 0, 0], [0, 1, 5, 1, 0], [0, 0, 1, 0, 0], [0, 0, 0, 0, 0]], dtype=uint8)
 cucim.skimage.morphology.closing(image, footprint=None, out=None)#
Return grayscale morphological closing of an image.
The morphological closing of an image is defined as a dilation followed by an erosion. Closing can remove small dark spots (i.e. “pepper”) and connect small bright cracks. This tends to “close” up (dark) gaps between (bright) features.
 Parameters
 imagendarray
Image array.
 footprintndarray, optional
The neighborhood expressed as an array of 1’s and 0’s. If None, use crossshaped footprint (connectivity=1).
 outndarray, optional
The array to store the result of the morphology. If None, a new array will be allocated.
 Returns
 closingarray, same shape and type as image
The result of the morphological closing.
 Other Parameters
 selemDEPRECATED
Deprecated in favor of footprint.
Deprecated since version 0.19.
Examples
>>> # Close a gap between two bright lines >>> import cupy as cp >>> from cucim.skimage.morphology import square >>> broken_line = cp.asarray([[0, 0, 0, 0, 0], ... [0, 0, 0, 0, 0], ... [1, 1, 0, 1, 1], ... [0, 0, 0, 0, 0], ... [0, 0, 0, 0, 0]], dtype=cp.uint8) >>> closing(broken_line, square(3)) array([[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [1, 1, 1, 1, 1], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]], dtype=uint8)
 cucim.skimage.morphology.cube(width, dtype=<class 'numpy.uint8'>)#
Generates a cubeshaped footprint.
This is the 3D equivalent of a square. Every pixel along the perimeter has a chessboard distance no greater than radius (radius=floor(width/2)) pixels.
 Parameters
 widthint
The width, height and depth of the cube.
 Returns
 footprintndarray
A footprint consisting only of ones, i.e. every pixel belongs to the neighborhood.
 Other Parameters
 dtypedatatype
The data type of the footprint.
 cucim.skimage.morphology.diamond(radius, dtype=<class 'numpy.uint8'>)#
Generates a flat, diamondshaped footprint.
A pixel is part of the neighborhood (i.e. labeled 1) if the city block/Manhattan distance between it and the center of the neighborhood is no greater than radius.
 Parameters
 radiusint
The radius of the diamondshaped footprint.
 Returns
 footprintndarray
The footprint where elements of the neighborhood are 1 and 0 otherwise.
 Other Parameters
 dtypedatatype
The data type of the footprint.
 cucim.skimage.morphology.dilation(image, footprint=None, out=None, shift_x=False, shift_y=False)#
Return grayscale morphological dilation of an image.
Morphological dilation sets the value of a pixel to the maximum over all pixel values within a local neighborhood centered about it. The values where the footprint is 1 define this neighborhood. Dilation enlarges bright regions and shrinks dark regions.
 Parameters
 imagendarray
Image array.
 footprintndarray, optional
The neighborhood expressed as an array of 1’s and 0’s. If None, use crossshaped footprint (connectivity=1).
 outndarray, optional
The array to store the result of the morphology. If None is passed, a new array will be allocated.
 shift_x, shift_ybool, optional
Shift footprint about center point. This only affects 2D eccentric footprints (i.e., footprints with evennumbered sides).
 Returns
 dilateduint8 array, same shape and type as image
The result of the morphological dilation.
 Other Parameters
 selemDEPRECATED
Deprecated in favor of footprint.
Deprecated since version 0.19.
Notes
For uint8 (and uint16 up to a certain bitdepth) data, the lower algorithm complexity makes the skimage.filters.rank.maximum function more efficient for larger images and footprints.
Examples
>>> # Dilation enlarges bright regions >>> import cupy as cp >>> from cucim.skimage.morphology import square >>> bright_pixel = cp.asarray([[0, 0, 0, 0, 0], ... [0, 0, 0, 0, 0], ... [0, 0, 1, 0, 0], ... [0, 0, 0, 0, 0], ... [0, 0, 0, 0, 0]], dtype=cp.uint8) >>> dilation(bright_pixel, square(3)) 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=uint8)
 cucim.skimage.morphology.disk(radius, dtype=<class 'numpy.uint8'>)#
Generates a flat, diskshaped footprint.
A pixel is within the neighborhood if the Euclidean distance between it and the origin is no greater than radius.
 Parameters
 radiusint
The radius of the diskshaped footprint.
 Returns
 footprintndarray
The footprint where elements of the neighborhood are 1 and 0 otherwise.
 Other Parameters
 dtypedatatype
The data type of the footprint.
 cucim.skimage.morphology.erosion(image, footprint=None, out=None, shift_x=False, shift_y=False)#
Return grayscale morphological erosion of an image.
Morphological erosion sets a pixel at (i,j) to the minimum over all pixels in the neighborhood centered at (i,j). Erosion shrinks bright regions and enlarges dark regions.
 Parameters
 imagendarray
Image array.
 footprintndarray, optional
The neighborhood expressed as an array of 1’s and 0’s. If None, use crossshaped footprint (connectivity=1).
 outndarrays, optional
The array to store the result of the morphology. If None is passed, a new array will be allocated.
 shift_x, shift_ybool, optional
shift footprint about center point. This only affects eccentric footprints (i.e. footprint with even numbered sides).
 Returns
 erodedarray, same shape as image
The result of the morphological erosion.
 Other Parameters
 selemDEPRECATED
Deprecated in favor of footprint.
Deprecated since version 0.19.
Notes
For
uint8
(anduint16
up to a certain bitdepth) data, the lower algorithm complexity makes the skimage.filters.rank.minimum function more efficient for larger images and footprints.Examples
>>> # Erosion shrinks bright regions >>> import cupy as cp >>> from cucim.skimage.morphology import square >>> bright_square = cp.asarray([[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=cp.uint8) >>> erosion(bright_square, square(3)) array([[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 1, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]], dtype=uint8)
 cucim.skimage.morphology.octagon(m, n, dtype=<class 'numpy.uint8'>)#
Generates an octagon shaped footprint.
For a given size of (m) horizontal and vertical sides and a given (n) height or width of slanted sides octagon is generated. The slanted sides are 45 or 135 degrees to the horizontal axis and hence the widths and heights are equal.
 Parameters
 mint
The size of the horizontal and vertical sides.
 nint
The height or width of the slanted sides.
 Returns
 footprintndarray
The footprint where elements of the neighborhood are 1 and 0 otherwise.
 Other Parameters
 dtypedatatype
The data type of the footprint.
 cucim.skimage.morphology.octahedron(radius, dtype=<class 'numpy.uint8'>)#
Generates a octahedronshaped footprint.
This is the 3D equivalent of a diamond. A pixel is part of the neighborhood (i.e. labeled 1) if the city block/Manhattan distance between it and the center of the neighborhood is no greater than radius.
 Parameters
 radiusint
The radius of the octahedronshaped footprint.
 Returns
 footprintndarray
The footprint where elements of the neighborhood are 1 and 0 otherwise.
 Other Parameters
 dtypedatatype
The data type of the footprint.
 cucim.skimage.morphology.opening(image, footprint=None, out=None)#
Return grayscale morphological opening of an image.
The morphological opening of an image is defined as an erosion followed by a dilation. Opening can remove small bright spots (i.e. “salt”) and connect small dark cracks. This tends to “open” up (dark) gaps between (bright) features.
 Parameters
 imagendarray
Image array.
 footprintndarray, optional
The neighborhood expressed as an array of 1’s and 0’s. If None, use crossshaped footprint (connectivity=1).
 outndarray, optional
The array to store the result of the morphology. If None is passed, a new array will be allocated.
 Returns
 openingarray, same shape and type as image
The result of the morphological opening.
 Other Parameters
 selemDEPRECATED
Deprecated in favor of footprint.
Deprecated since version 0.19.
Examples
>>> # Open up gap between two bright regions (but also shrink regions) >>> import cupy as cp >>> from cucim.skimage.morphology import square >>> bad_connection = cp.asarray([[1, 0, 0, 0, 1], ... [1, 1, 0, 1, 1], ... [1, 1, 1, 1, 1], ... [1, 1, 0, 1, 1], ... [1, 0, 0, 0, 1]], dtype=cp.uint8) >>> opening(bad_connection, square(3)) array([[0, 0, 0, 0, 0], [1, 1, 0, 1, 1], [1, 1, 0, 1, 1], [1, 1, 0, 1, 1], [0, 0, 0, 0, 0]], dtype=uint8)
 cucim.skimage.morphology.reconstruction(seed, mask, method='dilation', footprint=None, offset=None)#
Perform a morphological reconstruction of an image.
Morphological reconstruction by dilation is similar to basic morphological dilation: highintensity values will replace nearby lowintensity values. The basic dilation operator, however, uses a footprint to determine how far a value in the input image can spread. In contrast, reconstruction uses two images: a “seed” image, which specifies the values that spread, and a “mask” image, which gives the maximum allowed value at each pixel. The mask image, like the footprint, limits the spread of highintensity values. Reconstruction by erosion is simply the inverse: lowintensity values spread from the seed image and are limited by the mask image, which represents the minimum allowed value.
Alternatively, you can think of reconstruction as a way to isolate the connected regions of an image. For dilation, reconstruction connects regions marked by local maxima in the seed image: neighboring pixels lessthanorequalto those seeds are connected to the seeded region. Local maxima with values larger than the seed image will get truncated to the seed value.
 Parameters
 seedndarray
The seed image (a.k.a. marker image), which specifies the values that are dilated or eroded.
 maskndarray
The maximum (dilation) / minimum (erosion) allowed value at each pixel.
 method{‘dilation’’erosion’}, optional
Perform reconstruction by dilation or erosion. In dilation (or erosion), the seed image is dilated (or eroded) until limited by the mask image. For dilation, each seed value must be less than or equal to the corresponding mask value; for erosion, the reverse is true. Default is ‘dilation’.
 footprintndarray, optional
The neighborhood expressed as an nD array of 1’s and 0’s. Default is the nD square of radius equal to 1 (i.e. a 3x3 square for 2D images, a 3x3x3 cube for 3D images, etc.)
 offsetndarray, optional
The coordinates of the center of the footprint. Default is located on the geometrical center of the footprint, in that case footprint dimensions must be odd.
 Returns
 reconstructedndarray
The result of morphological reconstruction.
 Other Parameters
 selemDEPRECATED
Deprecated in favor of footprint.
Deprecated since version 0.19.
Notes
The algorithm is taken from [1]. Applications for grayscale reconstruction are discussed in [2] and [3].
References
 1
Robinson, “Efficient morphological reconstruction: a downhill filter”, Pattern Recognition Letters 25 (2004) 17591767.
 2
Vincent, L., “Morphological Grayscale Reconstruction in Image Analysis: Applications and Efficient Algorithms”, IEEE Transactions on Image Processing (1993)
 3
Soille, P., “Morphological Image Analysis: Principles and Applications”, Chapter 6, 2nd edition (2003), ISBN 3540429883.
Examples
>>> import cupy as cp >>> from cucim.skimage.morphology import reconstruction
First, we create a sinusoidal mask image with peaks at middle and ends.
>>> x = cp.linspace(0, 4 * np.pi) >>> y_mask = cp.cos(x)
Then, we create a seed image initialized to the minimum mask value (for reconstruction by dilation, minintensity values don’t spread) and add “seeds” to the left and right peak, but at a fraction of peak value (1).
>>> y_seed = y_mask.min() * cp.ones_like(x) >>> y_seed[0] = 0.5 >>> y_seed[1] = 0 >>> y_rec = reconstruction(y_seed, y_mask)
The reconstructed image (or curve, in this case) is exactly the same as the mask image, except that the peaks are truncated to 0.5 and 0. The middle peak disappears completely: Since there were no seed values in this peak region, its reconstructed value is truncated to the surrounding value (1).
As a more practical example, we try to extract the bright features of an image by subtracting a background image created by reconstruction.
>>> y, x = cp.mgrid[:20:0.5, :20:0.5] >>> bumps = cp.sin(x) + cp.sin(y)
To create the background image, set the mask image to the original image, and the seed image to the original image with an intensity offset, h.
>>> h = 0.3 >>> seed = bumps  h >>> background = reconstruction(seed, bumps)
The resulting reconstructed image looks exactly like the original image, but with the peaks of the bumps cut off. Subtracting this reconstructed image from the original image leaves just the peaks of the bumps
>>> hdome = bumps  background
This operation is known as the hdome of the image and leaves features of height h in the subtracted image.
 cucim.skimage.morphology.rectangle(nrows, ncols, dtype=<class 'numpy.uint8'>)#
Generates a flat, rectangularshaped footprint.
Every pixel in the rectangle generated for a given width and given height belongs to the neighborhood.
 Parameters
 nrowsint
The number of rows of the rectangle.
 ncolsint
The number of columns of the rectangle.
 Returns
 footprintndarray
A footprint consisting only of ones, i.e. every pixel belongs to the neighborhood.
 Other Parameters
 dtypedatatype
The data type of the footprint.
 heightDEPRECATED
Deprecated in favor of ncols.
Deprecated since version 0.18.0.
 widthDEPRECATED
Deprecated in favor of nrows.
Deprecated since version 0.18.0.
Notes
The use of
width
andheight
has been deprecated in version 0.18.0. Usenrows
andncols
instead.
 cucim.skimage.morphology.remove_small_holes(ar, area_threshold=64, connectivity=1, in_place=False, *, out=None)#
Remove contiguous holes smaller than the specified size.
 Parameters
 arndarray (arbitrary shape, int or bool type)
The array containing the connected components of interest.
 area_thresholdint, optional (default: 64)
The maximum area, in pixels, of a contiguous hole that will be filled. Replaces min_size.
 connectivityint, {1, 2, …, ar.ndim}, optional (default: 1)
The connectivity defining the neighborhood of a pixel.
 in_placebool, optional (default: False)
If True, remove the connected components in the input array itself. Otherwise, make a copy. Deprecated since version 0.19. Please use out instead.
 outndarray
Array of the same shape as ar and bool dtype, into which the output is placed. By default, a new array is created.
 Returns
 outndarray, same shape and type as input ar
The input array with small holes within connected components removed.
 Raises
 TypeError
If the input array is of an invalid type, such as float or string.
 ValueError
If the input array contains negative values.
Notes
If the array type is int, it is assumed that it contains alreadylabeled objects. The labels are not kept in the output image (this function always outputs a bool image). It is suggested that labeling is completed after using this function.
Examples
>>> import cupy as cp >>> from cucim.skimage import morphology >>> a = cp.array([[1, 1, 1, 1, 1, 0], ... [1, 1, 1, 0, 1, 0], ... [1, 0, 0, 1, 1, 0], ... [1, 1, 1, 1, 1, 0]], bool) >>> b = morphology.remove_small_holes(a, 2) >>> b array([[ True, True, True, True, True, False], [ True, True, True, True, True, False], [ True, False, False, True, True, False], [ True, True, True, True, True, False]]) >>> c = morphology.remove_small_holes(a, 2, connectivity=2) >>> c array([[ True, True, True, True, True, False], [ True, True, True, False, True, False], [ True, False, False, True, True, False], [ True, True, True, True, True, False]]) >>> d = morphology.remove_small_holes(a, 2, in_place=True) >>> d is a True
 cucim.skimage.morphology.remove_small_objects(ar, min_size=64, connectivity=1, in_place=False, *, out=None)#
Remove objects smaller than the specified size.
Expects ar to be an array with labeled objects, and removes objects smaller than min_size. If ar is bool, the image is first labeled. This leads to potentially different behavior for bool and 0and1 arrays.
 Parameters
 arndarray (arbitrary shape, int or bool type)
The array containing the objects of interest. If the array type is int, the ints must be nonnegative.
 min_sizeint, optional (default: 64)
The smallest allowable object size.
 connectivityint, {1, 2, …, ar.ndim}, optional (default: 1)
The connectivity defining the neighborhood of a pixel. Used during labelling if ar is bool.
 in_placebool, optional (default: False)
If
True
, remove the objects in the input array itself. Otherwise, make a copy. Deprecated since version 0.19. Please use out instead. outndarray
Array of the same shape as ar, into which the output is placed. By default, a new array is created.
 Returns
 outndarray, same shape and type as input ar
The input array with small connected components removed.
 Raises
 TypeError
If the input array is of an invalid type, such as float or string.
 ValueError
If the input array contains negative values.
Examples
>>> import cupy as cp >>> from cucim.skimage import morphology >>> a = cp.array([[0, 0, 0, 1, 0], ... [1, 1, 1, 0, 0], ... [1, 1, 1, 0, 1]], bool) >>> b = morphology.remove_small_objects(a, 6) >>> b array([[False, False, False, False, False], [ True, True, True, False, False], [ True, True, True, False, False]]) >>> c = morphology.remove_small_objects(a, 7, connectivity=2) >>> c array([[False, False, False, True, False], [ True, True, True, False, False], [ True, True, True, False, False]]) >>> d = morphology.remove_small_objects(a, 6, in_place=True) >>> d is a True
 cucim.skimage.morphology.square(width, dtype=<class 'numpy.uint8'>)#
Generates a flat, squareshaped footprint.
Every pixel along the perimeter has a chessboard distance no greater than radius (radius=floor(width/2)) pixels.
 Parameters
 widthint
The width and height of the square.
 Returns
 footprintndarray
A footprint consisting only of ones, i.e. every pixel belongs to the neighborhood.
 Other Parameters
 dtypedatatype
The data type of the footprint.
 cucim.skimage.morphology.star(a, dtype=<class 'numpy.uint8'>)#
Generates a star shaped footprint.
Start has 8 vertices and is an overlap of square of size 2*a + 1 with its 45 degree rotated version. The slanted sides are 45 or 135 degrees to the horizontal axis.
 Parameters
 aint
Parameter deciding the size of the star structural element. The side of the square array returned is 2*a + 1 + 2*floor(a / 2).
 Returns
 footprintndarray
The footprint where elements of the neighborhood are 1 and 0 otherwise.
 Other Parameters
 dtypedatatype
The data type of the footprint.
 cucim.skimage.morphology.thin(image, max_num_iter=None)#
Perform morphological thinning of a binary image.
 Parameters
 imagebinary (M, N) ndarray
The image to be thinned.
 max_num_iterint, number of iterations, optional
Regardless of the value of this parameter, the thinned image is returned immediately if an iteration produces no change. If this parameter is specified it thus sets an upper bound on the number of iterations performed.
 Returns
 outndarray of bool
Thinned image.
 Other Parameters
 max_iterDEPRECATED
Deprecated in favor of max_num_iter.
Deprecated since version 0.19.
See also
skeletonize()
,medial_axis()
Notes
This algorithm [1] works by making multiple passes over the image, removing pixels matching a set of criteria designed to thin connected regions while preserving eightconnected components and 2 x 2 squares [2]. In each of the two subiterations the algorithm correlates the intermediate skeleton image with a neighborhood mask, then looks up each neighborhood in a lookup table indicating whether the central pixel should be deleted in that subiteration.
References
 1
Z. Guo and R. W. Hall, “Parallel thinning with twosubiteration algorithms,” Comm. ACM, vol. 32, no. 3, pp. 359373, 1989. DOI:10.1145/62065.62074
 2
Lam, L., SeongWhan Lee, and Ching Y. Suen, “Thinning MethodologiesA Comprehensive Survey,” IEEE Transactions on Pattern Analysis and Machine Intelligence, Vol 14, No. 9, p. 879, 1992. DOI:10.1109/34.161346
Examples
>>> square = np.zeros((7, 7), dtype=np.uint8) >>> square[1:1, 2:2] = 1 >>> square[0, 1] = 1 >>> square array([[0, 1, 0, 0, 0, 0, 0], [0, 0, 1, 1, 1, 0, 0], [0, 0, 1, 1, 1, 0, 0], [0, 0, 1, 1, 1, 0, 0], [0, 0, 1, 1, 1, 0, 0], [0, 0, 1, 1, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0]], dtype=uint8) >>> skel = thin(square) >>> skel.astype(np.uint8) array([[0, 1, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0]], dtype=uint8)
 cucim.skimage.morphology.white_tophat(image, footprint=None, out=None)#
Return white top hat of an image.
The white top hat of an image is defined as the image minus its morphological opening. This operation returns the bright spots of the image that are smaller than the footprint.
 Parameters
 imagendarray
Image array.
 footprintndarray, optional
The neighborhood expressed as an array of 1’s and 0’s. If None, use crossshaped footprint (connectivity=1).
 outndarray, optional
The array to store the result of the morphology. If None is passed, a new array will be allocated.
 Returns
 outarray, same shape and type as image
The result of the morphological white top hat.
 Other Parameters
 selemDEPRECATED
Deprecated in favor of footprint.
Deprecated since version 0.19.
See also
References
Examples
>>> # Subtract grey background from bright peak >>> import cupy as cp >>> from cucim.skimage.morphology import square >>> bright_on_grey = cp.asarray([[2, 3, 3, 3, 2], ... [3, 4, 5, 4, 3], ... [3, 5, 9, 5, 3], ... [3, 4, 5, 4, 3], ... [2, 3, 3, 3, 2]], dtype=cp.uint8) >>> white_tophat(bright_on_grey, square(3)) array([[0, 0, 0, 0, 0], [0, 0, 1, 0, 0], [0, 1, 5, 1, 0], [0, 0, 1, 0, 0], [0, 0, 0, 0, 0]], dtype=uint8)
registration#
 cucim.skimage.registration.optical_flow_ilk(reference_image, moving_image, *, radius=7, num_warp=10, gaussian=False, prefilter=False, dtype=<class 'numpy.float32'>)#
Coarse to fine optical flow estimator.
The iterative LucasKanade (iLK) solver is applied at each level of the image pyramid. iLK [1] is a fast and robust alternative to TVL1 algorithm although less accurate for rendering flat surfaces and object boundaries (see [2]).
 Parameters
 reference_imagendarray, shape (M, N[, P[, …]])
The first gray scale image of the sequence.
 moving_imagendarray, shape (M, N[, P[, …]])
The second gray scale image of the sequence.
 radiusint, optional
Radius of the window considered around each pixel.
 num_warpint, optional
Number of times moving_image is warped.
 gaussianbool, optional
If True, a Gaussian kernel is used for the local integration. Otherwise, a uniform kernel is used.
 prefilterbool, optional
Whether to prefilter the estimated optical flow before each image warp. When True, a median filter with window size 3 along each axis is applied. This helps to remove potential outliers.
 dtypedtype, optional
Output data type: must be floating point. Single precision provides good results and saves memory usage and computation time compared to double precision.
 Returns
 flowndarray, shape ((reference_image.ndim, M, N[, P[, …]])
The estimated optical flow components for each axis.
Notes
The implemented algorithm is described in Table2 of [1].
Color images are not supported.
References
 1(1,2)
Le Besnerais, G., & Champagnat, F. (2005, September). Dense optical flow by iterative local window registration. In IEEE International Conference on Image Processing 2005 (Vol. 1, pp. I137). IEEE. DOI:10.1109/ICIP.2005.1529706
 2
Plyer, A., Le Besnerais, G., & Champagnat, F. (2016). Massively parallel Lucas Kanade optical flow for realtime video processing applications. Journal of RealTime Image Processing, 11(4), 713730. DOI:10.1007/s1155401404230
Examples
>>> import cupy as cp >>> from skimage.data import stereo_motorcycle >>> from cucim.skimage.color import rgb2gray >>> from cucim.skimage.registration import optical_flow_ilk >>> reference_image, moving_image, disp = map(cp.array, stereo_motorcycle()) >>> #  Convert the images to gray level: color is not supported. >>> reference_image = rgb2gray(reference_image) >>> moving_image = rgb2gray(moving_image) >>> flow = optical_flow_ilk(moving_image, reference_image)
 cucim.skimage.registration.optical_flow_tvl1(reference_image, moving_image, *, attachment=15, tightness=0.3, num_warp=5, num_iter=10, tol=0.0001, prefilter=False, dtype=<class 'numpy.float32'>)#
Coarse to fine optical flow estimator.
The TVL1 solver is applied at each level of the image pyramid. TVL1 is a popular algorithm for optical flow estimation introduced by Zack et al. [1], improved in [2] and detailed in [3].
 Parameters
 reference_imagendarray, shape (M, N[, P[, …]])
The first gray scale image of the sequence.
 moving_imagendarray, shape (M, N[, P[, …]])
The second gray scale image of the sequence.
 attachmentfloat, optional
Attachment parameter (\(\lambda\) in [1]). The smaller this parameter is, the smoother the returned result will be.
 tightnessfloat, optional
Tightness parameter (\(\tau\) in [1]). It should have a small value in order to maintain attachement and regularization parts in correspondence.
 num_warpint, optional
Number of times image1 is warped.
 num_iterint, optional
Number of fixed point iteration.
 tolfloat, optional
Tolerance used as stopping criterion based on the L² distance between two consecutive values of (u, v).
 prefilterbool, optional
Whether to prefilter the estimated optical flow before each image warp. When True, a median filter with window size 3 along each axis is applied. This helps to remove potential outliers.
 dtypedtype, optional
Output data type: must be floating point. Single precision provides good results and saves memory usage and computation time compared to double precision.
 Returns
 flowndarray, shape ((image0.ndim, M, N[, P[, …]])
The estimated optical flow components for each axis.
Notes
Color images are not supported.
References
 1(1,2,3)
Zach, C., Pock, T., & Bischof, H. (2007, September). A duality based approach for realtime TVL 1 optical flow. In Joint pattern recognition symposium (pp. 214223). Springer, Berlin, Heidelberg. DOI:10.1007/9783540749363_22
 2
Wedel, A., Pock, T., Zach, C., Bischof, H., & Cremers, D. (2009). An improved algorithm for TVL 1 optical flow. In Statistical and geometrical approaches to visual motion analysis (pp. 2345). Springer, Berlin, Heidelberg. DOI:10.1007/9783642030611_2
 3
Pérez, J. S., MeinhardtLlopis, E., & Facciolo, G. (2013). TVL1 optical flow estimation. Image Processing On Line, 2013, 137150. DOI:10.5201/ipol.2013.26
Examples
>>> import cupy as cp >>> from cucim.skimage.color import rgb2gray >>> from skimage.data import stereo_motorcycle >>> from cucim.skimage.registration import optical_flow_tvl1 >>> image0, image1, disp = [cp.array(a) for a in stereo_motorcycle()] >>> #  Convert the images to gray level: color is not supported. >>> image0 = rgb2gray(image0) >>> image1 = rgb2gray(image1) >>> flow = optical_flow_tvl1(image1, image0)
 cucim.skimage.registration.phase_cross_correlation(reference_image, moving_image, *, upsample_factor=1, space='real', return_error=True, reference_mask=None, moving_mask=None, overlap_ratio=0.3, normalization='phase')#
Efficient subpixel image translation registration by crosscorrelation.
This code gives the same precision as the FFT upsampled crosscorrelation in a fraction of the computation time and with reduced memory requirements. It obtains an initial estimate of the crosscorrelation peak by an FFT and then refines the shift estimation by upsampling the DFT only in a small neighborhood of that estimate by means of a matrixmultiply DFT [1].
 Parameters
 reference_imagearray
Reference image.
 moving_imagearray
Image to register. Must be same dimensionality as
reference_image
. upsample_factorint, optional
Upsampling factor. Images will be registered to within
1 / upsample_factor
of a pixel. For exampleupsample_factor == 20
means the images will be registered within 1/20th of a pixel. Default is 1 (no upsampling). Not used if any ofreference_mask
ormoving_mask
is not None. spacestring, one of “real” or “fourier”, optional
Defines how the algorithm interprets input data. “real” means data will be FFT’d to compute the correlation, while “fourier” data will bypass FFT of input data. Case insensitive. Not used if any of
reference_mask
ormoving_mask
is not None. return_errorbool, optional
Returns error and phase difference if on, otherwise only shifts are returned. Has noeffect if any of
reference_mask
ormoving_mask
is not None. In this case only shifts is returned. reference_maskndarray
Boolean mask for
reference_image
. The mask should evaluate toTrue
(or 1) on valid pixels.reference_mask
should have the same shape asreference_image
. moving_maskndarray or None, optional
Boolean mask for
moving_image
. The mask should evaluate toTrue
(or 1) on valid pixels.moving_mask
should have the same shape asmoving_image
. IfNone
,reference_mask
will be used. overlap_ratiofloat, optional
Minimum allowed overlap ratio between images. The correlation for translations corresponding with an overlap ratio lower than this threshold will be ignored. A lower overlap_ratio leads to smaller maximum translation, while a higher overlap_ratio leads to greater robustness against spurious matches due to small overlap between masked images. Used only if one of
reference_mask
ormoving_mask
is None. normalization{“phase”, None}
The type of normalization to apply to the crosscorrelation. This parameter is unused when masks (reference_mask and moving_mask) are supplied.
 Returns
 shiftsndarray
Shift vector (in pixels) required to register
moving_image
withreference_image
. Axis ordering is consistent with numpy (e.g. Z, Y, X) errorfloat
Translation invariant normalized RMS error between
reference_image
andmoving_image
. phasedifffloat
Global phase difference between the two images (should be zero if images are nonnegative).
Notes
The use of crosscorrelation to estimate image translation has a long history dating back to at least [2]. The “phase correlation” method (selected by
normalization="phase"
) was first proposed in [3]. Publications [1] and [2] use an unnormalized crosscorrelation (normalization=None
). Which form of normalization is better is applicationdependent. For example, the phase correlation method works well in registering images under different illumination, but is not very robust to noise. In a high noise scenario, the unnormalized method may be preferable.When masks are provided, a masked normalized crosscorrelation algorithm is used [5], [6].
References
 1(1,2)
Manuel GuizarSicairos, Samuel T. Thurman, and James R. Fienup, “Efficient subpixel image registration algorithms,” Optics Letters 33, 156158 (2008). DOI:10.1364/OL.33.000156
 2(1,2)
P. Anuta, Spatial registration of multispectral and multitemporal digital imagery using fast Fourier transform techniques, IEEE Trans. Geosci. Electron., vol. 8, no. 4, pp. 353–368, Oct. 1970. DOI:10.1109/TGE.1970.271435.
 3
C. D. Kuglin D. C. Hines. The phase correlation image alignment method, Proceeding of IEEE International Conference on Cybernetics and Society, pp. 163165, New York, NY, USA, 1975, pp. 163–165.
 4
James R. Fienup, “Invariant error metrics for image reconstruction” Optics Letters 36, 83528357 (1997). DOI:10.1364/AO.36.008352
 5
Dirk Padfield. Masked Object Registration in the Fourier Domain. IEEE Transactions on Image Processing, vol. 21(5), pp. 27062718 (2012). DOI:10.1109/TIP.2011.2181402
 6
D. Padfield. “Masked FFT registration”. In Proc. Computer Vision and Pattern Recognition, pp. 29182925 (2010). DOI:10.1109/CVPR.2010.5540032
restoration#
 cucim.skimage.restoration.calibrate_denoiser(image, denoise_function, denoise_parameters, *, stride=4, approximate_loss=True, extra_output=False)#
Calibrate a denoising function and return optimal Jinvariant version.
The returned function is partially evaluated with optimal parameter values set for denoising the input image.
 Parameters
 imagendarray
Input data to be denoised (converted using img_as_float).
 denoise_functionfunction
Denoising function to be calibrated.
 denoise_parametersdict of list
Ranges of parameters for denoise_function to be calibrated over.
 strideint, optional
Stride used in masking procedure that converts denoise_function to Jinvariance.
 approximate_lossbool, optional
Whether to approximate the selfsupervised loss used to evaluate the denoiser by only computing it on one masked version of the image. If False, the runtime will be a factor of stride**image.ndim longer.
 extra_outputbool, optional
If True, return parameters and losses in addition to the calibrated denoising function
 Returns
 best_denoise_functionfunction
The optimal Jinvariant version of denoise_function.
 If extra_output is True, the following tuple is also returned:
 (parameters_tested, losses)tuple (list of dict, list of int)
List of parameters tested for denoise_function, as a dictionary of kwargs Selfsupervised loss for each set of parameters in parameters_tested.
Notes
The calibration procedure uses a selfsupervised meansquareerror loss to evaluate the performance of Jinvariant versions of denoise_function. The minimizer of the selfsupervised loss is also the minimizer of the groundtruth loss (i.e., the true MSE error) [1]. The returned function can be used on the original noisy image, or other images with similar characteristics.
 Increasing the stride increases the performance of best_denoise_function
at the expense of increasing its runtime. It has no effect on the runtime of the calibration.
References
 1
J. Batson & L. Royer. Noise2Self: Blind Denoising by SelfSupervision, International Conference on Machine Learning, p. 524533 (2019).
Examples
>>> import cupy as cp >>> from cucim.skimage import color >>> from skimage import data >>> from cucim.skimage.restoration import (denoise_tv_chambolle, ... calibrate_denoiser) >>> img = color.rgb2gray(cp.array(data.astronaut()[:50, :50])) >>> noisy = img + 0.5 * img.std() * cp.random.randn(*img.shape) >>> parameters = {'weight': cp.arange(0.01, 0.5, 0.05)} >>> denoising_function = calibrate_denoiser(noisy, denoise_tv_chambolle, ... denoise_parameters=parameters) >>> denoised_img = denoising_function(img)
 cucim.skimage.restoration.denoise_tv_chambolle(image, weight=0.1, eps=0.0002, max_num_iter=200, multichannel=False, *, channel_axis=None)#
Perform totalvariation denoising on ndimensional images.
 Parameters
 imagendarray of ints, uints or floats
Input data to be denoised. image can be of any numeric type, but it is cast into an ndarray of floats for the computation of the denoised image.
 weightfloat, optional
Denoising weight. The greater weight, the more denoising (at the expense of fidelity to input).
 epsfloat, optional
Relative difference of the value of the cost function that determines the stop criterion. The algorithm stops when:
(E_(n1)  E_n) < eps * E_0
 max_num_iterint, optional
Maximal number of iterations used for the optimization.
 multichannelbool, optional
Apply totalvariation denoising separately for each channel. This option should be true for color images, otherwise the denoising is also applied in the channels dimension. This argument is deprecated: specify channel_axis instead.
 channel_axisint or None, optional
If None, the image is assumed to be a grayscale (single channel) image. Otherwise, this parameter indicates which axis of the array corresponds to channels.
 Returns
 outndarray
Denoised image.
 Other Parameters
 multichannelDEPRECATED
Deprecated in favor of channel_axis.
Deprecated since version 0.19.
 n_iter_maxDEPRECATED
Deprecated in favor of max_num_iter.
Deprecated since version 0.19.2.
Notes
Make sure to set the multichannel parameter appropriately for color images.
The principle of total variation denoising is explained in https://en.wikipedia.org/wiki/Total_variation_denoising
The principle of total variation denoising is to minimize the total variation of the image, which can be roughly described as the integral of the norm of the image gradient. Total variation denoising tends to produce “cartoonlike” images, that is, piecewiseconstant images.
This code is an implementation of the algorithm of Rudin, Fatemi and Osher that was proposed by Chambolle in [1].
References
 1
A. Chambolle, An algorithm for total variation minimization and applications, Journal of Mathematical Imaging and Vision, Springer, 2004, 20, 8997.
Examples
2D example on astronaut image:
>>> import cupy as cp >>> from cucim.skimage import color >>> from skimage import data >>> img = color.rgb2gray(cp.array(data.astronaut()[:50, :50])) >>> img += 0.5 * img.std() * cp.random.randn(*img.shape) >>> denoised_img = denoise_tv_chambolle(img, weight=60)
3D example on synthetic data:
>>> x, y, z = cp.ogrid[0:20, 0:20, 0:20] >>> mask = (x  22)**2 + (y  20)**2 + (z  17)**2 < 8**2 >>> mask = mask.astype(float) >>> mask += 0.2*cp.random.randn(*mask.shape) >>> res = denoise_tv_chambolle(mask, weight=100)
 cucim.skimage.restoration.richardson_lucy(image, psf, num_iter=50, clip=True, filter_epsilon=None)#
RichardsonLucy deconvolution.
 Parameters
 imagendarray
Input degraded image (can be N dimensional).
 psfndarray
The point spread function.
 num_iterint, optional
Number of iterations. This parameter plays the role of regularisation.
 clipboolean, optional
True by default. If true, pixel value of the result above 1 or under 1 are thresholded for skimage pipeline compatibility.
 filter_epsilon: float, optional
Value below which intermediate results become 0 to avoid division by small numbers.
 Returns
 im_deconvndarray
The deconvolved image.
 Other Parameters
 iterationsDEPRECATED
Deprecated in favor of num_iter.
Deprecated since version 0.19.
References
Examples
>>> import cupy as cp >>> from cucim.skimage import img_as_float, restoration >>> from skimage import data >>> camera = cp.asarray(img_as_float(cp.array(data.camera()))) >>> from cupyx.scipy.signal import convolve2d >>> psf = cp.ones((5, 5)) / 25 >>> camera = convolve2d(camera, psf, 'same') >>> camera += 0.1 * camera.std() * cp.random.standard_normal(camera.shape) >>> deconvolved = restoration.richardson_lucy(camera, psf, 5)
 cucim.skimage.restoration.unsupervised_wiener(image, psf, reg=None, user_params=None, is_real=True, clip=True, *, random_state=None)#
Unsupervised WienerHunt deconvolution.
Return the deconvolution with a WienerHunt approach, where the hyperparameters are automatically estimated. The algorithm is a stochastic iterative process (Gibbs sampler) described in the reference below. See also
wiener
function. Parameters
 image(M, N) ndarray
The input degraded image.
 psfndarray
The impulse response (input image’s space) or the transfer function (Fourier space). Both are accepted. The transfer function is automatically recognized as being complex (
cupy.iscomplexobj(psf)
). regndarray, optional
The regularisation operator. The Laplacian by default. It can be an impulse response or a transfer function, as for the psf.
 user_paramsdict, optional
Dictionary of parameters for the Gibbs sampler. See below.
 clipboolean, optional
True by default. If true, pixel values of the result above 1 or under 1 are thresholded for skimage pipeline compatibility.
 random_state{None, int, cupy.random.Generator}, optional
If random_state is None the cupy.random.Generator singleton is used. If random_state is an int, a new
Generator
instance is used, seeded with random_state. If random_state is already aGenerator
instance then that instance is used.
 Returns
 x_postmean(M, N) ndarray
The deconvolved image (the posterior mean).
 chainsdict
The keys
noise
andprior
contain the chain list of noise and prior precision respectively.
 Other Parameters
 The keys of ``user_params`` are:
 thresholdfloat
The stopping criterion: the norm of the difference between to successive approximated solution (empirical mean of object samples, see Notes section). 1e4 by default.
 burninint
The number of sample to ignore to start computation of the mean. 15 by default.
 min_num_iterint
The minimum number of iterations. 30 by default.
 max_num_iterint
The maximum number of iterations if
threshold
is not satisfied. 200 by default. callbackcallable (None by default)
A user provided callable to which is passed, if the function exists, the current image sample for whatever purpose. The user can store the sample, or compute other moments than the mean. It has no influence on the algorithm execution and is only for inspection.
Notes
The estimated image is design as the posterior mean of a probability law (from a Bayesian analysis). The mean is defined as a sum over all the possible images weighted by their respective probability. Given the size of the problem, the exact sum is not tractable. This algorithm use of MCMC to draw image under the posterior law. The practical idea is to only draw highly probable images since they have the biggest contribution to the mean. At the opposite, the less probable images are drawn less often since their contribution is low. Finally the empirical mean of these samples give us an estimation of the mean, and an exact computation with an infinite sample set.
References
 1
François Orieux, JeanFrançois Giovannelli, and Thomas Rodet, “Bayesian estimation of regularization and point spread function parameters for WienerHunt deconvolution”, J. Opt. Soc. Am. A 27, 15931607 (2010)
https://www.osapublishing.org/josaa/abstract.cfm?URI=josaa2771593
Examples
>>> import cupy as cp >>> import cupyx.scipy.ndimage as ndi >>> from cucim.skimage import color, restoration >>> from skimage import data >>> img = color.rgb2gray(cp.array(data.astronaut())) >>> psf = cp.ones((5, 5)) / 25 >>> img = ndi.uniform_filter(img, size=psf.shape) >>> img += 0.1 * img.std() * cp.random.standard_normal(img.shape) >>> deconvolved_img = restoration.unsupervised_wiener(img, psf)
 cucim.skimage.restoration.wiener(image, psf, balance, reg=None, is_real=True, clip=True)#
WienerHunt deconvolution
Return the deconvolution with a WienerHunt approach (i.e. with Fourier diagonalisation).
 Parameters
 image(M, N) ndarray
Input degraded image
 psfndarray
Point Spread Function. This is assumed to be the impulse response (input image space) if the datatype is real, or the transfer function (Fourier space) if the datatype is complex. There is no constraints on the shape of the impulse response. The transfer function must be of shape (M, N) if is_real is True, (M, N // 2 + 1) otherwise (see cupy.fft.rfftn).
 balancefloat
The regularisation parameter value that tunes the balance between the data adequacy that improve frequency restoration and the prior adequacy that reduce frequency restoration (to avoid noise artifacts).
 regndarray, optional
The regularisation operator. The Laplacian by default. It can be an impulse response or a transfer function, as for the psf. Shape constraint is the same as for the psf parameter.
 is_realboolean, optional
True by default. Specify if
psf
andreg
are provided with hermitian hypothesis, that is only half of the frequency plane is provided (due to the redundancy of Fourier transform of real signal). It’s apply only ifpsf
and/orreg
are provided as transfer function. For the hermitian property seeuft
module orcupy.fft.rfftn
. clipboolean, optional
True by default. If True, pixel values of the result above 1 or under 1 are thresholded for skimage pipeline compatibility.
 Returns
 im_deconv(M, N) ndarray
The deconvolved image.
Notes
This function applies the Wiener filter to a noisy and degraded image by an impulse response (or PSF). If the data model is
\[y = Hx + n\]where \(n\) is noise, \(H\) the PSF and \(x\) the unknown original image, the Wiener filter is
\[\hat x = F^\dagger (\Lambda_H^2 + \lambda \Lambda_D^2) \Lambda_H^\dagger F y\]where \(F\) and \(F^\dagger\) are the Fourier and inverse Fourier transforms respectively, \(\Lambda_H\) the transfer function (or the Fourier transform of the PSF, see [Hunt] below) and \(\Lambda_D\) the filter to penalize the restored image frequencies (Laplacian by default, that is penalization of high frequency). The parameter \(\lambda\) tunes the balance between the data (that tends to increase high frequency, even those coming from noise), and the regularization.
These methods are then specific to a prior model. Consequently, the application or the true image nature must corresponds to the prior model. By default, the prior model (Laplacian) introduce image smoothness or pixel correlation. It can also be interpreted as highfrequency penalization to compensate the instability of the solution with respect to the data (sometimes called noise amplification or “explosive” solution).
Finally, the use of Fourier space implies a circulant property of \(H\), see [Hunt].
References
 1
François Orieux, JeanFrançois Giovannelli, and Thomas Rodet, “Bayesian estimation of regularization and point spread function parameters for WienerHunt deconvolution”, J. Opt. Soc. Am. A 27, 15931607 (2010)
https://www.osapublishing.org/josaa/abstract.cfm?URI=josaa2771593
 2
B. R. Hunt “A matrix theory proof of the discrete convolution theorem”, IEEE Trans. on Audio and Electroacoustics, vol. au19, no. 4, pp. 285288, dec. 1971
Examples
>>> import cupy as cp >>> import cupyx.scipy.ndimage as ndi >>> from cucim.skimage import color, restoration >>> from skimage import data >>> img = color.rgb2gray(cp.array(data.astronaut())) >>> psf = cp.ones((5, 5)) / 25 >>> img = ndi.uniform_filter(img, size=psf.shape) >>> img += 0.1 * img.std() * cp.random.standard_normal(img.shape) >>> deconvolved_img = restoration.wiener(img, psf, 1100)
segmentation#
 cucim.skimage.segmentation.checkerboard_level_set(image_shape, square_size=5)#
Create a checkerboard level set with binary values.
 Parameters
 image_shapetuple of positive integers
Shape of the image.
 square_sizeint, optional
Size of the squares of the checkerboard. It defaults to 5.
 Returns
 outarray with shape image_shape
Binary level set of the checkerboard.
See also
 cucim.skimage.segmentation.disk_level_set(image_shape, *, center=None, radius=None)#
Create a disk level set with binary values.
 Parameters
 image_shapetuple of positive integers
Shape of the image
 centertuple of positive integers, optional
Coordinates of the center of the disk given in (row, column). If not given, it defaults to the center of the image.
 radiusfloat, optional
Radius of the disk. If not given, it is set to the 75% of the smallest image dimension.
 Returns
 outarray with shape image_shape
Binary level set of the disk with the given radius and center.
See also
 cucim.skimage.segmentation.find_boundaries(label_img, connectivity=1, mode='thick', background=0)#
Return bool array where boundaries between labeled regions are True.
 Parameters
 label_imgarray of int or bool
An array in which different regions are labeled with either different integers or boolean values.
 connectivityint in {1, …, label_img.ndim}, optional
A pixel is considered a boundary pixel if any of its neighbors has a different label. connectivity controls which pixels are considered neighbors. A connectivity of 1 (default) means pixels sharing an edge (in 2D) or a face (in 3D) will be considered neighbors. A connectivity of label_img.ndim means pixels sharing a corner will be considered neighbors.
 modestring in {‘thick’, ‘inner’, ‘outer’, ‘subpixel’}
How to mark the boundaries:
thick: any pixel not completely surrounded by pixels of the same label (defined by connectivity) is marked as a boundary. This results in boundaries that are 2 pixels thick.
inner: outline the pixels just inside of objects, leaving background pixels untouched.
outer: outline pixels in the background around object boundaries. When two objects touch, their boundary is also marked.
subpixel: return a doubled image, with pixels between the original pixels marked as boundary where appropriate.
 backgroundint, optional
For modes ‘inner’ and ‘outer’, a definition of a background label is required. See mode for descriptions of these two.
 Returns
 boundariesarray of bool, same shape as label_img
A bool image where
True
represents a boundary pixel. For mode equal to ‘subpixel’,boundaries.shape[i]
is equal to2 * label_img.shape[i]  1
for alli
(a pixel is inserted in between all other pairs of pixels).
Examples
>>> labels = cp.array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], ... [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], ... [0, 0, 0, 0, 0, 5, 5, 5, 0, 0], ... [0, 0, 1, 1, 1, 5, 5, 5, 0, 0], ... [0, 0, 1, 1, 1, 5, 5, 5, 0, 0], ... [0, 0, 1, 1, 1, 5, 5, 5, 0, 0], ... [0, 0, 0, 0, 0, 5, 5, 5, 0, 0], ... [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], ... [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], dtype=cp.uint8) >>> find_boundaries(labels, mode='thick').astype(cp.uint8) array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 1, 1, 1, 0, 0], [0, 0, 1, 1, 1, 1, 1, 1, 1, 0], [0, 1, 1, 1, 1, 1, 0, 1, 1, 0], [0, 1, 1, 0, 1, 1, 0, 1, 1, 0], [0, 1, 1, 1, 1, 1, 0, 1, 1, 0], [0, 0, 1, 1, 1, 1, 1, 1, 1, 0], [0, 0, 0, 0, 0, 1, 1, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], dtype=uint8) >>> find_boundaries(labels, mode='inner').astype(cp.uint8) array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 1, 1, 1, 0, 0], [0, 0, 1, 1, 1, 1, 0, 1, 0, 0], [0, 0, 1, 0, 1, 1, 0, 1, 0, 0], [0, 0, 1, 1, 1, 1, 0, 1, 0, 0], [0, 0, 0, 0, 0, 1, 1, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], dtype=uint8) >>> find_boundaries(labels, mode='outer').astype(cp.uint8) array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 1, 1, 1, 0, 0], [0, 0, 1, 1, 1, 1, 0, 0, 1, 0], [0, 1, 0, 0, 1, 1, 0, 0, 1, 0], [0, 1, 0, 0, 1, 1, 0, 0, 1, 0], [0, 1, 0, 0, 1, 1, 0, 0, 1, 0], [0, 0, 1, 1, 1, 1, 0, 0, 1, 0], [0, 0, 0, 0, 0, 1, 1, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], dtype=uint8) >>> labels_small = labels[::2, ::3] >>> labels_small array([[0, 0, 0, 0], [0, 0, 5, 0], [0, 1, 5, 0], [0, 0, 5, 0], [0, 0, 0, 0]], dtype=uint8) >>> find_boundaries(labels_small, mode='subpixel').astype(cp.uint8) array([[0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 1, 1, 0], [0, 0, 0, 1, 0, 1, 0], [0, 1, 1, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0], [0, 1, 1, 1, 0, 1, 0], [0, 0, 0, 1, 0, 1, 0], [0, 0, 0, 1, 1, 1, 0], [0, 0, 0, 0, 0, 0, 0]], dtype=uint8) >>> bool_image = cp.array([[False, False, False, False, False], ... [False, False, False, False, False], ... [False, False, True, True, True], ... [False, False, True, True, True], ... [False, False, True, True, True]], ... dtype=bool) >>> find_boundaries(bool_image) array([[False, False, False, False, False], [False, False, True, True, True], [False, True, True, True, True], [False, True, True, False, False], [False, True, True, False, False]])
 cucim.skimage.segmentation.inverse_gaussian_gradient(image, alpha=100.0, sigma=5.0)#
Inverse of gradient magnitude.
Compute the magnitude of the gradients in the image and then inverts the result in the range [0, 1]. Flat areas are assigned values close to 1, while areas close to borders are assigned values close to 0.
This function or a similar one defined by the user should be applied over the image as a preprocessing step before calling morphological_geodesic_active_contour.
 Parameters
 image(M, N) or (L, M, N) array
Grayscale image or volume.
 alphafloat, optional
Controls the steepness of the inversion. A larger value will make the transition between the flat areas and border areas steeper in the resulting array.
 sigmafloat, optional
Standard deviation of the Gaussian filter applied over the image.
 Returns
 gimage(M, N) or (L, M, N) array
Preprocessed image (or volume) suitable for morphological_geodesic_active_contour.
 cucim.skimage.segmentation.join_segmentations(s1, s2)#
Return the join of the two input segmentations.
The join J of S1 and S2 is defined as the segmentation in which two voxels are in the same segment if and only if they are in the same segment in both S1 and S2.
 Parameters
 s1, s2numpy arrays
s1 and s2 are label fields of the same shape.
 Returns
 jnumpy array
The join segmentation of s1 and s2.
Examples
>>> import cupy as cp >>> from cucim.skimage.segmentation import join_segmentations >>> s1 = cp.array([[0, 0, 1, 1], ... [0, 2, 1, 1], ... [2, 2, 2, 1]]) >>> s2 = cp.array([[0, 1, 1, 0], ... [0, 1, 1, 0], ... [0, 1, 1, 1]]) >>> join_segmentations(s1, s2) array([[0, 1, 3, 2], [0, 5, 3, 2], [4, 5, 5, 3]])
 cucim.skimage.segmentation.mark_boundaries(image, label_img, color=(1, 1, 0), outline_color=None, mode='outer', background_label=0, *, order=3)#
Return image with boundaries between labeled regions highlighted.
 Parameters
 image(M, N[, 3]) array
Grayscale or RGB image.
 label_img(M, N) array of int
Label array where regions are marked by different integer values.
 colorlength3 sequence, optional
RGB color of boundaries in the output image.
 outline_colorlength3 sequence, optional
RGB color surrounding boundaries in the output image. If None, no outline is drawn.
 modestring in {‘thick’, ‘inner’, ‘outer’, ‘subpixel’}, optional
The mode for finding boundaries.
 background_labelint, optional
Which label to consider background (this is only useful for modes
inner
andouter
).
 Returns
 marked(M, N, 3) array of float
An image in which the boundaries between labels are superimposed on the original image.
See also
 cucim.skimage.segmentation.morphological_chan_vese(image, num_iter, init_level_set='checkerboard', smoothing=1, lambda1=1, lambda2=1, iter_callback=<function <lambda>>)#
Morphological Active Contours without Edges (MorphACWE)
Active contours without edges implemented with morphological operators. It can be used to segment objects in images and volumes without well defined borders. It is required that the inside of the object looks different on average than the outside (i.e., the inner area of the object should be darker or lighter than the outer area on average).
 Parameters
 image(M, N) or (L, M, N) array
Grayscale image or volume to be segmented.
 num_iteruint
Number of num_iter to run
 init_level_setstr, (M, N) array, or (L, M, N) array
Initial level set. If an array is given, it will be binarized and used as the initial level set. If a string is given, it defines the method to generate a reasonable initial level set with the shape of the image. Accepted values are ‘checkerboard’ and ‘disk’. See the documentation of checkerboard_level_set and disk_level_set respectively for details about how these level sets are created.
 smoothinguint, optional
Number of times the smoothing operator is applied per iteration. Reasonable values are around 14. Larger values lead to smoother segmentations.
 lambda1float, optional
Weight parameter for the outer region. If lambda1 is larger than lambda2, the outer region will contain a larger range of values than the inner region.
 lambda2float, optional
Weight parameter for the inner region. If lambda2 is larger than lambda1, the inner region will contain a larger range of values than the outer region.
 iter_callbackfunction, optional
If given, this function is called once per iteration with the current level set as the only argument. This is useful for debugging or for plotting intermediate results during the evolution.
 Returns
 out(M, N) or (L, M, N) array
Final segmentation (i.e., the final level set)
 Other Parameters
 iterationsDEPRECATED
Deprecated in favor of num_iter.
Deprecated since version 0.19.
See also
Notes
This is a version of the ChanVese algorithm that uses morphological operators instead of solving a partial differential equation (PDE) for the evolution of the contour. The set of morphological operators used in this algorithm are proved to be infinitesimally equivalent to the ChanVese PDE (see [1]). However, morphological operators are do not suffer from the numerical stability issues typically found in PDEs (it is not necessary to find the right time step for the evolution), and are computationally faster.
The algorithm and its theoretical derivation are described in [1].
References
 1(1,2)
A Morphological Approach to Curvaturebased Evolution of Curves and Surfaces, Pablo MárquezNeila, Luis Baumela, Luis Álvarez. In IEEE Transactions on Pattern Analysis and Machine Intelligence (PAMI), 2014, DOI:10.1109/TPAMI.2013.106
 cucim.skimage.segmentation.morphological_geodesic_active_contour(gimage, num_iter, init_level_set='disk', smoothing=1, threshold='auto', balloon=0, iter_callback=<function <lambda>>)#
Morphological Geodesic Active Contours (MorphGAC).
Geodesic active contours implemented with morphological operators. It can be used to segment objects with visible but noisy, cluttered, broken borders.
 Parameters
 gimage(M, N) or (L, M, N) array
Preprocessed image or volume to be segmented. This is very rarely the original image. Instead, this is usually a preprocessed version of the original image that enhances and highlights the borders (or other structures) of the object to segment. morphological_geodesic_active_contour will try to stop the contour evolution in areas where gimage is small. See morphsnakes.inverse_gaussian_gradient as an example function to perform this preprocessing. Note that the quality of morphological_geodesic_active_contour might greatly depend on this preprocessing.
 num_iteruint
Number of num_iter to run.
 init_level_setstr, (M, N) array, or (L, M, N) array
Initial level set. If an array is given, it will be binarized and used as the initial level set. If a string is given, it defines the method to generate a reasonable initial level set with the shape of the image. Accepted values are ‘checkerboard’ and ‘disk’. See the documentation of checkerboard_level_set and disk_level_set respectively for details about how these level sets are created.
 smoothinguint, optional
Number of times the smoothing operator is applied per iteration. Reasonable values are around 14. Larger values lead to smoother segmentations.
 thresholdfloat, optional
Areas of the image with a value smaller than this threshold will be considered borders. The evolution of the contour will stop in this areas.
 balloonfloat, optional
Balloon force to guide the contour in noninformative areas of the image, i.e., areas where the gradient of the image is too small to push the contour towards a border. A negative value will shrink the contour, while a positive value will expand the contour in these areas. Setting this to zero will disable the balloon force.
 iter_callbackfunction, optional
If given, this function is called once per iteration with the current level set as the only argument. This is useful for debugging or for plotting intermediate results during the evolution.
 Returns
 out(M, N) or (L, M, N) array
Final segmentation (i.e., the final level set)
 Other Parameters
 iterationsDEPRECATED
Deprecated in favor of num_iter.
Deprecated since version 0.19.
Notes
This is a version of the Geodesic Active Contours (GAC) algorithm that uses morphological operators instead of solving partial differential equations (PDEs) for the evolution of the contour. The set of morphological operators used in this algorithm are proved to be infinitesimally equivalent to the GAC PDEs (see [1]). However, morphological operators are do not suffer from the numerical stability issues typically found in PDEs (e.g., it is not necessary to find the right time step for the evolution), and are computationally faster.
The algorithm and its theoretical derivation are described in [1].
References
 1(1,2)
A Morphological Approach to Curvaturebased Evolution of Curves and Surfaces, Pablo MárquezNeila, Luis Baumela, Luis Álvarez. In IEEE Transactions on Pattern Analysis and Machine Intelligence (PAMI), 2014, DOI:10.1109/TPAMI.2013.106
 cucim.skimage.segmentation.random_walker(data, labels, beta=130, mode='cg_j', tol=0.001, copy=True, multichannel=False, return_full_prob=False, spacing=None, *, prob_tol=0.001, channel_axis=None)#
Random walker algorithm for segmentation from markers.
Random walker algorithm is implemented for graylevel or multichannel images.
 Parameters
 dataarray_like
Image to be segmented in phases. Graylevel data can be two or threedimensional; multichannel data can be three or four dimensional with channel_axis specifying the dimension containing channels. Data spacing is assumed isotropic unless the spacing keyword argument is used.
 labelsarray of ints, of same shape as data without channels dimension
Array of seed markers labeled with different positive integers for different phases. Zerolabeled pixels are unlabeled pixels. Negative labels correspond to inactive pixels that are not taken into account (they are removed from the graph). If labels are not consecutive integers, the labels array will be transformed so that labels are consecutive. In the multichannel case, labels should have the same shape as a single channel of data, i.e. without the final dimension denoting channels.
 betafloat, optional
Penalization coefficient for the random walker motion (the greater beta, the more difficult the diffusion).
 modestring, available options {‘cg’, ‘cg_j’, ‘cg_mg’, ‘bf’}
Mode for solving the linear system in the random walker algorithm.
‘bf’ (brute force): an LU factorization of the Laplacian is computed. This is fast for small images (<1024x1024), but very slow and memoryintensive for large images (e.g., 3D volumes).
‘cg’ (conjugate gradient): the linear system is solved iteratively using the Conjugate Gradient method from scipy.sparse.linalg. This is less memoryconsuming than the brute force method for large images, but it is quite slow.
‘cg_j’ (conjugate gradient with Jacobi preconditionner): the Jacobi preconditionner is applyed during the Conjugate gradient method iterations. This may accelerate the convergence of the ‘cg’ method.
‘cg_mg’ (conjugate gradient with multigrid preconditioner): a preconditioner is computed using a multigrid solver, then the solution is computed with the Conjugate Gradient method. This mode requires that the pyamg module is installed.
 tolfloat, optional
Tolerance to achieve when solving the linear system using the conjugate gradient based modes (‘cg’, ‘cg_j’ and ‘cg_mg’).
 copybool, optional
If copy is False, the labels array will be overwritten with the result of the segmentation. Use copy=False if you want to save on memory.
 multichannelbool, optional
If True, input data is parsed as multichannel data (see ‘data’ above for proper input format in this case). This argument is deprecated: specify channel_axis instead.
 return_full_probbool, optional
If True, the probability that a pixel belongs to each of the labels will be returned, instead of only the most likely label.
 spacingiterable of floats, optional
Spacing between voxels in each spatial dimension. If None, then the spacing between pixels/voxels in each dimension is assumed 1.
 prob_tolfloat, optional
Tolerance on the resulting probability to be in the interval [0, 1]. If the tolerance is not satisfied, a warning is displayed.
 channel_axisint or None, optional
If None, the image is assumed to be a grayscale (single channel) image. Otherwise, this parameter indicates which axis of the array corresponds to channels.
 Returns
 outputndarray
If return_full_prob is False, array of ints of same shape and data type as labels, in which each pixel has been labeled according to the marker that reached the pixel first by anisotropic diffusion.
If return_full_prob is True, array of floats of shape (nlabels, labels.shape). output[label_nb, i, j] is the probability that label label_nb reaches the pixel (i, j) first.
 Other Parameters
 multichannelDEPRECATED
Deprecated in favor of channel_axis.
Deprecated since version 0.19.
See also
skimage.morphology.watershed()
watershed segmentation A segmentation algorithm based on mathematical morphology and “flooding” of regions from markers.
Notes
Multichannel inputs are scaled with all channel data combined. Ensure all channels are separately normalized prior to running this algorithm.
The spacing argument is specifically for anisotropic datasets, where data points are spaced differently in one or more spatial dimensions. Anisotropic data is commonly encountered in medical imaging.
The algorithm was first proposed in [1].
The algorithm solves the diffusion equation at infinite times for sources placed on markers of each phase in turn. A pixel is labeled with the phase that has the greatest probability to diffuse first to the pixel.
The diffusion equation is solved by minimizing x.T L x for each phase, where L is the Laplacian of the weighted graph of the image, and x is the probability that a marker of the given phase arrives first at a pixel by diffusion (x=1 on markers of the phase, x=0 on the other markers, and the other coefficients are looked for). Each pixel is attributed the label for which it has a maximal value of x. The Laplacian L of the image is defined as:
L_ii = d_i, the number of neighbors of pixel i (the degree of i)
L_ij = w_ij if i and j are adjacent pixels
The weight w_ij is a decreasing function of the norm of the local gradient. This ensures that diffusion is easier between pixels of similar values.
When the Laplacian is decomposed into blocks of marked and unmarked pixels:
L = M B.T B A
with first indices corresponding to marked pixels, and then to unmarked pixels, minimizing x.T L x for one phase amount to solving:
A x =  B x_m
where x_m = 1 on markers of the given phase, and 0 on other markers. This linear system is solved in the algorithm using a direct method for small images, and an iterative method for larger images.
References
 1
Leo Grady, Random walks for image segmentation, IEEE Trans Pattern Anal Mach Intell. 2006 Nov;28(11):176883. DOI:10.1109/TPAMI.2006.233.
Examples
>>> import cupy as cp >>> cp.random.seed(0) >>> a = cp.zeros((10, 10)) + 0.2 * cp.random.rand(10, 10) >>> a[5:8, 5:8] += 1 >>> b = cp.zeros_like(a, dtype=cp.int32) >>> b[3, 3] = 1 # Marker for first phase >>> b[6, 6] = 2 # Marker for second phase >>> random_walker(a, b) array([[1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 2, 2, 2, 1, 1], [1, 1, 1, 1, 1, 2, 2, 2, 1, 1], [1, 1, 1, 1, 1, 2, 2, 2, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]], dtype=int32)
 cucim.skimage.segmentation.relabel_sequential(label_field, offset=1)#
Relabel arbitrary labels to {offset, … offset + number_of_labels}.
This function also returns the forward map (mapping the original labels to the reduced labels) and the inverse map (mapping the reduced labels back to the original ones).
 Parameters
 label_fieldnumpy array of int, arbitrary shape
An array of labels, which must be nonnegative integers.
 offsetint, optional
The return labels will start at offset, which should be strictly positive.
 Returns
 relabeled</