Skip to content

Image

[source]

resize_image

paz.backend.image.opencv_image.resize_image(image, size, method=1)

Resize image.

Arguments

  • image: Numpy array.
  • size: List of two ints.
  • method: Flag indicating interpolation method i.e. paz.backend.image.CUBIC

Returns

Numpy array.


[source]

convert_color_space

paz.backend.image.opencv_image.convert_color_space(image, flag)

Convert image to a different color space.

Arguments

  • image: Numpy array.
  • flag: PAZ or openCV flag. e.g. paz.backend.image.RGB2BGR.

Returns

Numpy array.


[source]

load_image

paz.backend.image.opencv_image.load_image(filepath, num_channels=3)

Load image from a ''filepath''.

Arguments

  • filepath: String indicating full path to the image.
  • num_channels: Int.

Returns

Numpy array.


[source]

show_image

paz.backend.image.opencv_image.show_image(image, name='image', wait=True)

Shows RGB image in an external window.

Arguments

  • image: Numpy array
  • name: String indicating the window name.
  • wait: Boolean. If ''True'' window stays open until user presses a key. If ''False'' windows closes immediately.

[source]

warp_affine

paz.backend.image.opencv_image.warp_affine(image, matrix, fill_color=[0, 0, 0], size=None)

Transforms image using an affine matrix transformation.

Arguments

  • image: Numpy array.
  • matrix: Numpy array of shape (2,3) indicating affine transformation.
  • fill_color: List/tuple representing BGR use for filling empty space.

[source]

write_image

paz.backend.image.opencv_image.write_image(filepath, image)

Writes an image inside filepath. If filepath doesn't exist it makes a directory. If image has three channels the image is converted into BGR and then written. This is done such that this function compatible with load_image.

Arguments

  • filepath: String with image path. It should include postfix e.g. .png
  • image: Numpy array.

[source]

gaussian_image_blur

paz.backend.image.opencv_image.gaussian_image_blur(image, kernel_size=(5, 5))

Applies Gaussian blur to an image.

Arguments

  • image: Numpy array of shape ''(H, W, 4)''.
  • kernel_size: List of two ints e.g. ''(5, 5)''.

Returns

Numpy array


[source]

median_image_blur

paz.backend.image.opencv_image.median_image_blur(image, apperture=5)

Applies median blur to an image.

Arguments

  • image: Numpy array of shape ''(H, W, 3)''.

apperture. Int.

Returns

Numpy array.


[source]

get_rotation_matrix

paz.backend.image.opencv_image.get_rotation_matrix(center, degrees, scale=1.0)

Returns a 2D rotation matrix.

Arguments

  • center: List of two integer values.
  • degrees: Float indicating the angle in degrees.

Returns

Numpy array


[source]

cast_image

paz.backend.image.image.cast_image(image, dtype)

Casts an image into a different type

Arguments

  • image: Numpy array.
  • dtype: String or np.dtype.

Returns

Numpy array.


[source]

random_saturation

paz.backend.image.image.random_saturation(image, lower=0.3, upper=1.5)

Applies random saturation to an RGB image.

Arguments

  • image: Numpy array representing an image RGB format.
  • lower: Float.
  • upper: Float.

[source]

random_brightness

paz.backend.image.image.random_brightness(image, delta=32)

Applies random brightness to an RGB image.

Arguments

  • image: Numpy array representing an image RGB format.
  • delta: Int.

[source]

random_contrast

paz.backend.image.image.random_contrast(image, lower=0.5, upper=1.5)

Applies random contrast to an RGB image.

Arguments

  • image: Numpy array representing an image RGB format.
  • lower: Float.
  • upper: Float.

[source]

random_hue

paz.backend.image.image.random_hue(image, delta=18)

Applies random hue to an RGB image.

Arguments

  • image: Numpy array representing an image RGB format.
  • delta: Int.

[source]

flip_left_right

paz.backend.image.image.flip_left_right(image)

Flips an image left and right.

Arguments

  • image: Numpy array.

[source]

random_flip_left_right

paz.backend.image.image.random_flip_left_right(image)

Applies random left or right flip.

Arguments

  • image: Numpy array.

[source]

crop_image

paz.backend.image.image.crop_image(image, crop_box)

Resize image.

Arguments

  • image: Numpy array.
  • crop_box: List of four ints.

Returns

Numpy array.


[source]

image_to_normalized_device_coordinates

paz.backend.image.image.image_to_normalized_device_coordinates(image)

Map image value from [0, 255] -> [-1, 1].


[source]

normalized_device_coordinates_to_image

paz.backend.image.image.normalized_device_coordinates_to_image(image)

Map normalized value from [-1, 1] -> [0, 255].


[source]

random_shape_crop

paz.backend.image.image.random_shape_crop(image, shape)

Randomly crops an image of the given shape.

Arguments

  • image: Numpy array.
  • shape: List of two ints ''(H, W)''.

Returns

Numpy array of cropped image.


[source]

make_random_plain_image

paz.backend.image.image.make_random_plain_image(shape)

Makes random plain image by sampling three random values.

Arguments

  • shape: Image shape e.g. ''(H, W, 3)''.

Returns

Numpy array of shape ''(H, W, 3)''.


[source]

blend_alpha_channel

paz.backend.image.image.blend_alpha_channel(image, background)

Blends image with background using an alpha channel.

Arguments

  • image: Numpy array with alpha channel. Shape must be ''(H, W, 4)''
  • background: Numpy array of shape ''(H, W, 3)''.

[source]

concatenate_alpha_mask

paz.backend.image.image.concatenate_alpha_mask(image, alpha_mask)

Concatenates alpha mask to image.

Arguments

  • image: Numpy array of shape ''(H, W, 3)''.
  • alpha_mask: Numpy array array of shape ''(H, W)''.

Returns

Numpy array of shape ''(H, W, 4)''.


[source]

split_and_normalize_alpha_channel

paz.backend.image.image.split_and_normalize_alpha_channel(image)

Splits alpha channel from an RGBA image and normalizes alpha channel.

Arguments

  • image: Numpy array of shape ''(H, W, 4)''.

Returns

List of two numpy arrays containing respectively the image and the alpha channel.


[source]

random_image_blur

paz.backend.image.image.random_image_blur(image)

Applies random choice blur.

Arguments

  • image: Numpy array of shape ''(H, W, 3)''.

Returns

Numpy array.


[source]

translate_image

paz.backend.image.image.translate_image(image, translation, fill_color)

Translate image.

Arguments

  • image: Numpy array.
  • translation: A list of length two indicating the x,y translation values
  • fill_color: List of three floats representing a color.

Returns

Numpy array


[source]

sample_scaled_translation

paz.backend.image.image.sample_scaled_translation(delta_scale, image_shape)

Samples a scaled translation from a uniform distribution.

Arguments

  • delta_scale: List with two elements having the normalized deltas. e.g. ''[.25, .25]''.
  • image_shape: List containing the height and width of the image.

[source]

replace_lower_than_threshold

paz.backend.image.image.replace_lower_than_threshold(source, threshold=0.001, replacement=0.0)

Replace values from source that are lower than the given threshold. This function doesn't create a new array but does replacement in place.

Arguments

  • source: Array.
  • threshold: Float. Values lower than this value will be replaced.
  • replacement: Float. Value taken by elements lower than threshold.

Returns

Array of same shape as source.


[source]

normalize_min_max

paz.backend.image.image.normalize_min_max(x, x_min, x_max)

Normalized data using it's maximum and minimum values

Arguments

  • x: array
  • x_min: minimum value of x
  • x_max: maximum value of x

Returns

min-max normalized data


[source]

sample_scaled_translation

paz.backend.image.image.sample_scaled_translation(delta_scale, image_shape)

Samples a scaled translation from a uniform distribution.

Arguments

  • delta_scale: List with two elements having the normalized deltas. e.g. ''[.25, .25]''.
  • image_shape: List containing the height and width of the image.

[source]

get_rotation_matrix

paz.backend.image.opencv_image.get_rotation_matrix(center, degrees, scale=1.0)

Returns a 2D rotation matrix.

Arguments

  • center: List of two integer values.
  • degrees: Float indicating the angle in degrees.

Returns

Numpy array


[source]

calculate_image_center

paz.backend.image.image.calculate_image_center(image)

Return image center.

Arguments

  • image: Numpy array.

Returns

image center.


[source]

get_affine_transform

paz.backend.image.opencv_image.get_affine_transform(source_points, destination_points)

Return the transformation matrix.

Arguments

  • source_points: Numpy array.
  • destination_points: Numpy array.

Returns

Transformation matrix.


[source]

get_scaling_factor

paz.backend.image.image.get_scaling_factor(image, scale=1, shape=(128, 128))

Return scaling factor for the image.

Arguments

  • image: Numpy array.
  • scale: Int.
  • shape: Tuple of integers. eg. (128, 128)

Returns

scaling factor: Numpy array of size 2


[source]

scale_resize

paz.backend.image.image.scale_resize(image, image_size)

Resizes and crops image by returning the scales to original image.

Args: image: Numpy array, raw image. image_size: Int, size of the image.

Returns: Tuple: output_image, image_scale.