colour_checker_detection.detection.transform_image#

colour_checker_detection.detection.transform_image(image, translation=np.array([0, 0]), rotation=0, scale=np.array([1, 1]), interpolation_method: Literal[cv2.INTER_AREA, cv2.INTER_CUBIC, cv2.INTER_LANCZOS4, cv2.INTER_LINEAR, cv2.INTER_LINEAR_EXACT, cv2.INTER_MAX, cv2.INTER_NEAREST, cv2.INTER_NEAREST_EXACT, cv2.WARP_FILL_OUTLIERS, cv2.WARP_INVERSE_MAP] = cv2.INTER_CUBIC) NDArrayInt | NDArrayFloat[source]#

Transform given image using given translation, rotation and scale values.

The transformation is performed relatively to the image center and in the following order:

  1. Scale

  2. Rotation

  3. Translation

Parameters:
  • image – Image to transform.

  • translation – Translation value.

  • rotation – Rotation value in degrees.

  • scale – Scale value.

  • interpolation_method (Literal[cv2.INTER_AREA, cv2.INTER_CUBIC, cv2.INTER_LANCZOS4, cv2.INTER_LINEAR, cv2.INTER_LINEAR_EXACT, cv2.INTER_MAX, cv2.INTER_NEAREST, cv2.INTER_NEAREST_EXACT, cv2.WARP_FILL_OUTLIERS, cv2.WARP_INVERSE_MAP]) – Interpolation method.

Returns:

Transformed image.

Return type:

numpy.ndarray

Examples

>>> image = np.reshape(np.arange(24), (2, 4, 3))
>>> image  
array([[[ 0,  1,  2],
        [ 3,  4,  5],
        [ 6,  7,  8],
        [ 9, 10, 11]],

       [[12, 13, 14],
        [15, 16, 17],
        [18, 19, 20],
        [21, 22, 23]]]...)

# NOTE: Need to use cv2.INTER_NEAREST for integer images.

>>> transform_image(
...     image, translation=np.array([1, 0]), interpolation_method=cv2.INTER_NEAREST
... )  
array([[[ 0,  1,  2],
        [ 0,  1,  2],
        [ 3,  4,  5],
        [ 6,  7,  8]],

       [[12, 13, 14],
        [12, 13, 14],
        [15, 16, 17],
        [18, 19, 20]]]...)
>>> transform_image(
...     image, rotation=90, interpolation_method=cv2.INTER_NEAREST
... )  
array([[[15, 16, 17],
        [15, 16, 17],
        [15, 16, 17],
        [ 3,  4,  5]],

       [[18, 19, 20],
        [18, 19, 20],
        [18, 19, 20],
        [ 6,  7,  8]]]...)
>>> transform_image(
...     image, scale=np.array([2, 0.5]), interpolation_method=cv2.INTER_NEAREST
... )  
array([[[ 3,  4,  5],
        [ 6,  7,  8],
        [ 6,  7,  8],
        [ 9, 10, 11]],

       [[15, 16, 17],
        [18, 19, 20],
        [18, 19, 20],
        [21, 22, 23]]]...)