kaishi.image.file

Definition for image files.

Module Contents

kaishi.image.file.THUMBNAIL_SIZE = [64, 64]
kaishi.image.file.MAX_DIM_FOR_SMALL = 224
kaishi.image.file.PATCH_SIZE = [64, 64]
kaishi.image.file.RESAMPLE_METHOD
class kaishi.image.file.ImageFile(basedir: str, relpath: str, filename: str)

Bases: kaishi.core.file.File

Image file object that inherits from the core file class and adds image-specific attributes and methods.

verify_loaded(self)

Verify image and derivatives are loaded (only performs the load if the image is unloaded).

update_derived_images(self)

Update images derived from the base image (i.e. thumbnail, small version, and random patch).

rotate(self, ccw_rotation_degrees: int)

Rotate all instances of image by ‘ccw_rotation_degrees’.

Parameters

ccw_rotation_degrees (int) – degrees to rotate the image by

limit_dimensions(self, max_width: int = None, max_height: int = None, max_dimension: int = None)

Limit the max dimension of the image and resize accordingly. Any combination of these arguments can be defined, however, if none are defined, this method does nothing.

Parameters
  • max_width (int) – maximum width of the image

  • max_height (int) – maximum height of the image

  • max_dimension (int) – maximum width or height (applies to both)

convert_to_grayscale(self)

Convert image to grayscale.

compute_perceptual_hash(self, hashfunc=imagehash.average_hash)

Calculate perceptual hash (close in value to similar images.

Parameters

hashfunc (function) – function object to be used to calculate the hash value (defualts to imagehash.average_hash)

Returns

hash value (as computed by hashfunc)