colour_checker_detection.detection.reformat_image#

colour_checker_detection.detection.reformat_image(image: ArrayLike, target_width: int, 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]#

Reformat given image so that it is horizontal and resizes it to given target width.

Parameters:
  • image (ArrayLike) – Image to reformat.

  • target_width (int) – Width the image is resized to.

  • 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:

Reformatted 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_EXACT or cv2.INTER_LINEAR_EXACT # for integer images.

>>> reformat_image(image, 6, interpolation_method=cv2.INTER_LINEAR_EXACT)
... 
array([[[ 0,  1,  2],
        [ 2,  3,  4],
        [ 4,  5,  6],
        [ 5,  6,  7],
        [ 8,  9, 10],
        [ 9, 10, 11]],

       [[ 6,  7,  8],
        [ 8,  9, 10],
        [10, 11, 12],
        [12, 13, 14],
        [14, 15, 16],
        [15, 16, 17]],

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