visumorph

Submodules

Package Contents

Classes

Image

The main class for VisuMorph Image objects.

Functions

load_image(image_path)

Load an image from filesystem and return an Image object.

rotate

change_hue

scale(image, scale)

Enlarge/Shrink an image with a given scale.

flip(image[, v])

Flip image vertically or horizontally.

Attributes

__version__

visumorph.__version__
class visumorph.Image(image)[source]

The main class for VisuMorph Image objects.

get_dimensions()[source]
save(file_path)[source]

Saves the image to a file.

Parameters:

file_path (str) – The path where the image should be saved.

__repr__()[source]

Return repr(self).

__self_inject(func)

Wrapper method to self-inject into visumorph functions.

flip(*args, **kwargs)[source]

Flip image vertically or horizontally.

Parameters:

v (int, optional) – Flip vertically if v=1, horizontally if v=0. By default, v=0.

Returns:

Flipped VisuMorph image.

Return type:

image

Raises:

TypeError – If the image is not a valid VisuMorph Image and/or v is not 0 or 1.

Examples

>>> import visumorph
>>> from visumorph.flip import flip
>>> img = visumorph.load_image("exampleimage.jpg")
>>> img.flip(v=1)
rotate(*args, **kwargs)[source]

Rotate an image with a given rotation.

This method will rotate a VisuMorph image by a given degree of rotation. A background image can be specified for filling any empty spaces which are not covered by the image after rotation.

Parameters:
  • rotation (float) – The desired rotation angle in degrees. +ve means clockwise while -ve means counter-clockwise.

  • background (visumorph.Image, optional) – The background image to be filled in where the rotated image is not covered. Default is None, which a black background image would be used.

Returns:

The VisuMorph Image after rotation.

Return type:

image

Raises:

TypeError – If the image is not a valid VisuMorph Image and/or rotation given is not a number.

Examples

>>> import visumorph as vm
>>> img = vm.load_image("test.jpg")
>>> rotated_45_img = img.rotate(img, 45.0)
scale(*args, **kwargs)[source]

Enlarge/Shrink an image with a given scale.

This method will scale a VisuMorph image by a given scale with 1.0 as the original scale. The final transformed image would have a dimension of (scale * original_width, scale * original_height), rounded top to the nearest integer.

Parameters:

scale (float or int) – The desired scale. The original scale of the image is 1.0. A scale larger than 1.0 will result in a final image having a larger dimension, and vice versa. Cannot be equal or smaller than 0.0.

Returns:

The VisuMorph Image scaled.

Return type:

image

Raises:
  • TypeError – If the image is not a valid VisuMorph Image and/or scale given is not a number.

  • ValueError – If the scale provided is equal 0 or is a negative number.

Examples

>>> import visumorph as vm
>>> img = vm.load_image("test.jpg")
>>> scaled_img = img.scale(img, 1.15)
change_hue(*args, **kwargs)[source]

Change the hue of a VisuMorph Image object by blending it with a layer of specified color.

Parameters:
  • color (str, optional) – The color used for the blending layer (default is “white”).

  • delta_hue (float or int, optional) – The degree of blending with the color layer. A value of 0 means no change, and 1 means complete replacement with the color layer (default is 1).

Returns:

Image – A new VisuMorph Image object with the modified hue.

Return type:

visumorph.Image

Raises:
  • TypeError – If the input is not a valid VisuMorph Image object.

  • ValueError – If ‘delta_hue’ is not a number.

Examples

>>> import visumorph as vm
>>> img = vm.load_image("test.jpg")
>>> hue_changed = img.change_hue(img)
visumorph.load_image(image_path)[source]

Load an image from filesystem and return an Image object.

Parameters:

image_path (str) – The path to the image file to be read.

Returns:

The VisuMorph Image object with image data loaded in.

Return type:

image

visumorph.rotate(image, rotation, background=None)[source]

Rotate an image with a given rotation.

This function will rotate a VisuMorph image by a given degree of rotation. A background image can be specified for filling any empty spaces which are not covered by the image after rotation.

Parameters:
  • image (visumorph.Image) – The original image to be rotated.

  • rotation (float) – The desired rotation angle in degrees. +ve means clockwise while -ve means counter-clockwise.

  • background (visumorph.Image, optional) – The background image to be filled in where the rotated image is not covered. Default is None, which a black background image would be used.

Returns:

The VisuMorph Image after rotation.

Return type:

image

Raises:

TypeError – If the image is not a valid VisuMorph Image and/or rotation given is not a number.

Examples

>>> import visumorph as vm
>>> img = vm.load_image("test.jpg")
>>> rotated_45_img = vm.rotate(img, 45.0)
visumorph.change_hue(image, color='white', delta_hue=1)[source]

Change the hue of a VisuMorph Image object by blending it with a layer of specified color.

Parameters:
  • image (visumorph.Image) – A VisuMorph Image object whose hue is to be changed.

  • color (str, optional) – The color used for the blending layer (default is “white”).

  • delta_hue (float or int, optional) – The degree of blending with the color layer. A value of 0 means no change, and 1 means complete replacement with the color layer (default is 1).

Returns:

Image – A new VisuMorph Image object with the modified hue.

Return type:

visumorph.Image

Raises:
  • TypeError – If the input is not a valid VisuMorph Image object.

  • ValueError – If ‘delta_hue’ is not a number.

Examples

>>> import visumorph as vm
>>> img = vm.load_image("test.jpg")
>>> hue_changed = vm.change_hue(img)
visumorph.scale(image, scale)[source]

Enlarge/Shrink an image with a given scale.

This function will scale a VisuMorph image by a given scale with 1.0 as the original scale. The final transformed image would have a dimension of (scale * original_width, scale * original_height), rounded top to the nearest integer.

Parameters:
  • image (visumorph.Image) – The original image to be scaled.

  • scale (float or int) – The desired scale. The original scale of the image is 1.0. A scale larger than 1.0 will result in a final image having a larger dimension, and vice versa. Cannot be equal or smaller than 0.0.

Returns:

The VisuMorph Image scaled.

Return type:

image

Raises:
  • TypeError – If the image is not a valid VisuMorph Image and/or scale given is not a number.

  • ValueError – If the scale provided is equal 0 or is a negative number.

Examples

>>> import visumorph as vm
>>> img = vm.load_image("test.jpg")
>>> scaled_img = vm.scale(img, 1.15)
visumorph.flip(image, v=0)[source]

Flip image vertically or horizontally.

Parameters:
  • image (visumorph.Image) – Image to be flipped.

  • v (int, optional) – Flip vertically if v=1, horizontally if v=0. By default, v=0.

Returns:

Flipped VisuMorph image.

Return type:

image

Raises:

TypeError – If the image is not a valid VisuMorph Image and/or v is not 0 or 1.

Examples

>>> import visumorph
>>> from visumorph.flip import flip
>>> img = visumorph.load_image("exampleimage.jpg")
>>> flip(img, v=1)