3.1.3. Module tensor

3.1.3.1. Description

Data processing module in informatics. Utilities for data processing. Data can be vector, series (1-dimensional tensor), matrix (2-dimensional tensor), conventional medical image (3-dimensional tensor), or tensors in higher dimensions. Dependent on the type of data being processed, tensors are categorized into two distinct classes: Boolean and numerical.

Namespace of this module is originally info.toolbox.libs.tensor. For convenience, import from main entry via from info.me import tensorn for processing numeric tensor, or from info.me import tensorb for dealing with the boolean one, is also available.

Computing in this module support GPU accelerating. If cupy is installed in the environment, reset the configuration to activate it:

Code 3.32 activate gpu accelerating for computing
from info.me import tensorn as tsn
tsn.config.reset(device='gpu')

Numerical tensor is generally used as container for raw data. For dealing with numeric tensor:

standardization

standard scaler function or Unit to shrink data with values distributed as \(\mathcal{N}(1, 0)\).

normalization

normal scalar function or Unit to shrink values of data confined from 0 to 1.

clipper

clipper scalar function or Unit to clip values of data with lower and upper bound.

cropper

function or Unit to crop data via start and end assignments.

resize

resizing data into specific shape.

averaging_filter

averaging filter for tensor.

rank_filter

rank filter for tensor.

minimum_filter

local minimum filter for tensor.

maximum_filter

local maximum filter for tensor.

mean_filter

local mean filter for tensor.

median_filter

local median filter for tensor.

gaussian_filter

gaussian filter for tensor.

gabor_filter

gabor filter for tensor.

bilateral_filter

bilateral filter for tensor.

prewitt_filter

prewitt filter to highlight edge of tensor.

prewitt_detector

prewitt detector to determine edge of tensor.

prewitt_sharpen

prewitt sharpen to get higher-contrast-edge tensor.

sobel_filter

sobel filter to highlight edge of tensor.

sobel_detector

sobel detector to determine edge of tensor.

sobel_sharpen

sobel sharpen to get higher-contrast-edge tensor.

canny_filter

canny filter to highlight edge of tensor.

canny_detector

canny detector to determine edge of tensor.

canny_sharpen

canny sharpen to get higher-contrast-edge tensor.

laplacian_of_gaussian_filter

laplacian of gaussian filter to highlight edge of tensor.

laplacian_of_gaussian_detector

laplacian of gaussian detector to determine edge of tensor.

laplacian_of_gaussian_sharpen

laplacian of gaussian sharpen to get higher-contrast-edge tensor.

difference_of_gaussian_filter

difference of gaussian filter to highlight edge of tensor.

difference_of_gaussian_detector

difference of gaussian detector to determine edge of tensor.

difference_of_gaussian_sharpen

difference of gaussian sharpen to get higher-contrast-edge tensor.

hessian_determinant_response

hessian determinant to highlight corner of tensor.

hessian_curvature_response

hessian curvature to highlight corner of tensor.

hessian_curvature_detector

hessian detector to determine corners of tensor.

moravec_response

moravec response for tensor.

harris_response

harris curvature response for tensor.

usan_response

usan response for tensor.

segment_response

segment test response for tensor.

fast_response

fast response for tensor.

And boolean tensor is generally used for segmentation, assisted for some specific tasks such as emphasizing some certain area of raw data. For dealing with boolean tensor:

prober

sub segmentation generator from a bool ndarray.

connected_domain

connected domain generator from a bool or an integer ndarray.

seg_resize

resizing data into specific shape.

erosion

morphological erosion operation for boolean tensor.

dilation

morphological dilation operation for boolean tensor.

intersection

intersection operation for boolean tensor.

union

union operation for boolean tensor.

difference

difference operation for boolean tensor.

watershed

watershed algorithm for labeling segmentation.

3.1.3.2. Docstrings

3.1.3.2.1. Numeric tensor

standardization

standard scaler function or Unit to shrink data with values distributed as \(\mathcal{N}(1, 0)\). available for numpy and cupy ndarray.

Arguments:
Parameters:

data (Union[numpy.ndarray, cupy.ndarray]) – data to be standardized

Returns:

data after standardization

Return type:

Union[numpy.ndarray, cupy.ndarray]

Raises:

TypeError – if data was not assigned properly

Examples:
Code 3.33 standardize a series
from info.me import tensorn as tsn
import numpy as np

tsn.standardization(data=np.random.random(100)*100+50)
Logs:

Added in version 0.0.2.

– Created by Chen Zhang; Last updated on 01:34, 2025-09-06

normalization

normal scalar function or Unit to shrink values of data confined from 0 to 1. available for numpy and cupy ndarray.

Arguments:
Parameters:

data (Union[numpy.ndarray, cupy.ndarray]) – data to be normalized

Returns:

data after normalization

Return type:

Union[numpy.ndarray, cupy.ndarray]

Raises:

TypeError – if data was not assigned properly

Examples:
Code 3.34 normalize a series
from info.me import tensorn as tsn
import numpy as np

tsn.normalization(data=np.random.random(100)*100+50)
Logs:

Added in version 0.0.2.

– Created by Chen Zhang; Last updated on 01:34, 2025-09-06

clipper

clipper scalar function or Unit to clip values of data with lower and upper bound. available for numpy and cupy ndarray.

Arguments:
Parameters:
  • data (Union[numpy.ndarray, cupy.ndarray]) – data to be clipped

  • clip (tuple[Numeric, Numeric]) – 2-length list, composed of lower and upper bound

Returns:

data with values after clipping

Return type:

Union[numpy.ndarray, cupy.ndarray]

Raises:

TypeError – if data or clip was not assigned properly

Examples:
Code 3.35 clip a series
from info.me import tensorn as tsn
import numpy as np

tsn.clipper(data=np.random.random(100)*100+50, clip=[60, 120])
Logs:

Added in version 0.0.2.

– Created by Chen Zhang; Last updated on 01:34, 2025-09-06

cropper

function or Unit to crop data via start and end assignments. available for numpy and cupy ndarray.

Arguments:
Parameters:
  • data (Union[numpy.ndarray, cupy.ndarray]) – data to be cropped

  • crop_range (list[tuple[Numeric]]) – list composed of start & end points or ratios, values in end points or ratios must strictly greater than starts ones in each dimension

Returns:

cropped ndarray

Return type:

Union[numpy.ndarray, cupy.ndarray]

Raises:

TypeError – if data or crop_range was not assigned as available type

Examples:
Code 3.36 crop an image
from info.ins import datasets
from info.me import tensorn as tsn
img = datasets.blackcurrant()

# absolute cropping via start & end indices
tsn.cropper(data=img, crop_range=[(40, 0), (512, 370)])

# relative cropping via start & end ratios
tsn.cropper(data=img, crop_range=[(.07, 0.), (1., .72)])
Logs:

Added in version 0.0.2.

– Created by Chen Zhang; Last updated on 01:34, 2025-09-06

resize

resizing data into specific shape. spline interpolation supported. algorithm is implemented through canonical decomposition [Battaglino2018], or Tucker decomposition for tensor [Kolda2009]. available for numpy and cupy ndarray.

Arguments:
Parameters:
  • data (Union[numpy.ndarray, cupy.ndarray]) – data to be resized

  • new_size (tuple[int]) – tuple to determine new size for input data

  • decomp_method (Literal['cp', 'tucker', 'tt', 'tr']) – decomposition method for data; 'cp' for canonical decomposition into parallel factors, 'tucker' for Tucker decomposition; 'tt' for tensor train decomposition; 'tr' for tensor ring decomposition;``’cp’`` as default

  • decomp_rank (Union[int, tuple[int, ...]]) – decomposition rank; integer for all ranks, or tuple of integers for each rank; None as default to calculate automatically

  • interp_method (Literal[...]) – interpolation method links to kind argument of interp1d; options are 'linear', 'nearest', 'nearest-up', 'zero', 'slinear', 'quadratic', 'cubic', 'previous', and 'next'; 'linear' as default

Returns:

re-sized data

Return type:

Union[numpy.ndarray, cupy.ndarray]

Raises:

TypeError – if data or new_size was not assigned properly

Examples:
Code 3.37 resize an image through interpolation
from info.ins import datasets
from info.me import tensorn as tsn
img = datasets.blackcurrant()

dt_1 = tsn.resize(data=img, new_size=(200, 200))

# or use 2nd order spline
dt_2 = tsn.resize(data=img, new_size=(200, 200), interp_method='quadratic')
See also:
Logs:

Added in version 0.0.2.

– Created by Chen Zhang; Last updated on 01:34, 2025-09-06

averaging_filter

averaging filter for tensor. available for numpy and cupy ndarray.

Arguments:
Parameters:
  • data (Union[numpy.ndarray, cupy.ndarray]) – the input tensor

  • k_shape (tuple[int, ...]) – the shape of averaging kernel

  • k_mode (Literal) – method of edge filling; valid options are 'reflect', 'constant', 'nearest', 'mirror', and 'wrap'; 'reflect' as default

  • k_cval (Numeric) – filling number when k_mode is 'constant'; 0.0 as default

  • k_origin (Union[int, Iterable[int]]) – origin of anchor pixel in kernel; 0 as default

Returns:

a filtered tensor

Return type:

Union[numpy.ndarray, cupy.ndarray]

Raises:

TypeErrordata or k_shape are not assigned properly

Examples:
Code 3.38 averaging filter for image
from info.me import tensorn as tsn
from info.ins import datasets

tsn.averaging_filter(data=datasets.blackcurrant(), k_shape=(4, 5))
See also:
Logs:

Added in version 0.0.2.

– Created by Chen Zhang; Last updated on 01:34, 2025-09-06

rank_filter

rank filter for tensor. available for numpy and cupy ndarray.

Arguments:
Parameters:
  • data (Union[numpy.ndarray, cupy.ndarray]) – the input tensor

  • k_shape (tuple[int, ...]) – the shape of averaging kernel

  • k_rank (Numeric) – rank for filter, int as indexing or float from 0. to 1. as quantile; for examples, 0 for minimum, -1 for maximum using int assignment, 0.5 for median using float assignment

  • k_mode (Literal) – method of edge filling; valid options are 'reflect', 'constant', 'nearest', 'mirror', and 'wrap'; 'reflect' as default

  • k_cval (Numeric) – filling number when k_mode is 'constant'; 0.0 as default

  • k_origin (Union[int, Iterable[int]]) – origin of anchor pixel in kernel; 0 as default

Returns:

a filtered tensor

Return type:

Union[numpy.ndarray, cupy.ndarray]

Raises:

TypeErrordata, k_shape or k_rank are not assigned properly

Examples:
Code 3.39 rank filter for image
from info.me import tensorn as tsn
from info.ins import datasets

tsn.rank_filter(data=datasets.blackcurrant(), k_shape=(4, 5), k_rank=0.75)
tsn.rank_filter(data=datasets.blackcurrant(), k_shape=(4, 5), k_rank=-1)
Logs:

Added in version 0.0.2.

– Created by Chen Zhang; Last updated on 01:34, 2025-09-06

minimum_filter

local minimum filter for tensor. an aggregation function is type of data transfer method to map a multi-element data into a scalar. available for numpy and cupy ndarray.

Arguments:
Parameters:
  • data (Union[numpy.ndarray, cupy.ndarray]) – the input tensor

  • k_shape (tuple[int, ...]) – the shape of averaging kernel

  • k_mode (Literal) – method of edge filling; valid options are 'reflect', 'constant', 'nearest', 'mirror', and 'wrap'; 'reflect' as default

  • k_cval (Numeric) – filling number when k_mode is 'constant'; 0.0 as default

  • k_origin (Union[int, Iterable[int]]) – origin of anchor pixel in kernel; 0 as default

Returns:

a filtered tensor

Return type:

Union[numpy.ndarray, cupy.ndarray]

Raises:

TypeErrordata or k_shape are not assigned properly

Examples:
Code 3.40 aggregation functional filters for image
from info.me import tensorn as tsn
from info.ins import datasets
img, shape = datasets.blackcurrant(), (4, 5)

tsn.minimum_filter(data=img, k_shape=shape)
tsn.maximum_filter(data=img, k_shape=shape)
tsn.mean_filter(data=img, k_shape=shape)
tsn.median_filter(data=img, k_shape=shape)
Notes:

Some aggregation functions are specific forms of rank_filter:

Code 3.41 homogeneity of mappings for some aggregation functional filters and rank filter
from info.me import tensorn as tsn
from info.ins import datasets
img, shape, rf = datasets.blackcurrant(), (4, 5), tsn.rank_filter

assert (tsn.minimum_filter(data=img, k_shape=shape) - rf(data=img, k_shape=shape, k_rank=0)).any() == False
assert (tsn.maximum_filter(data=img, k_shape=shape) - rf(data=img, k_shape=shape, k_rank=-1)).any() == False
assert (tsn.median_filter(data=img, k_shape=shape) - rf(data=img, k_shape=shape, k_rank=0.5)).any() == False
See also:
Logs:

Added in version 0.0.2.

– Created by Chen Zhang; Last updated on 01:34, 2025-09-06

maximum_filter

local maximum filter for tensor. an aggregation function is type of data transfer method to map a multi-element data into a scalar. available for numpy and cupy ndarray.

Arguments:
Parameters:
  • data (Union[numpy.ndarray, cupy.ndarray]) – the input tensor

  • k_shape (tuple[int, ...]) – the shape of averaging kernel

  • k_mode (Literal) – method of edge filling; valid options are 'reflect', 'constant', 'nearest', 'mirror', and 'wrap'; 'reflect' as default

  • k_cval (Numeric) – filling number when k_mode is 'constant'; 0.0 as default

  • k_origin (Union[int, Iterable[int]]) – origin of anchor pixel in kernel; 0 as default

Returns:

a filtered tensor

Return type:

Union[numpy.ndarray, cupy.ndarray]

Raises:

TypeErrordata or k_shape are not assigned properly

Examples:
Code 3.42 aggregation functional filters for image
from info.me import tensorn as tsn
from info.ins import datasets
img, shape = datasets.blackcurrant(), (4, 5)

tsn.minimum_filter(data=img, k_shape=shape)
tsn.maximum_filter(data=img, k_shape=shape)
tsn.mean_filter(data=img, k_shape=shape)
tsn.median_filter(data=img, k_shape=shape)
Notes:

Some aggregation functions are specific forms of rank_filter:

Code 3.43 homogeneity of mappings for some aggregation functional filters and rank filter
from info.me import tensorn as tsn
from info.ins import datasets
img, shape, rf = datasets.blackcurrant(), (4, 5), tsn.rank_filter

assert (tsn.minimum_filter(data=img, k_shape=shape) - rf(data=img, k_shape=shape, k_rank=0)).any() == False
assert (tsn.maximum_filter(data=img, k_shape=shape) - rf(data=img, k_shape=shape, k_rank=-1)).any() == False
assert (tsn.median_filter(data=img, k_shape=shape) - rf(data=img, k_shape=shape, k_rank=0.5)).any() == False
See also:
Logs:

Added in version 0.0.2.

– Created by Chen Zhang; Last updated on 01:34, 2025-09-06

mean_filter

local mean filter for tensor. an aggregation function is type of data transfer method to map a multi-element data into a scalar. available for numpy and cupy ndarray.

Arguments:
Parameters:
  • data (Union[numpy.ndarray, cupy.ndarray]) – the input tensor

  • k_shape (tuple[int, ...]) – the shape of averaging kernel

  • k_mode (Literal) – method of edge filling; valid options are 'reflect', 'constant', 'nearest', 'mirror', and 'wrap'; 'reflect' as default

  • k_cval (Numeric) – filling number when k_mode is 'constant'; 0.0 as default

  • k_origin (Union[int, Iterable[int]]) – origin of anchor pixel in kernel; 0 as default

Returns:

a filtered tensor

Return type:

Union[numpy.ndarray, cupy.ndarray]

Raises:

TypeErrordata or k_shape are not assigned properly

Examples:
Code 3.44 aggregation functional filters for image
from info.me import tensorn as tsn
from info.ins import datasets
img, shape = datasets.blackcurrant(), (4, 5)

tsn.minimum_filter(data=img, k_shape=shape)
tsn.maximum_filter(data=img, k_shape=shape)
tsn.mean_filter(data=img, k_shape=shape)
tsn.median_filter(data=img, k_shape=shape)
Notes:

Some aggregation functions are specific forms of rank_filter:

Code 3.45 homogeneity of mappings for some aggregation functional filters and rank filter
from info.me import tensorn as tsn
from info.ins import datasets
img, shape, rf = datasets.blackcurrant(), (4, 5), tsn.rank_filter

assert (tsn.minimum_filter(data=img, k_shape=shape) - rf(data=img, k_shape=shape, k_rank=0)).any() == False
assert (tsn.maximum_filter(data=img, k_shape=shape) - rf(data=img, k_shape=shape, k_rank=-1)).any() == False
assert (tsn.median_filter(data=img, k_shape=shape) - rf(data=img, k_shape=shape, k_rank=0.5)).any() == False
See also:
Logs:

Added in version 0.0.2.

– Created by Chen Zhang; Last updated on 01:34, 2025-09-06

median_filter

local median filter for tensor. an aggregation function is type of data transfer method to map a multi-element data into a scalar. available for numpy and cupy ndarray.

Arguments:
Parameters:
  • data (Union[numpy.ndarray, cupy.ndarray]) – the input tensor

  • k_shape (tuple[int, ...]) – the shape of averaging kernel

  • k_mode (Literal) – method of edge filling; valid options are 'reflect', 'constant', 'nearest', 'mirror', and 'wrap'; 'reflect' as default

  • k_cval (Numeric) – filling number when k_mode is 'constant'; 0.0 as default

  • k_origin (Union[int, Iterable[int]]) – origin of anchor pixel in kernel; 0 as default

Returns:

a filtered tensor

Return type:

Union[numpy.ndarray, cupy.ndarray]

Raises:

TypeErrordata or k_shape are not assigned properly

Examples:
Code 3.46 aggregation functional filters for image
from info.me import tensorn as tsn
from info.ins import datasets
img, shape = datasets.blackcurrant(), (4, 5)

tsn.minimum_filter(data=img, k_shape=shape)
tsn.maximum_filter(data=img, k_shape=shape)
tsn.mean_filter(data=img, k_shape=shape)
tsn.median_filter(data=img, k_shape=shape)
Notes:

Some aggregation functions are specific forms of rank_filter:

Code 3.47 homogeneity of mappings for some aggregation functional filters and rank filter
from info.me import tensorn as tsn
from info.ins import datasets
img, shape, rf = datasets.blackcurrant(), (4, 5), tsn.rank_filter

assert (tsn.minimum_filter(data=img, k_shape=shape) - rf(data=img, k_shape=shape, k_rank=0)).any() == False
assert (tsn.maximum_filter(data=img, k_shape=shape) - rf(data=img, k_shape=shape, k_rank=-1)).any() == False
assert (tsn.median_filter(data=img, k_shape=shape) - rf(data=img, k_shape=shape, k_rank=0.5)).any() == False
See also:
Logs:

Added in version 0.0.2.

– Created by Chen Zhang; Last updated on 01:34, 2025-09-06

gaussian_filter

gaussian filter for tensor. gaussian kernel is generated using gaussian_kernel based on Equation 3.18. available for numpy and cupy ndarray.

Arguments:
Parameters:
  • data (Union[numpy.ndarray, cupy.ndarray]) – the input tensor

  • k_shape (tuple[int, ...]) – the shape of averaging kernel

  • k_mu (Union[numpy.ndarray, cupy.ndarray]) – mean of Gaussian; \(\boldsymbol{0}\) vector as default

  • k_sigma (Union[numpy.ndarray, cupy.ndarray]) – covariance matrix of Gaussian; diagonal matrix of k_shape as default

  • k_mode (Literal) – method of edge filling; valid options are 'reflect', 'constant', 'nearest', 'mirror', and 'wrap'; 'reflect' as default

  • k_cval (Numeric) – filling number when k_mode is 'constant'; 0.0 as default

  • k_origin (Union[int, Iterable[int]]) – origin of anchor pixel in kernel; 0 as default

Returns:

a filtered tensor

Return type:

Union[numpy.ndarray, cupy.ndarray]

Raises:

TypeErrordata or k_shape are not assigned properly

Examples:
Code 3.48 gaussian filter for image
from info.me import tensorn as tsn
from info.ins import datasets

tsn.gaussian_filter(data=datasets.blackcurrant(), k_shape=(4, 5))
See also:
Logs:

Added in version 0.0.2.

– Created by Chen Zhang; Last updated on 01:34, 2025-09-06

gabor_filter

gabor filter for tensor. gabor kernel is generated using gabor_kernel based on Equation 3.18. available for numpy and cupy ndarray.

Arguments:
Parameters:
  • data (Union[numpy.ndarray, cupy.ndarray]) – the input tensor

  • k_shape (tuple[int, ...]) – tuple for kernel shape

  • k_rescale (Numeric) – rescale coefficient to determine the size of gaussian envelope; 1 as default

  • k_orientation (list[Numeric]) – spatial orientation where the harmonic sine function periodically repeats; None as default to automatically generate 1 for each dimension (e.g. [1, 1, 1] for 3D data)

  • k_wavelength (Numeric) – wavelength of harmonic sine function; \(2\pi\) as default

  • k_phase (Numeric) – phase position of harmonic sine function; 0 as default

  • k_mode (Literal) – method of edge filling; valid options are 'reflect', 'constant', 'nearest', 'mirror', and 'wrap'; 'reflect' as default

  • k_cval (Numeric) – filling number when k_mode is 'constant'; 0.0 as default

  • k_origin (Union[int, Iterable[int]]) – origin of anchor pixel in kernel; 0 as default

Returns:

a filtered tensor

Return type:

Union[numpy.ndarray, cupy.ndarray]

Raises:

TypeErrordata, k_shape or k_orientation are not assigned properly

Examples:
Code 3.49 gabor filter for image
from info.me import tensorn as tsn
from info.ins import datasets

tsn.gabor_filter(data=datasets.blackcurrant(), k_shape=(15, 15), k_orientation=[1, 1])
See also:
Logs:

Added in version 0.0.4.

– Created by Chen Zhang; Last updated on 01:34, 2025-09-06

bilateral_filter

bilateral filter for tensor. available for numpy and cupy ndarray.

Arguments:
Parameters:
  • data (Union[numpy.ndarray, cupy.ndarray]) – the input tensor

  • k_shape (tuple[int, ...]) – the shape of averaging kernel

  • sigma_d (Union[numpy.ndarray, cupy.ndarray]) – covariance matrix of Gaussian; diagonal matrix of k_shape as default

  • sigma_r (Union[numpy.ndarray, cupy.ndarray]) – variance of ranged space; None for local adaptive variance as default

  • k_mode (Literal) – method of edge filling; valid options are 'reflect', 'constant', 'nearest', 'mirror', and 'wrap'; 'reflect' as default

  • k_cval (Numeric) – filling number when k_mode is 'constant'; 0.0 as default

  • k_origin (Union[int, Iterable[int]]) – origin of anchor pixel in kernel; 0 as default

Returns:

a filtered tensor

Return type:

Union[numpy.ndarray, cupy.ndarray]

Raises:

TypeErrordata or k_shape are not assigned properly

Examples:
Code 3.50 bilateral filter for image
from info.me import tensorn as tsn
from info.ins import datasets
img = datasets.blackcurrant()

# using self-adaptive sigma_r
tsn.bilateral_filter(data=img, k_shape=(4, 5))

# using fixed sigma_r
tsn.bilateral_filter(data=img, k_shape=(4, 5), sigma_r=10)

# in extremely large sigma_r, bilateral_filter will degenerate into the effect of Gaussian kernel:
tsn.bilateral_filter(data=img, k_shape=(4, 5), sigma_r=1e10)
Notes:

For each element-dependent block, the general form of wight kernel follow:

(3.1)\[W(\boldsymbol{x}, \boldsymbol{s}) \propto \exp{[-\frac{(\boldsymbol{x}-\boldsymbol{s})^T \boldsymbol{\Sigma}^{-1}_{d} (\boldsymbol{x}-\boldsymbol{s})}{2} - \frac{\Vert I(\boldsymbol{x}) - I(\boldsymbol{s}) \Vert^{2}}{2 \sigma^{2}_{r}}]}\]

Where \(I(\boldsymbol{x})\) and \(I(\boldsymbol{s})\) are the values spaced in tensor and kernel respectively. In kernel space, \(\boldsymbol{x}\) is the anchor pixel with zero offset, therefore the 1st exponential item in Equation 3.1 is the Gaussian kernel (Equation 3.18) with \(\boldsymbol{\mu} = \boldsymbol{0}\). For each element, \(W(\boldsymbol{x}, \boldsymbol{s})\) is rescaled by \(W = W(\boldsymbol{x},\boldsymbol{s})/\sum_{\boldsymbol{s}}W(\boldsymbol{x}, \boldsymbol{s})\)

Bilateral filter was proposed by C. Tomasi et. al. for an edge-preserving smoothing on image processing. As a no-linear method, kernel of bilateral will be a function of both Gaussian distribution, and the local element in tensor itself. Therefore, the computing cost of bilateral is heavier, compared to other static kernels

Logs:

Added in version 0.0.2.

– Created by Chen Zhang; Last updated on 01:34, 2025-09-06

prewitt_filter

prewitt filter to highlight edge of tensor. each derivative operator is constructed with planes filled with -1 and 1 in start and end surface, respectively. for prewitt filter, gradient components of tensor were calculated for all axis then integrated through 2 norm. for prewitt detector, pixels with gray level upper more than threshold will be identified as edges. for prewitt sharpen, pixels around edge-like area will be augmented into the effect of higher contrast. available for numpy and cupy ndarray.

Arguments:
Parameters:
  • data (Union[numpy.ndarray, cupy.ndarray]) – the input tensor

  • k_shape (tuple[int, ...]) – the shape of averaging kernel; 3 for each dimension as default

  • k_mode (Literal) – method of edge filling; valid options are 'reflect', 'constant', 'nearest', 'mirror', and 'wrap'; 'reflect' as default

  • k_cval (Numeric) – filling number when k_mode is 'constant'; 0.0 as default

  • k_origin (Union[int, Iterable[int]]) – origin of anchor pixel in kernel; 0 as default

  • prewitt_limen (Numeric) – (detector only) threshold for edge identification; values ranged from 0. to 1. for relative threshold using quantiles, otherwise the absolute one; 0.9 as default

  • sharp_alpha (Numeric) – (sharpen only) intensity for increasing edge contrast; 1 as default

Returns:

a numeric (filter, sharpen) or bool (detector) tensor

Return type:

Union[numpy.ndarray, cupy.ndarray]

Raises:

TypeErrordata is not assigned properly

Examples:
Code 3.51 prewitt detector, filter and sharpen for image
from info.me import tensorn as tsn
from info.ins import datasets
img = datasets.blackcurrant()

# apply prewitt detector
tsn.prewitt_detector(data=img)

# apply prewitt filter
tsn.prewitt_filter(data=img)

# apply prewitt sharpen
tsn.prewitt_sharpen(data=img)
Logs:

Added in version 0.0.2.

– Created by Chen Zhang; Last updated on 01:34, 2025-09-06

prewitt_detector

prewitt detector to determine edge of tensor. each derivative operator is constructed with planes filled with -1 and 1 in start and end surface, respectively. for prewitt filter, gradient components of tensor were calculated for all axis then integrated through 2 norm. for prewitt detector, pixels with gray level upper more than threshold will be identified as edges. for prewitt sharpen, pixels around edge-like area will be augmented into the effect of higher contrast. available for numpy and cupy ndarray.

Arguments:
Parameters:
  • data (Union[numpy.ndarray, cupy.ndarray]) – the input tensor

  • k_shape (tuple[int, ...]) – the shape of averaging kernel; 3 for each dimension as default

  • k_mode (Literal) – method of edge filling; valid options are 'reflect', 'constant', 'nearest', 'mirror', and 'wrap'; 'reflect' as default

  • k_cval (Numeric) – filling number when k_mode is 'constant'; 0.0 as default

  • k_origin (Union[int, Iterable[int]]) – origin of anchor pixel in kernel; 0 as default

  • prewitt_limen (Numeric) – (detector only) threshold for edge identification; values ranged from 0. to 1. for relative threshold using quantiles, otherwise the absolute one; 0.9 as default

  • sharp_alpha (Numeric) – (sharpen only) intensity for increasing edge contrast; 1 as default

Returns:

a numeric (filter, sharpen) or bool (detector) tensor

Return type:

Union[numpy.ndarray, cupy.ndarray]

Raises:

TypeErrordata is not assigned properly

Examples:
Code 3.52 prewitt detector, filter and sharpen for image
from info.me import tensorn as tsn
from info.ins import datasets
img = datasets.blackcurrant()

# apply prewitt detector
tsn.prewitt_detector(data=img)

# apply prewitt filter
tsn.prewitt_filter(data=img)

# apply prewitt sharpen
tsn.prewitt_sharpen(data=img)
Logs:

Added in version 0.0.2.

– Created by Chen Zhang; Last updated on 01:34, 2025-09-06

prewitt_sharpen

prewitt sharpen to get higher-contrast-edge tensor. each derivative operator is constructed with planes filled with -1 and 1 in start and end surface, respectively. for prewitt filter, gradient components of tensor were calculated for all axis then integrated through 2 norm. for prewitt detector, pixels with gray level upper more than threshold will be identified as edges. for prewitt sharpen, pixels around edge-like area will be augmented into the effect of higher contrast. available for numpy and cupy ndarray.

Arguments:
Parameters:
  • data (Union[numpy.ndarray, cupy.ndarray]) – the input tensor

  • k_shape (tuple[int, ...]) – the shape of averaging kernel; 3 for each dimension as default

  • k_mode (Literal) – method of edge filling; valid options are 'reflect', 'constant', 'nearest', 'mirror', and 'wrap'; 'reflect' as default

  • k_cval (Numeric) – filling number when k_mode is 'constant'; 0.0 as default

  • k_origin (Union[int, Iterable[int]]) – origin of anchor pixel in kernel; 0 as default

  • prewitt_limen (Numeric) – (detector only) threshold for edge identification; values ranged from 0. to 1. for relative threshold using quantiles, otherwise the absolute one; 0.9 as default

  • sharp_alpha (Numeric) – (sharpen only) intensity for increasing edge contrast; 1 as default

Returns:

a numeric (filter, sharpen) or bool (detector) tensor

Return type:

Union[numpy.ndarray, cupy.ndarray]

Raises:

TypeErrordata is not assigned properly

Examples:
Code 3.53 prewitt detector, filter and sharpen for image
from info.me import tensorn as tsn
from info.ins import datasets
img = datasets.blackcurrant()

# apply prewitt detector
tsn.prewitt_detector(data=img)

# apply prewitt filter
tsn.prewitt_filter(data=img)

# apply prewitt sharpen
tsn.prewitt_sharpen(data=img)
Logs:

Added in version 0.0.2.

– Created by Chen Zhang; Last updated on 01:34, 2025-09-06

sobel_filter

sobel filter to highlight edge of tensor. each derivative operator is constructed with planes distributed as \(-G\) and \(G\) in start and end surface respectively, where \(G\) is 1-dimensional degenerated marginal distribution of Gaussian (see marginal probability). for sobel filter, gradient components of tensor were calculated for all axis then integrated through 2 norm. for sobel detector, pixels with gray level upper more than threshold will be identified as edges. for sobel sharpen, pixels around edge-like area will be augmented into the effect of higher contrast. available for numpy and cupy ndarray.

Arguments:
Parameters:
  • data (Union[numpy.ndarray, cupy.ndarray]) – the input tensor

  • k_shape (tuple[int, ...]) – the shape of averaging kernel; 3 for each dimension as default

  • k_mode (Literal) – method of edge filling; valid options are 'reflect', 'constant', 'nearest', 'mirror', and 'wrap'; 'reflect' as default

  • k_cval (Numeric) – filling number when k_mode is 'constant'; 0.0 as default

  • k_origin (Union[int, Iterable[int]]) – origin of anchor pixel in kernel; 0 as default

  • sobel_limen (Numeric) – (detector only) threshold for edge identification; values ranged from 0. to 1. for relative threshold using quantiles, otherwise the absolute one; 0.9 as default

  • sharp_alpha (Numeric) – (sharpen only) intensity for increasing edge contrast; 1 as default

Returns:

a numeric (filter, sharpen) or bool (detector) tensor

Return type:

Union[numpy.ndarray, cupy.ndarray]

Raises:

TypeErrordata is not assigned properly

Examples:
Code 3.54 sobel detector, filter and sharpen for image
from info.me import tensorn as tsn
from info.ins import datasets
img = datasets.blackcurrant()

# apply sobel detector
tsn.sobel_detector(data=img)

# apply sobel filter
tsn.sobel_filter(data=img)

# apply sobel sharpen
tsn.sobel_sharpen(data=img)
Logs:

Added in version 0.0.2.

– Created by Chen Zhang; Last updated on 01:34, 2025-09-06

sobel_detector

sobel detector to determine edge of tensor. each derivative operator is constructed with planes distributed as \(-G\) and \(G\) in start and end surface respectively, where \(G\) is 1-dimensional degenerated marginal distribution of Gaussian (see marginal probability). for sobel filter, gradient components of tensor were calculated for all axis then integrated through 2 norm. for sobel detector, pixels with gray level upper more than threshold will be identified as edges. for sobel sharpen, pixels around edge-like area will be augmented into the effect of higher contrast. available for numpy and cupy ndarray.

Arguments:
Parameters:
  • data (Union[numpy.ndarray, cupy.ndarray]) – the input tensor

  • k_shape (tuple[int, ...]) – the shape of averaging kernel; 3 for each dimension as default

  • k_mode (Literal) – method of edge filling; valid options are 'reflect', 'constant', 'nearest', 'mirror', and 'wrap'; 'reflect' as default

  • k_cval (Numeric) – filling number when k_mode is 'constant'; 0.0 as default

  • k_origin (Union[int, Iterable[int]]) – origin of anchor pixel in kernel; 0 as default

  • sobel_limen (Numeric) – (detector only) threshold for edge identification; values ranged from 0. to 1. for relative threshold using quantiles, otherwise the absolute one; 0.9 as default

  • sharp_alpha (Numeric) – (sharpen only) intensity for increasing edge contrast; 1 as default

Returns:

a numeric (filter, sharpen) or bool (detector) tensor

Return type:

Union[numpy.ndarray, cupy.ndarray]

Raises:

TypeErrordata is not assigned properly

Examples:
Code 3.55 sobel detector, filter and sharpen for image
from info.me import tensorn as tsn
from info.ins import datasets
img = datasets.blackcurrant()

# apply sobel detector
tsn.sobel_detector(data=img)

# apply sobel filter
tsn.sobel_filter(data=img)

# apply sobel sharpen
tsn.sobel_sharpen(data=img)
Logs:

Added in version 0.0.2.

– Created by Chen Zhang; Last updated on 01:34, 2025-09-06

sobel_sharpen

sobel sharpen to get higher-contrast-edge tensor. each derivative operator is constructed with planes distributed as \(-G\) and \(G\) in start and end surface respectively, where \(G\) is 1-dimensional degenerated marginal distribution of Gaussian (see marginal probability). for sobel filter, gradient components of tensor were calculated for all axis then integrated through 2 norm. for sobel detector, pixels with gray level upper more than threshold will be identified as edges. for sobel sharpen, pixels around edge-like area will be augmented into the effect of higher contrast. available for numpy and cupy ndarray.

Arguments:
Parameters:
  • data (Union[numpy.ndarray, cupy.ndarray]) – the input tensor

  • k_shape (tuple[int, ...]) – the shape of averaging kernel; 3 for each dimension as default

  • k_mode (Literal) – method of edge filling; valid options are 'reflect', 'constant', 'nearest', 'mirror', and 'wrap'; 'reflect' as default

  • k_cval (Numeric) – filling number when k_mode is 'constant'; 0.0 as default

  • k_origin (Union[int, Iterable[int]]) – origin of anchor pixel in kernel; 0 as default

  • sobel_limen (Numeric) – (detector only) threshold for edge identification; values ranged from 0. to 1. for relative threshold using quantiles, otherwise the absolute one; 0.9 as default

  • sharp_alpha (Numeric) – (sharpen only) intensity for increasing edge contrast; 1 as default

Returns:

a numeric (filter, sharpen) or bool (detector) tensor

Return type:

Union[numpy.ndarray, cupy.ndarray]

Raises:

TypeErrordata is not assigned properly

Examples:
Code 3.56 sobel detector, filter and sharpen for image
from info.me import tensorn as tsn
from info.ins import datasets
img = datasets.blackcurrant()

# apply sobel detector
tsn.sobel_detector(data=img)

# apply sobel filter
tsn.sobel_filter(data=img)

# apply sobel sharpen
tsn.sobel_sharpen(data=img)
Logs:

Added in version 0.0.2.

– Created by Chen Zhang; Last updated on 01:34, 2025-09-06

canny_filter

canny filter to highlight edge of tensor. each derivative operator is constructed with planes distributed as \(-G\) and \(G\) in start and end surface respectively, where \(G\) is 1-dimensional degenerated marginal distribution of Gaussian (see marginal probability). tensor will be preprocessed through kernel \(\mathcal{N}(\boldsymbol{\mu}, \boldsymbol{\Sigma})\). for canny filter, gradient components of tensor were calculated for all axis then integrated through 2 norm. for canny detector, pixels with gray level upper more than threshold will be identified as edges. for canny sharpen, pixels around edge-like area will be augmented into the effect of higher contrast. available for numpy and cupy ndarray.

Arguments:
Parameters:
  • data (Union[numpy.ndarray, cupy.ndarray]) – the input tensor

  • k_shape (tuple[int, ...]) – the shape of averaging kernel; 3 for each dimension as default

  • k_mode (Literal) – method of edge filling; valid options are 'reflect', 'constant', 'nearest', 'mirror', and 'wrap'; 'reflect' as default

  • k_cval (Numeric) – filling number when k_mode is 'constant'; 0.0 as default

  • k_origin (Union[int, Iterable[int]]) – origin of anchor pixel in kernel; 0 as default

  • canny_limen (Numeric) – (detector only) threshold for edge identification; values ranged from 0. to 1. for relative threshold using quantiles, otherwise the absolute one; 0.9 as default

  • sharp_alpha (Numeric) – (sharpen only) intensity for increasing edge contrast; 1 as default

Returns:

a numeric (filter, sharpen) or bool (detector) tensor

Return type:

Union[numpy.ndarray, cupy.ndarray]

Raises:

TypeErrordata is not assigned properly

Examples:
Code 3.57 canny detector, filter and sharpen for image
from info.me import tensorn as tsn
from info.ins import datasets
img = datasets.blackcurrant()

# apply canny detector
tsn.canny_detector(data=img)

# apply canny filter
tsn.canny_filter(data=img)

# apply canny sharpen
tsn.canny_sharpen(data=img)
Logs:

Added in version 0.0.2.

– Created by Chen Zhang; Last updated on 01:34, 2025-09-06

canny_detector

canny detector to determine edge of tensor. each derivative operator is constructed with planes distributed as \(-G\) and \(G\) in start and end surface respectively, where \(G\) is 1-dimensional degenerated marginal distribution of Gaussian (see marginal probability). tensor will be preprocessed through kernel \(\mathcal{N}(\boldsymbol{\mu}, \boldsymbol{\Sigma})\). for canny filter, gradient components of tensor were calculated for all axis then integrated through 2 norm. for canny detector, pixels with gray level upper more than threshold will be identified as edges. for canny sharpen, pixels around edge-like area will be augmented into the effect of higher contrast. available for numpy and cupy ndarray.

Arguments:
Parameters:
  • data (Union[numpy.ndarray, cupy.ndarray]) – the input tensor

  • k_shape (tuple[int, ...]) – the shape of averaging kernel; 3 for each dimension as default

  • k_mode (Literal) – method of edge filling; valid options are 'reflect', 'constant', 'nearest', 'mirror', and 'wrap'; 'reflect' as default

  • k_cval (Numeric) – filling number when k_mode is 'constant'; 0.0 as default

  • k_origin (Union[int, Iterable[int]]) – origin of anchor pixel in kernel; 0 as default

  • canny_limen (Numeric) – (detector only) threshold for edge identification; values ranged from 0. to 1. for relative threshold using quantiles, otherwise the absolute one; 0.9 as default

  • sharp_alpha (Numeric) – (sharpen only) intensity for increasing edge contrast; 1 as default

Returns:

a numeric (filter, sharpen) or bool (detector) tensor

Return type:

Union[numpy.ndarray, cupy.ndarray]

Raises:

TypeErrordata is not assigned properly

Examples:
Code 3.58 canny detector, filter and sharpen for image
from info.me import tensorn as tsn
from info.ins import datasets
img = datasets.blackcurrant()

# apply canny detector
tsn.canny_detector(data=img)

# apply canny filter
tsn.canny_filter(data=img)

# apply canny sharpen
tsn.canny_sharpen(data=img)
Logs:

Added in version 0.0.2.

– Created by Chen Zhang; Last updated on 01:34, 2025-09-06

canny_sharpen

canny sharpen to get higher-contrast-edge tensor. each derivative operator is constructed with planes distributed as \(-G\) and \(G\) in start and end surface respectively, where \(G\) is 1-dimensional degenerated marginal distribution of Gaussian (see marginal probability). tensor will be preprocessed through kernel \(\mathcal{N}(\boldsymbol{\mu}, \boldsymbol{\Sigma})\). for canny filter, gradient components of tensor were calculated for all axis then integrated through 2 norm. for canny detector, pixels with gray level upper more than threshold will be identified as edges. for canny sharpen, pixels around edge-like area will be augmented into the effect of higher contrast. available for numpy and cupy ndarray.

Arguments:
Parameters:
  • data (Union[numpy.ndarray, cupy.ndarray]) – the input tensor

  • k_shape (tuple[int, ...]) – the shape of averaging kernel; 3 for each dimension as default

  • k_mode (Literal) – method of edge filling; valid options are 'reflect', 'constant', 'nearest', 'mirror', and 'wrap'; 'reflect' as default

  • k_cval (Numeric) – filling number when k_mode is 'constant'; 0.0 as default

  • k_origin (Union[int, Iterable[int]]) – origin of anchor pixel in kernel; 0 as default

  • canny_limen (Numeric) – (detector only) threshold for edge identification; values ranged from 0. to 1. for relative threshold using quantiles, otherwise the absolute one; 0.9 as default

  • sharp_alpha (Numeric) – (sharpen only) intensity for increasing edge contrast; 1 as default

Returns:

a numeric (filter, sharpen) or bool (detector) tensor

Return type:

Union[numpy.ndarray, cupy.ndarray]

Raises:

TypeErrordata is not assigned properly

Examples:
Code 3.59 canny detector, filter and sharpen for image
from info.me import tensorn as tsn
from info.ins import datasets
img = datasets.blackcurrant()

# apply canny detector
tsn.canny_detector(data=img)

# apply canny filter
tsn.canny_filter(data=img)

# apply canny sharpen
tsn.canny_sharpen(data=img)
Logs:

Added in version 0.0.2.

– Created by Chen Zhang; Last updated on 01:34, 2025-09-06

laplacian_of_gaussian_filter

laplacian of gaussian filter to highlight edge of tensor. kernel of LoG is determined by Equation 3.22. for LoG filter, \(C_1 > 0\) then all weights in kernel will sum to 0, gradient components of tensor were calculated for all axis then integrated through 2 norm. for LoG detector, pixels with gray level upper more than threshold will be identified as edges. for LoG sharpen, \(C_1 < 0\) and pixels around edge-like area will be augmented into the effect of higher contrast. available for numpy and cupy ndarray.

Arguments:
Parameters:
  • data (Union[numpy.ndarray, cupy.ndarray]) – the input tensor

  • k_shape (tuple[int, ...]) – the shape of averaging kernel; 3 for each dimension as default

  • k_mode (Literal) – method of edge filling; valid options are 'reflect', 'constant', 'nearest', 'mirror', and 'wrap'; 'reflect' as default

  • k_cval (Numeric) – filling number when k_mode is 'constant'; 0.0 as default

  • k_origin (Union[int, Iterable[int]]) – origin of anchor pixel in kernel; 0 as default

  • log_limen (Numeric) – (detector only) threshold for edge identification; values ranged from 0. to 1. for relative threshold using quantiles, otherwise the absolute one; 0.9 as default

  • sharp_alpha (Numeric) – (sharpen only) intensity for increasing edge contrast; 1 as default

Returns:

a numeric (filter, sharpen) or bool (detector) tensor

Return type:

Union[numpy.ndarray, cupy.ndarray]

Raises:

TypeErrordata is not assigned properly

Examples:
Code 3.60 LoG detector, filter and sharpen for image
from info.me import tensorn as tsn
from info.ins import datasets
img = datasets.blackcurrant()

# apply LoG detector
tsn.laplacian_of_gaussian_detector(data=img)

# apply LoG filter
tsn.laplacian_of_gaussian_filter(data=img)

# apply LoG sharpen
tsn.laplacian_of_gaussian_sharpen(data=img)
Logs:

Added in version 0.0.2.

– Created by Chen Zhang; Last updated on 01:34, 2025-09-06

laplacian_of_gaussian_detector

laplacian of gaussian detector to determine edge of tensor. kernel of LoG is determined by Equation 3.22. for LoG filter, \(C_1 > 0\) then all weights in kernel will sum to 0, gradient components of tensor were calculated for all axis then integrated through 2 norm. for LoG detector, pixels with gray level upper more than threshold will be identified as edges. for LoG sharpen, \(C_1 < 0\) and pixels around edge-like area will be augmented into the effect of higher contrast. available for numpy and cupy ndarray.

Arguments:
Parameters:
  • data (Union[numpy.ndarray, cupy.ndarray]) – the input tensor

  • k_shape (tuple[int, ...]) – the shape of averaging kernel; 3 for each dimension as default

  • k_mode (Literal) – method of edge filling; valid options are 'reflect', 'constant', 'nearest', 'mirror', and 'wrap'; 'reflect' as default

  • k_cval (Numeric) – filling number when k_mode is 'constant'; 0.0 as default

  • k_origin (Union[int, Iterable[int]]) – origin of anchor pixel in kernel; 0 as default

  • log_limen (Numeric) – (detector only) threshold for edge identification; values ranged from 0. to 1. for relative threshold using quantiles, otherwise the absolute one; 0.9 as default

  • sharp_alpha (Numeric) – (sharpen only) intensity for increasing edge contrast; 1 as default

Returns:

a numeric (filter, sharpen) or bool (detector) tensor

Return type:

Union[numpy.ndarray, cupy.ndarray]

Raises:

TypeErrordata is not assigned properly

Examples:
Code 3.61 LoG detector, filter and sharpen for image
from info.me import tensorn as tsn
from info.ins import datasets
img = datasets.blackcurrant()

# apply LoG detector
tsn.laplacian_of_gaussian_detector(data=img)

# apply LoG filter
tsn.laplacian_of_gaussian_filter(data=img)

# apply LoG sharpen
tsn.laplacian_of_gaussian_sharpen(data=img)
Logs:

Added in version 0.0.2.

– Created by Chen Zhang; Last updated on 01:34, 2025-09-06

laplacian_of_gaussian_sharpen

laplacian of gaussian sharpen to get higher-contrast-edge tensor. kernel of LoG is determined by Equation 3.22. for LoG filter, \(C_1 > 0\) then all weights in kernel will sum to 0, gradient components of tensor were calculated for all axis then integrated through 2 norm. for LoG detector, pixels with gray level upper more than threshold will be identified as edges. for LoG sharpen, \(C_1 < 0\) and pixels around edge-like area will be augmented into the effect of higher contrast. available for numpy and cupy ndarray.

Arguments:
Parameters:
  • data (Union[numpy.ndarray, cupy.ndarray]) – the input tensor

  • k_shape (tuple[int, ...]) – the shape of averaging kernel; 3 for each dimension as default

  • k_mode (Literal) – method of edge filling; valid options are 'reflect', 'constant', 'nearest', 'mirror', and 'wrap'; 'reflect' as default

  • k_cval (Numeric) – filling number when k_mode is 'constant'; 0.0 as default

  • k_origin (Union[int, Iterable[int]]) – origin of anchor pixel in kernel; 0 as default

  • log_limen (Numeric) – (detector only) threshold for edge identification; values ranged from 0. to 1. for relative threshold using quantiles, otherwise the absolute one; 0.9 as default

  • sharp_alpha (Numeric) – (sharpen only) intensity for increasing edge contrast; 1 as default

Returns:

a numeric (filter, sharpen) or bool (detector) tensor

Return type:

Union[numpy.ndarray, cupy.ndarray]

Raises:

TypeErrordata is not assigned properly

Examples:
Code 3.62 LoG detector, filter and sharpen for image
from info.me import tensorn as tsn
from info.ins import datasets
img = datasets.blackcurrant()

# apply LoG detector
tsn.laplacian_of_gaussian_detector(data=img)

# apply LoG filter
tsn.laplacian_of_gaussian_filter(data=img)

# apply LoG sharpen
tsn.laplacian_of_gaussian_sharpen(data=img)
Logs:

Added in version 0.0.2.

– Created by Chen Zhang; Last updated on 01:34, 2025-09-06

difference_of_gaussian_filter

difference of gaussian filter to highlight edge of tensor. two kernels are determined by gaussian_kernel based on Equation 3.18. available for numpy and cupy ndarray.

Arguments:
Parameters:
  • data (Union[numpy.ndarray, cupy.ndarray]) – the input tensor

  • sigma_ratio (Numeric) – ratio of two scales of two kernels; 1.6 as default, suggested by Marr and Hildreth for balancing bandwidth and sensitivity [Marr1980]

  • k_shape (tuple[int, ...]) – the shape of averaging kernel; 3 for each dimension as default

  • k_mode (Literal) – method of edge filling; valid options are 'reflect', 'constant', 'nearest', 'mirror', and 'wrap'; 'reflect' as default

  • k_cval (Numeric) – filling number when k_mode is 'constant'; 0.0 as default

  • k_origin (Union[int, Iterable[int]]) – origin of anchor pixel in kernel; 0 as default

  • dog_limen (Numeric) – (detector only) threshold for edge identification; values ranged from 0. to 1. for relative threshold using quantiles, otherwise the absolute one; 0.9 as default

  • sharp_alpha (Numeric) – (sharpen only) intensity for increasing edge contrast; 1 as default

Returns:

a numeric (filter, sharpen) or bool (detector) tensor

Return type:

Union[numpy.ndarray, cupy.ndarray]

Raises:

TypeErrordata is not assigned properly

Examples:
Code 3.63 DoG detector, filter and sharpen for image
from info.me import tensorn as tsn
from info.ins import datasets
img = datasets.blackcurrant()

# apply DoG detector
tsn.difference_of_gaussian_detector(data=img)

# apply DoG filter
tsn.difference_of_gaussian_filter(data=img)

# apply DoG sharpen
tsn.difference_of_gaussian_sharpen(data=img)
Notes:

For covariance \(\boldsymbol{\Sigma}\) of multivariate gaussian distribution, its inverse \(\boldsymbol{\Sigma}^{-1}\) is also symmetric. Therefore, the derivative of covariance matrix \(\boldsymbol{\Sigma}\) in multivariate gaussian is:

(3.2)\[\begin{split}\begin{eqnarray} \frac{\partial f(\boldsymbol{x}|\boldsymbol{\mu},\boldsymbol{\Sigma})}{\partial \boldsymbol{\Sigma}} &=& \frac{[\boldsymbol{\Sigma}^{-1}(\boldsymbol{x}-\boldsymbol{\mu})(\boldsymbol{x}-\boldsymbol{\mu})^{T} \boldsymbol{\Sigma}^{-1} - \boldsymbol{\Sigma}^{-1}]}{2 \cdot (2\pi)^\frac{k}{2} \vert \boldsymbol{\Sigma} \vert^\frac{1}{2}} \exp{[-\frac{1}{2} (\boldsymbol{x} - \boldsymbol{\mu})^T \boldsymbol{\Sigma}^{-1} (\boldsymbol{x} - \boldsymbol{\mu})]} \\ &=& \frac{[\boldsymbol{\Sigma}^{-1}(\boldsymbol{x}-\boldsymbol{\mu}) (\boldsymbol{x}-\boldsymbol{\mu})^{T} \boldsymbol{\Sigma}^{-1} - \boldsymbol{\Sigma}^{-1}]}{2} f(\boldsymbol{x}|\boldsymbol{\mu},\boldsymbol{\Sigma}) \end{eqnarray}\end{split}\]

Whose format is almost identical as Equation 3.20. That is, the LoG can be approximated using gaussian filtered results with different scales.

See also:
Logs:

Added in version 0.0.4.

– Created by Chen Zhang; Last updated on 01:34, 2025-09-06

difference_of_gaussian_detector

difference of gaussian detector to determine edge of tensor. two kernels are determined by gaussian_kernel based on Equation 3.18. available for numpy and cupy ndarray.

Arguments:
Parameters:
  • data (Union[numpy.ndarray, cupy.ndarray]) – the input tensor

  • sigma_ratio (Numeric) – ratio of two scales of two kernels; 1.6 as default, suggested by Marr and Hildreth for balancing bandwidth and sensitivity [Marr1980]

  • k_shape (tuple[int, ...]) – the shape of averaging kernel; 3 for each dimension as default

  • k_mode (Literal) – method of edge filling; valid options are 'reflect', 'constant', 'nearest', 'mirror', and 'wrap'; 'reflect' as default

  • k_cval (Numeric) – filling number when k_mode is 'constant'; 0.0 as default

  • k_origin (Union[int, Iterable[int]]) – origin of anchor pixel in kernel; 0 as default

  • dog_limen (Numeric) – (detector only) threshold for edge identification; values ranged from 0. to 1. for relative threshold using quantiles, otherwise the absolute one; 0.9 as default

  • sharp_alpha (Numeric) – (sharpen only) intensity for increasing edge contrast; 1 as default

Returns:

a numeric (filter, sharpen) or bool (detector) tensor

Return type:

Union[numpy.ndarray, cupy.ndarray]

Raises:

TypeErrordata is not assigned properly

Examples:
Code 3.64 DoG detector, filter and sharpen for image
from info.me import tensorn as tsn
from info.ins import datasets
img = datasets.blackcurrant()

# apply DoG detector
tsn.difference_of_gaussian_detector(data=img)

# apply DoG filter
tsn.difference_of_gaussian_filter(data=img)

# apply DoG sharpen
tsn.difference_of_gaussian_sharpen(data=img)
Notes:

For covariance \(\boldsymbol{\Sigma}\) of multivariate gaussian distribution, its inverse \(\boldsymbol{\Sigma}^{-1}\) is also symmetric. Therefore, the derivative of covariance matrix \(\boldsymbol{\Sigma}\) in multivariate gaussian is:

(3.3)\[\begin{split}\begin{eqnarray} \frac{\partial f(\boldsymbol{x}|\boldsymbol{\mu},\boldsymbol{\Sigma})}{\partial \boldsymbol{\Sigma}} &=& \frac{[\boldsymbol{\Sigma}^{-1}(\boldsymbol{x}-\boldsymbol{\mu})(\boldsymbol{x}-\boldsymbol{\mu})^{T} \boldsymbol{\Sigma}^{-1} - \boldsymbol{\Sigma}^{-1}]}{2 \cdot (2\pi)^\frac{k}{2} \vert \boldsymbol{\Sigma} \vert^\frac{1}{2}} \exp{[-\frac{1}{2} (\boldsymbol{x} - \boldsymbol{\mu})^T \boldsymbol{\Sigma}^{-1} (\boldsymbol{x} - \boldsymbol{\mu})]} \\ &=& \frac{[\boldsymbol{\Sigma}^{-1}(\boldsymbol{x}-\boldsymbol{\mu}) (\boldsymbol{x}-\boldsymbol{\mu})^{T} \boldsymbol{\Sigma}^{-1} - \boldsymbol{\Sigma}^{-1}]}{2} f(\boldsymbol{x}|\boldsymbol{\mu},\boldsymbol{\Sigma}) \end{eqnarray}\end{split}\]

Whose format is almost identical as Equation 3.20. That is, the LoG can be approximated using gaussian filtered results with different scales.

See also:
Logs:

Added in version 0.0.4.

– Created by Chen Zhang; Last updated on 01:34, 2025-09-06

difference_of_gaussian_sharpen

difference of gaussian sharpen to get higher-contrast-edge tensor. two kernels are determined by gaussian_kernel based on Equation 3.18. available for numpy and cupy ndarray.

Arguments:
Parameters:
  • data (Union[numpy.ndarray, cupy.ndarray]) – the input tensor

  • sigma_ratio (Numeric) – ratio of two scales of two kernels; 1.6 as default, suggested by Marr and Hildreth for balancing bandwidth and sensitivity [Marr1980]

  • k_shape (tuple[int, ...]) – the shape of averaging kernel; 3 for each dimension as default

  • k_mode (Literal) – method of edge filling; valid options are 'reflect', 'constant', 'nearest', 'mirror', and 'wrap'; 'reflect' as default

  • k_cval (Numeric) – filling number when k_mode is 'constant'; 0.0 as default

  • k_origin (Union[int, Iterable[int]]) – origin of anchor pixel in kernel; 0 as default

  • dog_limen (Numeric) – (detector only) threshold for edge identification; values ranged from 0. to 1. for relative threshold using quantiles, otherwise the absolute one; 0.9 as default

  • sharp_alpha (Numeric) – (sharpen only) intensity for increasing edge contrast; 1 as default

Returns:

a numeric (filter, sharpen) or bool (detector) tensor

Return type:

Union[numpy.ndarray, cupy.ndarray]

Raises:

TypeErrordata is not assigned properly

Examples:
Code 3.65 DoG detector, filter and sharpen for image
from info.me import tensorn as tsn
from info.ins import datasets
img = datasets.blackcurrant()

# apply DoG detector
tsn.difference_of_gaussian_detector(data=img)

# apply DoG filter
tsn.difference_of_gaussian_filter(data=img)

# apply DoG sharpen
tsn.difference_of_gaussian_sharpen(data=img)
Notes:

For covariance \(\boldsymbol{\Sigma}\) of multivariate gaussian distribution, its inverse \(\boldsymbol{\Sigma}^{-1}\) is also symmetric. Therefore, the derivative of covariance matrix \(\boldsymbol{\Sigma}\) in multivariate gaussian is:

(3.4)\[\begin{split}\begin{eqnarray} \frac{\partial f(\boldsymbol{x}|\boldsymbol{\mu},\boldsymbol{\Sigma})}{\partial \boldsymbol{\Sigma}} &=& \frac{[\boldsymbol{\Sigma}^{-1}(\boldsymbol{x}-\boldsymbol{\mu})(\boldsymbol{x}-\boldsymbol{\mu})^{T} \boldsymbol{\Sigma}^{-1} - \boldsymbol{\Sigma}^{-1}]}{2 \cdot (2\pi)^\frac{k}{2} \vert \boldsymbol{\Sigma} \vert^\frac{1}{2}} \exp{[-\frac{1}{2} (\boldsymbol{x} - \boldsymbol{\mu})^T \boldsymbol{\Sigma}^{-1} (\boldsymbol{x} - \boldsymbol{\mu})]} \\ &=& \frac{[\boldsymbol{\Sigma}^{-1}(\boldsymbol{x}-\boldsymbol{\mu}) (\boldsymbol{x}-\boldsymbol{\mu})^{T} \boldsymbol{\Sigma}^{-1} - \boldsymbol{\Sigma}^{-1}]}{2} f(\boldsymbol{x}|\boldsymbol{\mu},\boldsymbol{\Sigma}) \end{eqnarray}\end{split}\]

Whose format is almost identical as Equation 3.20. That is, the LoG can be approximated using gaussian filtered results with different scales.

See also:
Logs:

Added in version 0.0.4.

– Created by Chen Zhang; Last updated on 01:34, 2025-09-06

hessian_determinant_response

hessian determinant to highlight corner of tensor. two kernels are determined by gaussian_kernel based on Equation 3.18. available for numpy and cupy ndarray.

Arguments:
Parameters:
  • data (Union[numpy.ndarray, cupy.ndarray]) – the input tensor

  • k_shape (tuple[int, ...]) – the shape of averaging kernel; 3 for each dimension as default

  • k_mode (Literal) – method of edge filling; valid options are 'reflect', 'constant', 'nearest', 'mirror', and 'wrap'; 'reflect' as default

  • k_cval (Numeric) – filling number when k_mode is 'constant'; 0.0 as default

  • in_spacing (Union[Numeric, Iterable[Numeric]]) – pixel spacing to determine differential operator; if numeric, operator uses equal spacing for all dimensions; if iterable of numeric, operator applies spacing in accordance with each numeric for each dimension; None as default to generate 1 spacing for all dimensions

  • hessian_limen (Numeric) – (detector only) threshold for edge identification; values ranged from 0. to 1. 0.9 as default

  • sharp_alpha (Numeric) – (sharpen only) intensity for increasing corner contrast; 1 as default

Returns:

a numeric (determinant, curvature) or bool (detector) tensor

Return type:

Union[numpy.ndarray, cupy.ndarray]

Raises:

TypeErrordata is not assigned properly

Examples:
Code 3.66 hessian detector, filter and sharpen for image
from info.me import tensorn as tsn
from info.ins import datasets
img = datasets.accent()

# apply hessian detector
tsn.hessian_detector(data=img)

# apply hessian filter
tsn.hessian_filter(data=img)

# apply hessian sharpen
tsn.hessian_sharpen(data=img)
Notes:

The gaussian curvature of \(m\)-dimensional tensor \(\textbf{I}\) is defined as:

(3.5)\[\textbf{K} = \frac{\det{(\boldsymbol{H}(\textbf{I}))}}{(1+\sum_{i=1}^m \textbf{I}_{d_i}^2)^2}\]

Where \(I_{d_i}\) refers the 1st order differentiate of \(I\), in aspect of the \(i\)-th dimension; \(\boldsymbol{H}(\textbf{I})\) is hessian matrix:

(3.6)\[\begin{split}\boldsymbol{H}(\textbf{I}) = \begin{bmatrix} \textbf{I}_{d_{1}d_{1}} & \dots & \textbf{I}_{d_{1}d_{m}} \\ \vdots & \ddots & \vdots \\ \textbf{I}_{d_{m}d_{1}} & \dots & \textbf{I}_{d_{m}d_{m}} \end{bmatrix}\end{split}\]

determinant and curvature responses the measure of the hessian matrix, and the gaussian curvature respectively. detector uses the limen based on numerical response of curvature.

Logs:

Added in version 0.0.4.

– Created by Chen Zhang; Last updated on 01:34, 2025-09-06

hessian_curvature_response

hessian curvature to highlight corner of tensor. two kernels are determined by gaussian_kernel based on Equation 3.18. available for numpy and cupy ndarray.

Arguments:
Parameters:
  • data (Union[numpy.ndarray, cupy.ndarray]) – the input tensor

  • k_shape (tuple[int, ...]) – the shape of averaging kernel; 3 for each dimension as default

  • k_mode (Literal) – method of edge filling; valid options are 'reflect', 'constant', 'nearest', 'mirror', and 'wrap'; 'reflect' as default

  • k_cval (Numeric) – filling number when k_mode is 'constant'; 0.0 as default

  • in_spacing (Union[Numeric, Iterable[Numeric]]) – pixel spacing to determine differential operator; if numeric, operator uses equal spacing for all dimensions; if iterable of numeric, operator applies spacing in accordance with each numeric for each dimension; None as default to generate 1 spacing for all dimensions

  • hessian_limen (Numeric) – (detector only) threshold for edge identification; values ranged from 0. to 1. 0.9 as default

  • sharp_alpha (Numeric) – (sharpen only) intensity for increasing corner contrast; 1 as default

Returns:

a numeric (determinant, curvature) or bool (detector) tensor

Return type:

Union[numpy.ndarray, cupy.ndarray]

Raises:

TypeErrordata is not assigned properly

Examples:
Code 3.67 hessian detector, filter and sharpen for image
from info.me import tensorn as tsn
from info.ins import datasets
img = datasets.accent()

# apply hessian detector
tsn.hessian_detector(data=img)

# apply hessian filter
tsn.hessian_filter(data=img)

# apply hessian sharpen
tsn.hessian_sharpen(data=img)
Notes:

The gaussian curvature of \(m\)-dimensional tensor \(\textbf{I}\) is defined as:

(3.7)\[\textbf{K} = \frac{\det{(\boldsymbol{H}(\textbf{I}))}}{(1+\sum_{i=1}^m \textbf{I}_{d_i}^2)^2}\]

Where \(I_{d_i}\) refers the 1st order differentiate of \(I\), in aspect of the \(i\)-th dimension; \(\boldsymbol{H}(\textbf{I})\) is hessian matrix:

(3.8)\[\begin{split}\boldsymbol{H}(\textbf{I}) = \begin{bmatrix} \textbf{I}_{d_{1}d_{1}} & \dots & \textbf{I}_{d_{1}d_{m}} \\ \vdots & \ddots & \vdots \\ \textbf{I}_{d_{m}d_{1}} & \dots & \textbf{I}_{d_{m}d_{m}} \end{bmatrix}\end{split}\]

determinant and curvature responses the measure of the hessian matrix, and the gaussian curvature respectively. detector uses the limen based on numerical response of curvature.

Logs:

Added in version 0.0.4.

– Created by Chen Zhang; Last updated on 01:34, 2025-09-06

hessian_curvature_detector

hessian detector to determine corners of tensor. two kernels are determined by gaussian_kernel based on Equation 3.18. available for numpy and cupy ndarray.

Arguments:
Parameters:
  • data (Union[numpy.ndarray, cupy.ndarray]) – the input tensor

  • k_shape (tuple[int, ...]) – the shape of averaging kernel; 3 for each dimension as default

  • k_mode (Literal) – method of edge filling; valid options are 'reflect', 'constant', 'nearest', 'mirror', and 'wrap'; 'reflect' as default

  • k_cval (Numeric) – filling number when k_mode is 'constant'; 0.0 as default

  • in_spacing (Union[Numeric, Iterable[Numeric]]) – pixel spacing to determine differential operator; if numeric, operator uses equal spacing for all dimensions; if iterable of numeric, operator applies spacing in accordance with each numeric for each dimension; None as default to generate 1 spacing for all dimensions

  • hessian_limen (Numeric) – (detector only) threshold for edge identification; values ranged from 0. to 1. 0.9 as default

  • sharp_alpha (Numeric) – (sharpen only) intensity for increasing corner contrast; 1 as default

Returns:

a numeric (determinant, curvature) or bool (detector) tensor

Return type:

Union[numpy.ndarray, cupy.ndarray]

Raises:

TypeErrordata is not assigned properly

Examples:
Code 3.68 hessian detector, filter and sharpen for image
from info.me import tensorn as tsn
from info.ins import datasets
img = datasets.accent()

# apply hessian detector
tsn.hessian_detector(data=img)

# apply hessian filter
tsn.hessian_filter(data=img)

# apply hessian sharpen
tsn.hessian_sharpen(data=img)
Notes:

The gaussian curvature of \(m\)-dimensional tensor \(\textbf{I}\) is defined as:

(3.9)\[\textbf{K} = \frac{\det{(\boldsymbol{H}(\textbf{I}))}}{(1+\sum_{i=1}^m \textbf{I}_{d_i}^2)^2}\]

Where \(I_{d_i}\) refers the 1st order differentiate of \(I\), in aspect of the \(i\)-th dimension; \(\boldsymbol{H}(\textbf{I})\) is hessian matrix:

(3.10)\[\begin{split}\boldsymbol{H}(\textbf{I}) = \begin{bmatrix} \textbf{I}_{d_{1}d_{1}} & \dots & \textbf{I}_{d_{1}d_{m}} \\ \vdots & \ddots & \vdots \\ \textbf{I}_{d_{m}d_{1}} & \dots & \textbf{I}_{d_{m}d_{m}} \end{bmatrix}\end{split}\]

determinant and curvature responses the measure of the hessian matrix, and the gaussian curvature respectively. detector uses the limen based on numerical response of curvature.

Logs:

Added in version 0.0.4.

– Created by Chen Zhang; Last updated on 01:34, 2025-09-06

moravec_response

moravec response for tensor. approach using for edge and corner augment. available for numpy and cupy ndarray.

Arguments:
Parameters:
  • data (Union[numpy.ndarray, cupy.ndarray]) – the input tensor

  • norm_order (int) – norm order to determine how to aggregate differentials vector; 2 as default to use Euclidean norm

  • k_mode (Literal) – method of edge filling; valid options are 'reflect', 'constant', 'nearest', 'mirror', and 'wrap'; 'reflect' as default

  • k_cval (Numeric) – filling number when k_mode is 'constant'; 0.0 as default

Returns:

the moravec response tensor

Return type:

Union[numpy.ndarray, cupy.ndarray]

Raises:

TypeErrordata is not assigned properly

Examples:
Code 3.69 moravec response on image
from info.me import tensorn as tsn
from info.ins import datasets
img = datasets.accent()

tsn.moravec_response(data=img)
Notes:

The moravec response can be summarized simply as:

(3.11)\[\textbf{M} = f(\textbf{T}_{\boldsymbol{i}(\boldsymbol{j})} - \textbf{T}_\boldsymbol{j})\]

Where \(\textbf{T}\) and \(\textbf{M}\) is the original tensor, and its moravec response respectively. \(\boldsymbol{j}\) and \(\boldsymbol{i}(\boldsymbol{j})\) are indices both in \(\mathbb{Z}^{m+}\), and \(\boldsymbol{i}(\boldsymbol{j})\) is the function of \(\boldsymbol{j}\) who satisfies (assume \(\boldsymbol{v} = \boldsymbol{i}(\boldsymbol{j}) - \boldsymbol{j}\)) each element \(v_k\) in \(\boldsymbol{v}\) is in set \(\{0, 1\}\), and \(\sum_{k=1}^{m} v_k \neq 0\).

As for each index \(\boldsymbol{j}\), the function mapping \(\boldsymbol{i}(\boldsymbol{j})\) will expand \(\textbf{T}_{\boldsymbol{i}(\boldsymbol{j})}\) one dimension plus, to contain the indices who satisfy the above-mentioned constraints. This results the container is in \(\mathbb{R}^{(m+1)}\) who packages all differentials related to original pixels, the function \(f\) needs to degenerate this expanded dimension, via aggregation approaches.

Logs:

Added in version 0.0.4.

– Created by Chen Zhang; Last updated on 01:34, 2025-09-06

harris_response

harris curvature response for tensor. approach using for corner augment. available for numpy and cupy ndarray.

Arguments:
Parameters:
  • data (Union[numpy.ndarray, cupy.ndarray]) – the input tensor

  • in_spacing (Union[Numeric, Iterable[Numeric]]) – spacing for each dimension in the unit voxel; if no-iterable numeric object, this value will be applied on all dimensions. 1 as default, to calculate in pixel spacing

  • trace_coef (Numeric) – coefficient of trace in harris response; range from 0.04 to 0.06 is suggested; 0.05 as default

  • clip_window (Literal['binomial', 'continuous']) – window function for harris kernel; 'binomial' applies a rescaled binary gaussian kernel, and 'continuous' applies a gaussian kernel; 'binomial' as default

  • k_shape (tuple[int, ...]) – tuple for kernel shape; None as default to apply 3 in all dimensions

  • k_mode (Literal) – method of edge filling; valid options are 'reflect', 'constant', 'nearest', 'mirror', and 'wrap'; 'reflect' as default

  • k_cval (Numeric) – filling number when k_mode is 'constant'; 0.0 as default

Returns:

the harris curvature response tensor

Return type:

Union[numpy.ndarray, cupy.ndarray]

Raises:

TypeErrordata is not assigned properly

Examples:
Code 3.70 harris response on image
from info.me import tensorn as tsn
from info.ins import datasets
img = datasets.accent()

tsn.harris_response(data=img)
Nots:

For harris response, it can be defined as:

(3.12)\[\textbf{H}(\boldsymbol{i}) = \sum_{\boldsymbol{j}} w(\boldsymbol{j}) [\textbf{T}(\boldsymbol{i} + \boldsymbol{j}) - \textbf{T}(\boldsymbol{i})]^2\]

Where \(\textbf{T}\) and \(\textbf{M}\) is the original tensor, and its moravec response respectively. \(\boldsymbol{i}\) is the index in \(\textbf{T}\), and \(\boldsymbol{j}\) is the index in harris kernel. \(w(\boldsymbol{j})\) is the clip window for computing weight of kernel. if it uses binary option, all values in kernel will be \(\{0, a\}\) where the sum of \(a\) is positions of \(m\)-dimensional ellipse determined by kernel shape, and the sum of kernel will be 1; if continuous option is selected, weight uses general gaussian distribution.

Using 1st order Taylor expansion as approximation, each pixel of \(\textbf{T}\) will be expanded in two extra dimensions (cornerness matrix) as:

(3.13)\[\begin{split}\boldsymbol{M} = \sum_{j} w(\boldsymbol{j}) \begin{bmatrix} \textbf{T}_{d_{1}}^2 & \cdots & \textbf{T}_{d_1} \textbf{T}_{d_m} \\ \vdots & \ddots & \vdots \\ \textbf{T}_{d_m}\textbf{T}_{d_1} & \cdots & \textbf{T}_{d_{m}}^2 \end{bmatrix}\end{split}\]

Where \(T_{d_i}\) refers the 1st order differentiate of \(\textbf{T}\), in aspect of the \(i\)-th dimension. In practice, cornerness is implemented using \(C = \det{\boldsymbol{M}} - k (\mathrm{Tr}(\boldsymbol{M}))^2\), where \(k\) is the hyperparameter had effect on cornerness computing, the determinant and trace of \(\boldsymbol{M}\) can be obtained through its singular values.

Logs:

Added in version 0.0.4.

– Created by Chen Zhang; Last updated on 01:34, 2025-09-06

usan_response

usan response for tensor. approach using for edge and corner augment. available for numpy and cupy ndarray.

Arguments:
Parameters:
  • data (Union[numpy.ndarray, cupy.ndarray]) – the input tensor

  • k_shape (tuple[int, ...]) – the shape of averaging kernel; 3 for each dimension as default

  • k_mode (Literal) – method of edge filling; valid options are 'reflect', 'constant', 'nearest', 'mirror', and 'wrap'; 'reflect' as default

  • k_cval (Numeric) – filling number when k_mode is 'constant'; 0.0 as default

  • clip_window (Literal['binomial', 'continuous']) – window function for harris kernel; 'binomial' applies a rescaled binary gaussian kernel, and 'continuous' applies 3rd moment of gaussian kernel; 'binomial' as default

Returns:

the usan response tensor

Return type:

Union[numpy.ndarray, cupy.ndarray]

Raises:

TypeErrordata is not assigned properly

Examples:
Code 3.71 usan and susan response on image
from info.me import tensorn as tsn
from info.ins import datasets
img = datasets.accent()

usan = tsn.usan_response(data=img)
susan = (40 - usan).clip(0, None)  # use 40 as susan threshold
Notes:

usan response generates a series of kernels, to obtain differentials from \(m\)-dimensional ellipse determined by shape, related to the center of the kernel. By determining the threshold \(g\), the function mapping \(\min(0, g-\mathrm{usan\_response}(\textbf{T}))\) will be the corresponding susan response (see Smith1997).

Logs:

Added in version 0.0.4.

– Created by Chen Zhang; Last updated on 01:34, 2025-09-06

segment_response

segment test response for tensor. approach using for edge and corner augment. available for numpy and cupy ndarray.

Arguments:
Parameters:
  • data (Union[numpy.ndarray, cupy.ndarray]) – the input tensor

  • k_shape (tuple[int, ...]) – the shape of averaging kernel; 3 for each dimension as default

  • k_mode (Literal) – method of edge filling; valid options are 'reflect', 'constant', 'nearest', 'mirror', and 'wrap'; 'reflect' as default

  • k_cval (Numeric) – filling number when k_mode is 'constant'; 0.0 as default

  • segment_threshold (Numeric) – threshold, to reject pixels whose differential is lower than that value in any orthogonal direction; if it ranges in \((0, 1)\), the quantile will be used; 0.6 as default

Returns:

the segment test response tensor

Return type:

Union[numpy.ndarray, cupy.ndarray]

Raises:

TypeErrordata is not assigned properly

Examples:
Code 3.72 segment test response on image
from info.me import tensorn as tsn
from info.ins import datasets
img = datasets.accent()

tsn.segment_response(data=img)
Notes:

Kernel of segment test uses \(m\)-dimensional ellipsoidal shell, instead of \(m\)-dimensional ellipse. Pixels whose differential in any orthogonal direction is lower than the threshold will be rejected, then the accepted pixels will be subdivided into positive and negative classes. Absolute sum mapping is applied on the two classes, then the final response of pixel is determined by the maximum of the two sums.

Logs:

Added in version 0.0.4.

– Created by Chen Zhang; Last updated on 01:34, 2025-09-06

fast_response

fast response for tensor. approach using for edge and corner augment. available for numpy and cupy ndarray.

Arguments:
Parameters:
  • data (Union[numpy.ndarray, cupy.ndarray]) – the input tensor

  • k_shape (tuple[int, ...]) – the shape of averaging kernel; 3 for each dimension as default

  • k_mode (Literal) – method of edge filling; valid options are 'reflect', 'constant', 'nearest', 'mirror', and 'wrap'; 'reflect' as default

  • k_cval (Numeric) – filling number when k_mode is 'constant'; 0.0 as default

  • fast_reject_thresholds (Union[float, tuple[Numeric, Numeric]]) – thresholds of (a, b) to make \(\mathbb{R}^1\) into division \((-\infty, a] \cup (a, b] \cup (b,+\infty)\), as the scopes for differentials lower than, similar as, and greater than the kernel center respectively; if single float \(t\), it must range from 0 to 0.5, for quantiles of (t, 1-t); if a and b both range from 0 to 1, quantiles are calculated automatically; else uses the numeric themselves; (0.4, 0.6) as default

  • fast_classifier (Optional[Callable]) – callable object to transfer vector container for differentials to numeric; None as default to not apply

Returns:

the fast response tensor

Return type:

Union[numpy.ndarray, cupy.ndarray]

Raises:

TypeErrordata is not assigned properly

Examples:
Code 3.73 fast response on image
from info.me import tensorn as tsn
from info.ins import datasets
img = datasets.accent()

tsn.fast_response(data=img)
Notes:

Kernel of segment test uses \(m\)-dimensional ellipsoidal shell, instead of \(m\)-dimensional ellipse. Pixels whose differentials will be subdivided into three classes: similar as, lower, and greater than, through two pre-defined thresholds. Two sums are calculated in last two types, then final response is determined by the maximum of the two sums.

Logs:

Added in version 0.0.4.

– Created by Chen Zhang; Last updated on 01:34, 2025-09-06

3.1.3.2.2. Boolean tensor

prober

sub segmentation generator from a bool ndarray. available for numpy and cupy ndarray.

Arguments:
Parameters:
  • data (Union[numpy.ndarray, cupy.ndarray]) – the bool ndarray segmentation

  • prob_nums (int) – number of generated sub segmentations

  • prob_radius (Numeric) – radius for each generated sub segmentations

  • in_spacing (Optional[tuple[Numeric, ...]]) – voxel spacing for all dimensions; if assigned, prob_radius will be re-calculated, to adapt voxel space; None as default to use pixel space

Returns:

generator composed of sub segmentations with specified radius

Return type:

Union[numpy.ndarray, cupy.ndarray]

Raises:

TypeErrordata, prob_nums or prob_radius are not assigned properly

Examples:
Code 3.74 generate 15 sub segmentations from a meta segmentations
from info.me import tensorb as tsb
for seg in tsb.prober(data=meta_segmentation, prob_nums=15, prob_radius=5):
    print(seg.sum())
Logs:

Added in version 0.0.3.

Changed in version 0.0.4: support in_spacing argument for sampling in voxel space.

– Created by Chen Zhang; Last updated on 01:34, 2025-09-06

connected_domain

connected domain generator from a bool or an integer ndarray. available for numpy and cupy ndarray.

Arguments:
Parameters:
  • data (Union[numpy.ndarray, cupy.ndarray]) – bool ndarray segmentation, or int ndarray using different integers for connected domains

  • detector (Union[numpy.ndarray, cupy.ndarray]) – structure to determine connected domain; None as default to use orthogonal connection in each dimension

Returns:

generator composed of connected domains as segmentations

Return type:

Union[numpy.ndarray, cupy.ndarray]

Raises:

TypeErrordata is not assigned properly

Examples:
Code 3.75 generate connected domains from a meta segmentation
from info.me import tensorb as tsb
from info.ins import datasets
for msk in tsb.connected_domain(data=datasets.segs()):
    print(msk.sum())
Logs:

Added in version 0.0.4.

– Created by Chen Zhang; Last updated on 01:34, 2025-09-06

seg_resize

resizing data into specific shape. spline interpolation supported. algorithm is implemented through canonical decomposition [Battaglino2018]. available for numpy and cupy ndarray.

Arguments:
Parameters:
  • data (Union[numpy.ndarray, cupy.ndarray]) – data to be resized

  • new_size (tuple[int]) – tuple to determine new size for input data

  • interp_method (Literal[...]) – interpolation method links to kind argument of interp1d; options are 'linear', 'nearest', 'nearest-up', 'zero', 'slinear', 'quadratic', 'cubic', 'previous', and 'next'; 'linear' as default

Returns:

re-sized data

Return type:

Union[numpy.ndarray, cupy.ndarray]

Raises:

TypeError – if data or new_size was not assigned properly

Examples:
Code 3.76 resize a meta segmentation
from info.me import tensorb as tsb
from info.ins import datasets

new_seg = tsb.resize(data=datasets.segs(), new_size=(70, 80))
See also:
Logs:

Added in version 0.0.4.

– Created by Chen Zhang; Last updated on 01:34, 2025-09-06

erosion

morphological erosion operation for boolean tensor. can be applied in pixel or voxel space. available for numpy and cupy ndarray.

Arguments:
Parameters:
  • data (Union[numpy.ndarray, cupy.ndarray]) – the bool ndarray segmentation

  • norm (Union[Numeric, Iterable[Numeric]]) – criterion to be eroded; 2nd order norm for orthogonal components in each dimension if numeric; or a sequence of numeric, customized in each dimension; 1 as default

  • in_spacing (Iterable[Numeric]) – spacing for each dimension in the unit voxel; None as default for pixel spacing

Returns:

eroded segmentation

Return type:

Union[numpy.ndarray, cupy.ndarray]

Raises:

TypeError – if data is not assigned properly

Examples:
Code 3.77 erosion for segmentations
from info.me import tensorb as tsb
from info.ins import datasets
segs = datasets.segs()

# erosion in pixel space
seg1 = tsb.erosion(data=segs)

# erosion in voxel space
seg2 = tsb.erosion(data=segs, in_spacing=(1.1, 3))

# customized erosion in voxel space
seg3 = tsb.erosion(data=segs, norm=(3.3, 6), in_spacing=(1.1, 3))
Logs:

Added in version 0.0.4.

– Created by Chen Zhang; Last updated on 01:34, 2025-09-06

dilation

morphological dilation operation for boolean tensor. can be applied in pixel or voxel space. available for numpy and cupy ndarray.

Arguments:
Parameters:
  • data (Union[numpy.ndarray, cupy.ndarray]) – the bool ndarray segmentation

  • norm (Union[Numeric, Iterable[Numeric]]) – criterion to be eroded; 2nd order norm for orthogonal components in each dimension if numeric; or a sequence of numeric, customized in each dimension; 1 as default

  • in_spacing (Iterable[Numeric]) – spacing for each dimension in the unit voxel; None as default for pixel spacing

Returns:

eroded segmentation

Return type:

Union[numpy.ndarray, cupy.ndarray]

Raises:

TypeError – if data is not assigned properly

Examples:
Code 3.78 dilation for segmentations
from info.me import tensorb as tsb
from info.ins import datasets
segs = datasets.segs()

# dilation in pixel space
seg1 = tsb.dilation(data=segs)

# dilation in voxel space
seg2 = tsb.dilation(data=segs, in_spacing=(1.1, 3))

# customized dilation in voxel space
seg3 = tsb.dilation(data=segs, norm=(3.3, 6), in_spacing=(1.1, 3))
Logs:

Added in version 0.0.4.

– Created by Chen Zhang; Last updated on 01:34, 2025-09-06

intersection

intersection operation for boolean tensor. available for numpy and cupy ndarray.

Arguments:
Parameters:
  • data (Union[numpy.ndarray, cupy.ndarray]) – the bool ndarray segmentation

  • instances (Union[ndarray, list[ndarray]]) – the intersection of data and instances segmentations

Returns:

intersection segmentation

Return type:

Union[numpy.ndarray, cupy.ndarray]

Raises:

TypeError – if data and instances are not assigned properly

Examples:
Code 3.79 calculate intersection of segmentations
from info.me import tensorb as tsb
seg, other_segs = ...  # ndarray, list of boolean ndarray

intersection_seg = tsb.intersection(data=seg, instances=other_segs)
Logs:

Added in version 0.0.4.

– Created by Chen Zhang; Last updated on 01:34, 2025-09-06

union

union operation for boolean tensor. available for numpy and cupy ndarray.

Arguments:
Parameters:
  • data (Union[numpy.ndarray, cupy.ndarray]) – the bool ndarray segmentation

  • instances (Union[ndarray, list[ndarray]]) – the union of data and instances segmentations

Returns:

union segmentation

Return type:

Union[numpy.ndarray, cupy.ndarray]

Raises:

TypeError – if data and instances are not assigned properly

Examples:
Code 3.80 calculate union of segmentations
from info.me import tensorb as tsb
seg, other_segs = ...  # ndarray, list of boolean ndarray

union_seg = tsb.union(data=seg, instances=other_segs)
Logs:

Added in version 0.0.4.

– Created by Chen Zhang; Last updated on 01:34, 2025-09-06

difference

difference operation for boolean tensor. available for numpy and cupy ndarray.

Arguments:
Parameters:
  • data (Union[numpy.ndarray, cupy.ndarray]) – the bool ndarray segmentation

  • instances (Union[ndarray, list[ndarray]]) – the difference of data and instances segmentations

Returns:

difference segmentation

Return type:

Union[numpy.ndarray, cupy.ndarray]

Raises:

TypeError – if data and instances are not assigned properly

Examples:
Code 3.81 calculate difference of segmentations
from info.me import tensorb as tsb
seg, other_segs = ...  # ndarray, list of boolean ndarray

difference_seg = tsb.difference(data=seg, instances=other_segs)
Logs:

Added in version 0.0.4.

– Created by Chen Zhang; Last updated on 01:34, 2025-09-06

watershed

watershed algorithm for labeling segmentation. available for numpy and cupy ndarray.

Arguments:
Parameters:
  • data (Union[numpy.ndarray, cupy.ndarray]) – the bool ndarray segmentation

  • flood_seeds (Union[numpy.ndarray, cupy.ndarray]) – initial positions for flooding; must be label object with integers to mark each individual segmentation

  • flood_geography (Union[numpy.ndarray, cupy.ndarray]) – geography for flooding; None as default will calculate through basic segmentation

  • label_output (bool) – trigger to determine whether return label-like result; if True, a label-like ndarray will be obtained, otherwise a generator of bool ndarray for each label; True as default

Returns:

ndarray of labels as flood_seeds, or generator of bool ndarray for each label

Return type:

Union[numpy.ndarray, cupy.ndarray, Generator]

Raises:

TypeError – if data and flood_seeds are not assigned properly

Examples:
Code 3.82 watershed for segmentations
from info.me import tensorb as tsb
import numpy as np

msk = np.zeros((512, 512))
y, x = np.ogrid[0:512, 0:512]
centers = np.array([(200, 100), (350, 400), (260, 200)])
m1, m2, m3 = [(y - c[0]) ** 2 + (x - c[1]) ** 2 < 30 ** 2 for c in centers]
msk[m1 + m2 + m3] = 1
seeds = np.zeros_like(msk)
_ = [seeds.__setitem__(tuple(c), idx+1) for idx, c in enumerate(centers)]
msk = msk.astype(bool)

res = tsb.watershed(data=msk, flood_seeds=seeds)
Notes:

Numpy implementation for topological watershed algorithm suggested by Beucher, S. and & Meyer, F..

Logs:

Added in version 0.0.4.

– Created by Chen Zhang; Last updated on 01:34, 2025-09-06


Authors:

Chen Zhang

Version:

0.0.5

Created on:

Jun 27, 2023