sharpedge.reposition_image

Functions

_flip_image(img, flip)

Flips the image based on the specified flip parameter.

_rotate_image(img, rotate)

Rotates the image based on the specified rotate parameter.

_shift_image_x(img, shift_x)

Shifts the image along the x-axis.

_shift_image_y(img, shift_y)

Shifts the image along the y-axis.

reposition_image(img[, flip, rotate, shift_x, shift_y])

Flip, rotate, and shift an image based on the specified requested action.

Module Contents

sharpedge.reposition_image._flip_image(img, flip)[source]

Flips the image based on the specified flip parameter. Private function to be invoked by reposition_image()

sharpedge.reposition_image._rotate_image(img, rotate)[source]

Rotates the image based on the specified rotate parameter. Private function to be invoked by reposition_image()

sharpedge.reposition_image._shift_image_x(img, shift_x)[source]

Shifts the image along the x-axis. Private function to be invoked by reposition_image()

sharpedge.reposition_image._shift_image_y(img, shift_y)[source]

Shifts the image along the y-axis. Private function to be invoked by reposition_image()

sharpedge.reposition_image.reposition_image(img, flip='none', rotate='up', shift_x=0, shift_y=0)[source]

Flip, rotate, and shift an image based on the specified requested action.

This function allows repositioning of an image by applying one or more transformations (flipping, rotating, and shifting). Each transformation can be controlled by the respective parameters.

Parameters:
  • img (numpy.ndarray) – The input image as a 2D numpy array (grayscale) or 3D numpy array (RGB).

  • flip (str, optional) – Argument used to flip the image. It can be - ‘none’: No flipping. - ‘horizontal’: Flip the image horizontally. - ‘vertical’: Flip the image vertically. - ‘both’: Flip the image both horizontally and vertically. Default is ‘none’.

  • rotate (str, optional) – Argument used to rotate the image. It can be - ‘up’: No rotation. - ‘left’: Rotate the image 90 degrees counter-clockwise. - ‘right’: Rotate the image 90 degrees clockwise. - ‘down’: Rotate the image 180 degrees (flip upside down). Default is ‘up’.

  • shift_x (int, optional) – Argument used to shift the image along the x-axis. Default is 0.

  • shift_y (int, optional) – Argument used to shift the image along the y-axis. Default is 0.

Returns:

The repositioned image that has been flipped, rotated, and/or shifted based on the parameter values.

Return type:

numpy.ndarray

Raises:
  • ValueError

    • If the input image is not a 2D or 3D numpy array.

    • or if the flip or rotate arguments are invalid.

  • TypeError – If shift_x or shift_y is not an integer.

Warning

UserWarning
  • If the shift values are larger than the image dimensions.

  • If resizing causes unexpected behavior due to large shifts.

Examples

>>> img = np.random.rand(100, 100)
>>> repositioned_img = reposition_image(img, flip='horizontal', rotate='left', shift_x=10, shift_y=20)

For an RGB image: >>> img_rgb = np.random.rand(100, 100, 3) >>> repositioned_img = reposition_image(img_rgb, flip=’both’, rotate=’down’, shift_x=-5, shift_y=10)