ida_lib.operations package

Submodules

ida_lib.operations.geometry_ops_functional module

ida_lib.operations.geometry_ops_functional.affine_compose_data(data: dict, matrix: None._VariableFunctionsClass.tensor) → dict
Parameters
  • data – dict of elements to be transformed

  • matrix – matrix of transformation

Returns

transformed data

ida_lib.operations.geometry_ops_functional.affine_coordinates_matrix(matrix_coordinates: None._VariableFunctionsClass.tensor, matrix_transformation: None._VariableFunctionsClass.tensor) → None._VariableFunctionsClass.tensor
ida_lib.operations.geometry_ops_functional.affine_image(img: None._VariableFunctionsClass.tensor, matrix: None._VariableFunctionsClass.tensor, interpolation: str = 'bilinear', padding_mode: str = 'zeros') → None._VariableFunctionsClass.tensor
ida_lib.operations.geometry_ops_functional.config_scale_matrix(scale_factor, center, matrix)
ida_lib.operations.geometry_ops_functional.get_rotation_matrix(center: None._VariableFunctionsClass.tensor, degrees: None._VariableFunctionsClass.tensor)
ida_lib.operations.geometry_ops_functional.get_scale_matrix(center: None._VariableFunctionsClass.tensor, scale_factor: Union[float, None._VariableFunctionsClass.tensor])
ida_lib.operations.geometry_ops_functional.get_shear_matrix(shear_factor: tuple) → None._VariableFunctionsClass.tensor
ida_lib.operations.geometry_ops_functional.get_squared_scale_matrix(center: None._VariableFunctionsClass.tensor, scale_factor: Union[float, None._VariableFunctionsClass.tensor])
ida_lib.operations.geometry_ops_functional.get_squared_shear_matrix(shear_factor: tuple) → None._VariableFunctionsClass.tensor
ida_lib.operations.geometry_ops_functional.get_translation_matrix(translation: None._VariableFunctionsClass.tensor) → None._VariableFunctionsClass.tensor
ida_lib.operations.geometry_ops_functional.hflip_compose_data(data: dict) → dict
Parameters

data – dict of elements to be transformed

Returns

transformed data

ida_lib.operations.geometry_ops_functional.hflip_coordinates_matrix(matrix: None._VariableFunctionsClass.tensor, width: int) → None._VariableFunctionsClass.tensor
ida_lib.operations.geometry_ops_functional.hflip_image(img: None._VariableFunctionsClass.tensor) → None._VariableFunctionsClass.tensor
ida_lib.operations.geometry_ops_functional.own_affine(tensor: torch.Tensor, matrix: torch.Tensor, interpolation: str = 'bilinear', padding_mode: str = 'border') → torch.Tensor

Apply an affine transformation to the image.

Parameters
  • tensor – The image tensor to be warped.

  • matrix – The 2x3 affine transformation matrix.

  • interpolation – interpolation mode to calculate output values ‘bilinear’ | ‘nearest’. Default: ‘bilinear’.

  • padding_mode – padding mode for outside grid values ‘zeros’ | ‘border’ | ‘reflection’. Default: ‘zeros’.

Returns

The warped image.

ida_lib.operations.geometry_ops_functional.prepare_data(func)

Decorator that prepares the input data to apply the geometric transformation. For this purpose, it concatenates all the two-dimensional elements of the input data in the same tensor on which a single transformation is applied. If the input data contains point coordinates, they are grouped in a matrix as homogeneous coordinates, over which a single matrix multiplication is performed.

Parameters

func – geometric function to be applied to the data

Returns

processed data

ida_lib.operations.geometry_ops_functional.rotate_compose_data(data: dict, degrees: None._VariableFunctionsClass.tensor, center: None._VariableFunctionsClass.tensor)
Parameters
  • data – dict of elements to be transformed

  • degrees – counterclockwise degrees of rotation

  • center – center of rotation. Default, center of the image

Returns

transformed data

ida_lib.operations.geometry_ops_functional.rotate_coordinates_matrix(matrix_coordinates: None._VariableFunctionsClass.tensor, matrix: None._VariableFunctionsClass.tensor) → None._VariableFunctionsClass.tensor
ida_lib.operations.geometry_ops_functional.rotate_image(img: None._VariableFunctionsClass.tensor, degrees: None._VariableFunctionsClass.tensor, center: None._VariableFunctionsClass.tensor) → None._VariableFunctionsClass.tensor

mode

ida_lib.operations.geometry_ops_functional.scale_compose_data(data: dict, scale_factor: Union[float, None._VariableFunctionsClass.tensor], center: Optional[None._VariableFunctionsClass.tensor] = None) → dict
Parameters
  • data – dict of elements to be transformed

  • scale_factor – factor of scaling

  • center – center of scaling. By default its taken the center of the image

Returns

transformed data

ida_lib.operations.geometry_ops_functional.scale_coordinates_matrix(matrix_coordinates: None._VariableFunctionsClass.tensor, matrix: None._VariableFunctionsClass.tensor) → None._VariableFunctionsClass.tensor
ida_lib.operations.geometry_ops_functional.scale_image(img: None._VariableFunctionsClass.tensor, scale_factor: None._VariableFunctionsClass.tensor, center: None._VariableFunctionsClass.tensor) → None._VariableFunctionsClass.tensor
ida_lib.operations.geometry_ops_functional.shear_compose_data(data: dict, shear_factor: tuple) → dict
Parameters
  • data – dict of elements to be transformed

  • shear_factor – pixels of shearing

Returns

transformed data

ida_lib.operations.geometry_ops_functional.shear_coordinates_matrix(matrix_coordinates: None._VariableFunctionsClass.tensor, matrix: None._VariableFunctionsClass.tensor) → None._VariableFunctionsClass.tensor
ida_lib.operations.geometry_ops_functional.shear_image(img: None._VariableFunctionsClass.tensor, shear_factor: None._VariableFunctionsClass.tensor) → None._VariableFunctionsClass.tensor
ida_lib.operations.geometry_ops_functional.translate_compose_data(data: dict, translation: Union[int, None._VariableFunctionsClass.tensor]) → dict
Parameters
  • data – dict of elements to be transformed

  • translation – number of pixels to translate

Returns

transformed data

ida_lib.operations.geometry_ops_functional.translate_coordinates_matrix(matrix_coordinates: None._VariableFunctionsClass.tensor, translation: None._VariableFunctionsClass.tensor) → None._VariableFunctionsClass.tensor
ida_lib.operations.geometry_ops_functional.translate_image(img: None._VariableFunctionsClass.tensor, translation: None._VariableFunctionsClass.tensor) → None._VariableFunctionsClass.tensor
ida_lib.operations.geometry_ops_functional.vflip_compose_data(data: dict) → dict
Parameters

data – dict of elements to be transformed

Returns

transformed data

ida_lib.operations.geometry_ops_functional.vflip_coordinates_matrix(matrix: None._VariableFunctionsClass.tensor, height: int) → None._VariableFunctionsClass.tensor
ida_lib.operations.geometry_ops_functional.vflip_image(img: None._VariableFunctionsClass.tensor) → None._VariableFunctionsClass.tensor

ida_lib.operations.pixel_ops_functional module

ida_lib.operations.pixel_ops_functional.apply_blur(img, blur_size=5, 5)
ida_lib.operations.pixel_ops_functional.apply_gaussian_blur(img, blur_size=5, 5)
Parameters
  • img – input image to be transformed

  • blur_size – number of surrounding pixels affecting each output pixel. (pixels on axis X, pixels on axis y)

Returns

returns the transformed image

ida_lib.operations.pixel_ops_functional.apply_gaussian_noise(image, var=20)
ida_lib.operations.pixel_ops_functional.apply_lut_by_pixel_function(function, image: numpy.ndarray) → numpy.ndarray

Applies the input operation to the image using a LUT

Parameters
  • function – Mathematical function that represents the operation to carry out in each pixel of the image

  • image – input image

Returns

ida_lib.operations.pixel_ops_functional.apply_poisson_noise(image)
ida_lib.operations.pixel_ops_functional.apply_salt_and_pepper_noise(image, amount=0.05, s_vs_p=0.5)
ida_lib.operations.pixel_ops_functional.apply_spekle_noise(image, mean=0, var=0.01)
ida_lib.operations.pixel_ops_functional.blur(img: Union[dict, None._VariableFunctionsClass.tensor, numpy.ndarray], blur_size) → Union[dict, None._VariableFunctionsClass.tensor, numpy.ndarray]
Parameters
  • img – input image to be transformed

  • blur_size – number of surrounding pixels affecting each output pixel. (pixels on axis X, pixels on axis y)

Returns

returns the transformed image

ida_lib.operations.pixel_ops_functional.change_brightness(image: Union[dict, None._VariableFunctionsClass.tensor, numpy.ndarray], brightness: int) → Union[dict, None._VariableFunctionsClass.tensor, numpy.ndarray]

Change the brightness of the input image.

Parameters
  • image – input image to be normalized

  • brightness – desired amount of brightness for the image 0 - no brightness 1 - same 2 - max brightness

Returns

transformed image

ida_lib.operations.pixel_ops_functional.change_contrast(image: Union[dict, None._VariableFunctionsClass.tensor, numpy.ndarray], contrast) → Union[dict, None._VariableFunctionsClass.tensor, numpy.ndarray]

:param image : input image to be transformed :param contrast: modification factor to be applied to the image contrast

  • 0 - total contrast removal

  • 1 - dont modify

  • >1 - augment contrast

Returns

returns the transformed image

ida_lib.operations.pixel_ops_functional.change_gamma(image: Union[dict, None._VariableFunctionsClass.tensor, numpy.ndarray], gamma: float) → Union[dict, None._VariableFunctionsClass.tensor, numpy.ndarray]
Parameters
  • image – input image to be transformed

  • gamma – desired factor gamma * gamma = 0 -> removes image luminance (black output image) * gamma = 1 -> remains unchanged * gamma > 1 -> increases luminance

Returns

returns the transformed image

ida_lib.operations.pixel_ops_functional.gaussian_blur(img: Union[dict, None._VariableFunctionsClass.tensor, numpy.ndarray], blur_size) → Union[dict, None._VariableFunctionsClass.tensor, numpy.ndarray]
Parameters
  • img – input image to be transformed

  • blur_size – number of surrounding pixels affecting each output pixel. (pixels on axis X, pixels on axis y)

Returns

returns the transformed image

ida_lib.operations.pixel_ops_functional.gaussian_noise(image: Union[dict, None._VariableFunctionsClass.tensor, numpy.ndarray], var=20) → Union[dict, None._VariableFunctionsClass.tensor, numpy.ndarray]
Parameters
  • image – input image to be transformed

  • var – var of the gaussian distribution of noise

Returns

returns the transformed image

ida_lib.operations.pixel_ops_functional.get_brightness_function(brightness: int)
Parameters

brightness – brightness factor

Returns

Return the lambda function of the brightness operation

ida_lib.operations.pixel_ops_functional.get_contrast_function(contrast: float)
Parameters

contrast – modification factor to be applied to the image contrast

Returns

Return the lambda function of the contrast operation

ida_lib.operations.pixel_ops_functional.get_gamma_function(gamma)
Parameters

gamma – desired factor gamma

Returns

Returns the lambda function of the gamma adjust operation

ida_lib.operations.pixel_ops_functional.histogram_equalization(img: Union[dict, None._VariableFunctionsClass.tensor, numpy.ndarray]) → Union[dict, None._VariableFunctionsClass.tensor, numpy.ndarray]
Parameters

img – input image to be transformed

Returns

returns the transformed image

ida_lib.operations.pixel_ops_functional.normalize_image(img: numpy.ndarray, norm_type: int = 32) → numpy.ndarray

Normalize the input image

Parameters
  • img – input image to be normalized

  • norm_type – opencv normalization type (‘ cv2.NORM_MINMAX’ |cv2.NORM_HAMMING |cv2.NORM_HAMMING2 |cv2.NORM_INF |cv2.NORM_RELATIVE …)

Returns

normalized image

ida_lib.operations.pixel_ops_functional.poisson_noise(image: Union[dict, None._VariableFunctionsClass.tensor, numpy.ndarray]) → Union[dict, None._VariableFunctionsClass.tensor, numpy.ndarray]
Parameters

image – input image to be transformed

Returns

returns the transformed image

ida_lib.operations.pixel_ops_functional.prepare_data_for_opencv(func)

Decorator that prepares the input data to apply the transformation that only affects the image (color). :param func: color function to be applied to the data :return: processed data

ida_lib.operations.pixel_ops_functional.salt_and_pepper_noise(image: Union[dict, None._VariableFunctionsClass.tensor, numpy.ndarray], amount, s_vs_p) → Union[dict, None._VariableFunctionsClass.tensor, numpy.ndarray]
Parameters
  • image – input image to be transformed

  • amount – percentage of image’s pixels to be occupied by noise

  • s_vs_p – percentage of salt respect total noise. Default same salt (white pixel) as pepper (black pixels)

Returns

returns the transformed image

ida_lib.operations.pixel_ops_functional.spekle_noise(image: Union[dict, None._VariableFunctionsClass.tensor, numpy.ndarray], mean=0, var=0.01) → Union[dict, None._VariableFunctionsClass.tensor, numpy.ndarray]
Parameters
  • image – input image to be transformed

  • mean – mean of noise distribution

  • var – variance of noise distribution

Returns

returns the transformed image

ida_lib.operations.transforms module

ida_lib.operations.transforms.hflip(data: dict, visualize: bool = False) → dict

Horizontally flip the input data.

Parameters
  • data – dict of elements to be transformed

  • visualize – if true it activates the display tool to debug the transformation

Returns

transformed data

ida_lib.operations.transforms.vflip(data: dict, visualize: bool = False) → dict

Vertically flip the input data.

Parameters
  • data – dict of elements to be transformed

  • visualize – if true it activates the display tool to debug the transformation

Returns

transformed data

ida_lib.operations.transforms.affine(data: dict, matrix: None._VariableFunctionsClass.tensor, visualize: bool = False) → dict

Applies affine transformation to the data

:param data dict of elements to be transformed :param matrix: matrix of transformation :param visualize: if true it activates the display tool to debug the transformation :return: transformed data

ida_lib.operations.transforms.rotate(data: dict, degrees: float, visualize: bool = False, center: Union[None, torch.Tensor] = None) → dict

Rotate each element of the input data by the indicated degrees counterclockwise

Parameters
  • data – dict of elements to be transformed

  • degrees – degrees of rotation

  • center – center of rotation. If center is None, it is taken the center of the image to apply the rotation

  • visualize – if true it activates the display tool to debug the transformation

Returns

transformed data

ida_lib.operations.transforms.shear(data: dict, shear_factor: tuple, visualize: bool = False) → dict

Shear input data by the input shear factor

Parameters
  • data – dict of elements to be transformed

  • shear_factor – pixels to shear

  • visualize – if true it activates the display tool to debug the transformation

Returns

transformed data

ida_lib.operations.transforms.scale(data: dict, scale_factor, visualize: bool = False, center: Union[None, torch.Tensor] = None) → dict

Scale each element of the input data by the input factor.

Parameters
  • data – dict of elements to be transformed

  • scale_factor – factor of scaling to be applied * scale_factor < 1 -> output image is smaller than input one * scale_factor = 1 -> output image is is the same as the input image * scale_factor = 2 -> each original pixel occupies 2 pixels in the output image

  • center – center of scaling. If center is None, it is taken the center of the image to apply the scale

  • visualize – if true it activates the display tool to debug the transformation

Returns

transformed data

ida_lib.operations.transforms.translate(data: dict, translation: tuple, visualize: bool = False) → dict

Translate input by the input translation.

Parameters
  • data – dict of elements to be transformed

  • translation – number of pixels to be translated

  • visualize – if true it activates the display tool to debug the transformation

Returns

transformed data

ida_lib.operations.transforms.change_gamma(data: Union[dict, torch.Tensor, numpy.ndarray], gamma, visualize: bool = False) → Union[dict, torch.Tensor, numpy.ndarray]

Adjust image’s gamma (luminance correction) . if the input data is a dictionary, only those corresponding

to an image are altered

Parameters
  • data – dict of elements to be transformed

  • gamma

    desired gamma factor (luminance of image)

    • gamma = 0 -> removes image luminance (black output image)

    • gamma = 1 -> remains unchanged

    • gamma > 1 -> increases luminance

  • visualize – if true it activates the display tool to debug the transformation

Returns

transformed data

ida_lib.operations.transforms.change_contrast(data: Union[dict, torch.Tensor, numpy.ndarray], contrast: float, visualize: bool = False) → Union[dict, torch.Tensor, numpy.ndarray]

Change the image contrast. if the input data is a dictionary, only those corresponding to an image are altered

Parameters
  • data – dict of elements to be transformed

  • contrast – desired contrast factor to the data * contrast = 0 -> removes image contrast (white output image) * contrast = 1 -> remains unchanged * contrast > 1 -> increases contrast

:param visualize : if true it activates the display tool to debug the transformation :return: transformed data

ida_lib.operations.transforms.change_brightness(data: Union[dict, torch.Tensor, numpy.ndarray], bright=1, visualize: bool = False) → Union[dict, torch.Tensor, numpy.ndarray]

Change the image brightness. if the input data is a dictionary, only those corresponding to an image are altered

Parameters
  • data – dict of elements to be transformed

  • bright

    desired brightness amount for the data

    • brightness = 0 -> removes image brightness (black output image)

    • brightness = 1 -> remains unchanged

    • brightness > 1 -> increases brightness

  • visualize – if true it activates the display tool to debug the transformation

Returns

transformed data

ida_lib.operations.transforms.equalize_histogram(data: Union[dict, torch.Tensor, numpy.ndarray], visualize: bool = False) → Union[dict, torch.Tensor, numpy.ndarray]

Equalize image histogram. if the input data is a dictionary, only those corresponding to an image are altered

Parameters
  • data – dict of elements to be transformed

  • visualize – if true it activates the display tool to debug the transformation

Returns

transformed data

ida_lib.operations.transforms.inject_gaussian_noise(data: Union[dict, torch.Tensor, numpy.ndarray], var=0.5, visualize: bool = False) → Union[dict, torch.Tensor, numpy.ndarray]

Inject gaussian noise. If the input data is a dictionary, only those corresponding to an image are altered

Parameters
  • data – dict of elements to be transformed

  • var – variance of the noise distribution

  • visualize – if true it activates the display tool to debug the transformation

Returns

transformed data

ida_lib.operations.transforms.inject_poisson_noise(data: Union[dict, torch.Tensor, numpy.ndarray], visualize: bool = False) → Union[dict, torch.Tensor, numpy.ndarray]

Inject poisson noise. if the input data is a dictionary, only those corresponding to an image are altered

Parameters
  • data – dict of elements to be transformed

  • visualize – if true it activates the display tool to debug the transformation

Returns

transformed data

ida_lib.operations.transforms.inject_spekle_noise(data: Union[dict, torch.Tensor, numpy.ndarray], mean=0, var=0.01, visualize: bool = False) → Union[dict, torch.Tensor, numpy.ndarray]

Inject poisson noise. if the input data is a dictionary, only those corresponding to an image are altered

Parameters
  • data – dict of elements to be transformed

  • mean – mean of noise distribution

  • var – variance of noise distribution

  • visualize – if true it activates the display tool to debug the transformation

Returns

transformed data

ida_lib.operations.transforms.inject_salt_and_pepper_noise(data: Union[dict, torch.Tensor, numpy.ndarray], amount=0.05, s_vs_p=0.5, visualize: bool = False) → Union[dict, torch.Tensor, numpy.ndarray]

Inject salt and pepper noise if the input data is a dictionary, only those corresponding to an image are altered

Parameters
  • data – dict of elements to be transformed

  • amount – percentage of image’s pixels to be occupied by noise

:param s_vs_p : noise type distribution. Default same salt (white pixel) as pepper (black pixels) :param visualize: if true it activates the display tool to debug the transformation :return: transformed data

ida_lib.operations.transforms.blur(data: Union[dict, torch.Tensor, numpy.ndarray], blur_size=5, 5, visualize: bool = False) → Union[dict, torch.Tensor, numpy.ndarray]

Blur image. if the input data is a dictionary, only those corresponding to an image are altered

Parameters
  • data – dict of elements to be transformed

  • blur_size – number of surrounding pixels affecting each output pixel. (pixels on axis X, pixels on axis y)

  • visualize – if true it activates the display tool to debug the transformation

Returns

transformed data

ida_lib.operations.transforms.gaussian_blur(data: Union[dict, torch.Tensor, numpy.ndarray], blur_size=5, 5, visualize: bool = False) → Union[dict, torch.Tensor, numpy.ndarray]

Blurring an image by a Gaussian function. if the input data is a dictionary, only those corresponding to an image are altered

Parameters
  • data – dict of elements to be transformed

  • blur_size – number of surrounding pixels affecting each output pixel. (pixels on axis X, pixels on axis y)

  • visualize – if true it activates the display tool to debug the transformation

Returns

transformed data

ida_lib.operations.utils module

ida_lib.operations.utils.add_new_axis(arr: numpy.ndarray)
ida_lib.operations.utils.arrays_equal(arr1, arr2)
ida_lib.operations.utils.data_to_numpy(data)
ida_lib.operations.utils.dtype_to_torch_type(im_type: numpy.dtype)

Maps the numpy type to the equivalent torch.type

Parameters

im_type – numpy type

Returns

torch.type

ida_lib.operations.utils.element_to_dict_csv_format(item, name)
ida_lib.operations.utils.get_principal_type(data: dict)
ida_lib.operations.utils.get_torch_image_center(data)
ida_lib.operations.utils.homogeneous_points_to_list(keypoints)
ida_lib.operations.utils.homogeneous_points_to_matrix(keypoints)
ida_lib.operations.utils.is_a_normalized_image(image)
ida_lib.operations.utils.is_numpy_data(data)
ida_lib.operations.utils.keypoints_to_homogeneous_and_concatenate(keypoints, resize_factor=None)
ida_lib.operations.utils.keypoints_to_homogeneous_functional(keypoints)
ida_lib.operations.utils.map_value(x, in_min, in_max, out_min, out_max)
ida_lib.operations.utils.mask_change_to_01_functional(mask)
ida_lib.operations.utils.remove_digits(label: str)
ida_lib.operations.utils.round_torch(arr: None._VariableFunctionsClass.tensor, n_digits: int = 3)
ida_lib.operations.utils.save_im(tensor, title)

Module contents