Filters

gabor

class MEDimage.filters.gabor.Gabor(size: int, sigma: float, lamb: float, gamma: float, theta: float, rot_invariance=False, padding='symmetric')[source]

Bases: object

The Gabor filter class

__init__(size: int, sigma: float, lamb: float, gamma: float, theta: float, rot_invariance=False, padding='symmetric') None[source]

The constructor of the Gabor filter. Highly inspired by Ref 1.

Parameters:
  • size (int) – An integer that represent the length along one dimension of the kernel.

  • sigma (float) – A positive float that represent the scale of the Gabor filter

  • lamb (float) – A positive float that represent the wavelength in the Gabor filter. (mm or pixel?)

  • gamma (float) – A positive float that represent the spacial aspect ratio

  • theta (float) – Angle parameter used in the rotation matrix

  • rot_invariance (bool) – If true, rotation invariance will be done on the kernel and the kernel will be rotate 2*pi / theta times.

  • padding – The padding type that will be used to produce the convolution

Returns:

None

convolve(images: ndarray, orthogonal_rot=False, pooling_method='mean') ndarray[source]

Filter a given image using the Gabor kernel defined during the construction of this instance.

Parameters:
  • images (ndarray) – A n-dimensional numpy array that represent the images to filter

  • orthogonal_rot (bool) – If true, the 3D images will be rotated over coronal, axial and sagittal axis

Returns:

The filtered image as a numpy ndarray

Return type:

ndarray

create_kernel() List[ndarray][source]

Create the kernel of the Gabor filter

Returns:

A list of numpy 2D-array that contain the kernel of the real part and the imaginary part respectively.

Return type:

List[ndarray]

MEDimage.filters.gabor.apply_gabor(input_images: image_volume_obj | ndarray, medscan: MEDscan | None = None, voxel_length: float = 0.0, sigma: float = 0.0, _lambda: float = 0.0, gamma: float = 0.0, theta: float = 0.0, rot_invariance: bool = False, padding: str = 'symmetric', orthogonal_rot: bool = False, pooling_method: str = 'mean') ndarray[source]

Apply the Gabor filter to a given imaging data.

Parameters:
  • input_images (Union[image_volume_obj, np.ndarray]) – The input images to filter.

  • medscan (MEDscan, optional) – The MEDscan object that will provide the filter parameters.

  • voxel_length (float, optional) – The voxel size of the input image.

  • sigma (float, optional) – A positive float that represent the scale of the Gabor filter.

  • _lambda (float, optional) – A positive float that represent the wavelength in the Gabor filter.

  • gamma (float, optional) – A positive float that represent the spacial aspect ratio.

  • theta (float, optional) – Angle parameter used in the rotation matrix.

  • rot_invariance (bool, optional) – If true, rotation invariance will be done on the kernel and the kernel will be rotate 2*pi / theta times.

  • padding (str, optional) – The padding type that will be used to produce the convolution. Check options here: numpy.pad.

  • orthogonal_rot (bool, optional) – If true, the 3D images will be rotated over coronal, axial and sagittal axis.

Returns:

The filtered image.

Return type:

ndarray

laws

class MEDimage.filters.laws.Laws(config: List | None = None, energy_distance: int = 7, rot_invariance: bool = False, padding: str = 'symmetric')[source]

Bases: object

The Laws filter class

__init__(config: List | None = None, energy_distance: int = 7, rot_invariance: bool = False, padding: str = 'symmetric')[source]

The constructor of the Laws filter

Parameters:
  • config (str) – A string list of every 1D filter used to create the Laws kernel. Since the outer product is not commutative, we need to use a list to specify the order of the outer product. It is not recommended to use filter of different size to create the Laws kernel.

  • energy_distance (float) – The distance that will be used to create the energy_kernel.

  • rot_invariance (bool) – If true, rotation invariance will be done on the kernel.

  • padding (str) – The padding type that will be used to produce the convolution

Returns:

None

convolve(images: ndarray, orthogonal_rot=False, energy_image=False)[source]

Filter a given image using the Laws kernel defined during the construction of this instance.

Parameters:
  • images (ndarray) – A n-dimensional numpy array that represent the images to filter

  • orthogonal_rot (bool) – If true, the 3D images will be rotated over coronal, axial and sagittal axis

  • energy_image (bool) – If true, return also the Laws Texture Energy Images

Returns:

The filtered image

Return type:

ndarray

create_kernel() ndarray[source]

Create the Laws by computing the outer product of 1d filter specified in the config attribute. Kernel = config[0] X config[1] X … X config[n]. Where X is the outer product.

Returns:

A numpy multi-dimensional arrays that represent the Laws kernel.

Return type:

ndarray

MEDimage.filters.laws.apply_laws(input_images: ndarray | image_volume_obj, medscan: MEDscan | None = None, config: List[str] = [], energy_distance: int = 7, padding: str = 'symmetric', rot_invariance: bool = False, orthogonal_rot: bool = False, energy_image: bool = False) ndarray[source]

Apply the mean filter to the input image

Parameters:
  • input_images (ndarray) – The images to filter.

  • medscan (MEDscan, optional) – The MEDscan object that will provide the filter parameters.

  • config (List[str], optional) – A string list of every 1D filter used to create the Laws kernel. Since the outer product is not commutative, we need to use a list to specify the order of the outer product. It is not recommended to use filter of different size to create the Laws kernel.

  • energy_distance (int, optional) – The distance of the Laws energy map from the center of the image.

  • padding (str, optional) – The padding type that will be used to produce the convolution. Check options here: numpy.pad.

  • rot_invariance (bool, optional) – If true, rotation invariance will be done on the kernel.

  • orthogonal_rot (bool, optional) – If true, the 3D images will be rotated over coronal, axial and sagittal axis.

  • energy_image (bool, optional) – If true, will compute and return the Laws Texture Energy Images.

Returns:

The filtered image.

Return type:

ndarray

log

class MEDimage.filters.log.LaplacianOfGaussian(ndims: int, size: int, sigma: float = 0.1, padding: str = 'symmetric')[source]

Bases: object

The Laplacian of gaussian filter class.

__init__(ndims: int, size: int, sigma: float = 0.1, padding: str = 'symmetric')[source]

The constructor of the laplacian of gaussian (LoG) filter

Parameters:
  • ndims (int) – Number of dimension of the kernel filter

  • size (int) – An integer that represent the length along one dimension of the kernel.

  • sigma (float) – The gaussian standard deviation parameter of the laplacian of gaussian filter

  • padding (str) – The padding type that will be used to produce the convolution

Returns:

None

convolve(images: ndarray, orthogonal_rot=False) ndarray[source]

Filter a given image using the LoG kernel defined during the construction of this instance.

Parameters:
  • images (ndarray) – A n-dimensional numpy array that represent the images to filter

  • orthogonal_rot (bool) – If true, the 3D images will be rotated over coronal, axial and sagittal axis

Returns:

The filtered image

Return type:

ndarray

create_kernel() ndarray[source]

This method construct the LoG kernel using the parameters specified to the constructor

Returns:

The laplacian of gaussian kernel as a numpy multidimensional array

Return type:

ndarray

MEDimage.filters.log.apply_log(input_images: ndarray | image_volume_obj, medscan: MEDscan | None = None, ndims: int = 3, voxel_length: float = 0.0, sigma: float = 0.1, padding: str = 'symmetric', orthogonal_rot: bool = False) ndarray[source]

Apply the mean filter to the input image

Parameters:
  • input_images (ndarray) – The images to filter.

  • medscan (MEDscan, optional) – The MEDscan object that will provide the filter parameters.

  • ndims (int, optional) – The number of dimensions of the input image.

  • voxel_length (float, optional) – The voxel size of the input image.

  • sigma (float, optional) – standard deviation of the Gaussian, controls the scale of the convolutional operator.

  • padding (str, optional) – The padding type that will be used to produce the convolution. Check options here: numpy.pad.

  • orthogonal_rot (bool, optional) – If true, the 3D images will be rotated over coronal, axial and sagittal axis.

Returns:

The filtered image.

Return type:

ndarray

mean

class MEDimage.filters.mean.Mean(ndims: int, size: int, padding='symmetric')[source]

Bases: object

The mean filter class

__init__(ndims: int, size: int, padding='symmetric')[source]

The constructor of the mean filter

Parameters:
  • ndims (int) – Number of dimension of the kernel filter

  • size (int) – An integer that represent the length along one dimension of the kernel.

  • padding – The padding type that will be used to produce the convolution

Returns:

None

convolve(images: ndarray, orthogonal_rot: bool = False) ndarray[source]

Filter a given image using the LoG kernel defined during the construction of this instance.

Parameters:
  • images (ndarray) – A n-dimensional numpy array that represent the images to filter

  • orthogonal_rot (bool, optional) – If true, the 3D images will be rotated over coronal, axial and sagittal axis

Returns:

The filtered image

Return type:

ndarray

create_kernel()[source]

This method construct the mean kernel using the parameters specified to the constructor.

Returns:

The mean kernel as a numpy multidimensional array

Return type:

ndarray

MEDimage.filters.mean.apply_mean(input_images: ndarray | image_volume_obj, medscan: MEDscan | None = None, ndims: int = 3, size: int = 15, padding: str = 'symmetric', orthogonal_rot: bool = False) ndarray[source]

Apply the mean filter to the input image

Parameters:
  • input_images (ndarray) – The images to filter.

  • medscan (MEDscan, optional) – The MEDscan object that will provide the filter parameters.

  • ndims (int, optional) – The number of dimensions of the input image.

  • size (int, optional) – The size of the kernel.

  • padding (str, optional) – The padding type that will be used to produce the convolution. Check options here: numpy.pad.

  • orthogonal_rot (bool, optional) – If true, the 3D images will be rotated over coronal, axial and sagittal axis.

Returns:

The filtered image.

Return type:

ndarray

wavelet

class MEDimage.filters.wavelet.Wavelet(ndims: int, wavelet_name='haar', padding='symmetric', rot_invariance=False)[source]

Bases: object

The wavelet filter class.

__init__(ndims: int, wavelet_name='haar', padding='symmetric', rot_invariance=False)[source]

The constructor of the wavelet filter

Parameters:
  • ndims (int) – The number of dimension of the images that will be filter as int.

  • wavelet_name (str) – The name of the wavelet kernel as string.

  • padding (str) – The padding type that will be used to produce the convolution

  • rot_invariance (bool) – If true, rotation invariance will be done on the images.

Returns:

None

_pad_imgs(images: ndarray, padding, axis: List)[source]

Apply padding on a 3d images using a 2D padding pattern (special for wavelet).

Parameters:
  • images – a numpy array that represent the image.

  • padding – The padding length that will apply on each side of each axe.

  • axis – A list of axes on which the padding will be done.

Returns:

A numpy array that represent the padded image.

Return type:

ndarray

convolve(images: ndarray, _filter='LHL', level=1) ndarray[source]

Filter a given batch of images using pywavelet.

Parameters:
  • images (ndarray) – A n-dimensional numpy array that represent the images to filter

  • _filter (str) – The filter to uses.

  • level (int) – The number of decomposition steps to perform.

Returns:

The filtered image as numpy nd-array

Return type:

ndarray

create_kernel(wavelet_name: str)[source]

Get the wavelet object and his kernel length.

Parameters:

wavelet_name (str) – A string that represent the wavelet name that will be use to create the kernel

Returns:

None

MEDimage.filters.wavelet.apply_wavelet(input_images: ndarray | image_volume_obj, medscan: MEDscan | None = None, ndims: int = 3, wavelet_name: str = 'haar', subband: str = 'LHL', level: int = 1, padding: str = 'symmetric', rot_invariance: bool = False) ndarray[source]

Apply the mean filter to the input image

Parameters:
  • input_images (ndarray) – The image to filter.

  • medscan (MEDscan, optional) – The MEDscan object that will provide the filter parameters.

  • ndims (int, optional) – The number of dimensions of the input image.

  • wavelet_name (str) – The name of the wavelet kernel as string.

  • level (List[str], optional) – The number of decompositions steps to perform.

  • subband (str, optional) – String of the 1D wavelet kernels (“H” for high-pass filter or “L” for low-pass filter). Must have a size of ndims.

  • padding (str, optional) – The padding type that will be used to produce the convolution. Check options here: numpy.pad.

  • rot_invariance (bool, optional) – If true, rotation invariance will be done on the kernel.

Returns:

The filtered image.

Return type:

ndarray

apply_filter

MEDimage.filters.apply_filter.apply_filter(medscan: MEDscan, vol_obj: image_volume_obj | ndarray, user_set_min_val: float | None = None, feature: str | None = None) image_volume_obj | ndarray[source]

Applies mean filter on the given data

Parameters:
  • medscan (MEDscan) – Instance of the MEDscan class that holds the filtering params

  • vol_obj (image_volume_obj) – Imaging data to be filtered

  • user_set_min_val (float, optional) – The minimum value to use for the discretization. Defaults to None.

  • feature (str, optional) – The feature to extract from the family. In batch extraction, all the features of the family will be extracted. Defaults to None.

Returns:

Filtered imaging data.

Return type:

image_volume_obj

utils

MEDimage.filters.utils.convolve(dim: int, kernel: ndarray, images: ndarray, orthogonal_rot: bool = False, mode: str = 'symmetric') ndarray[source]

Convolve a given n-dimensional array with the kernel to generate a filtered image.

Parameters:
  • dim (int) – The dimension of the images.

  • kernel (ndarray) – The kernel to use for the convolution.

  • images (ndarray) – A n-dimensional numpy array that represent a batch of images to filter.

  • orthogonal_rot (bool, optional) – If true, the 3D images will be rotated over coronal, axial and sagittal axis.

  • mode (str, optional) – The padding mode. Check options here: numpy.pad.

Returns:

The filtered image.

Return type:

ndarray

MEDimage.filters.utils.pad_imgs(images: ndarray, padding_length: List, axis: List, mode: str) ndarray[source]

Apply padding on a 3d images using a 2D padding pattern.

Parameters:
  • images (ndarray) – a numpy array that represent the image.

  • padding_length (List) – The padding length that will apply on each side of each axe.

  • axis (List) – A list of axes on which the padding will be done.

  • mode (str) – The padding mode. Check options here: numpy.pad.

Returns:

A numpy array that represent the padded image.

Return type:

ndarray