pyvale.render.imagetools module

User facing image and texture loading, saving, and preparation helpers.

class EImageType(*values)[source]

Bases: Enum

Image file formats supported by image_save().

TIFF = '.tiff'
BMP = '.bmp'
PNG = '.png'
image_crop(image, x, y, width, height)[source]

Crop a rectangular region from an image (top left origin).

Parameters:
  • image (np.ndarray) – Input image array with shape (height, width) or (height, width, num_channels).

  • x (int) – Top left pixel coordinates of the crop rectangle.

  • y (int) – Top left pixel coordinates of the crop rectangle.

  • width (int) – Width and height of the crop region in pixels.

  • height (int) – Width and height of the crop region in pixels.

Returns:

np.ndarray – Cropped subarray with shape (height, width, ...) and matching dtype.

Raises:

ValueError – If crop bounds are invalid or exceed image dimensions.

image_grayscale(image)[source]

Convert an RGB or RGBA image to greyscale using standard luminance.

Parameters:

image (np.ndarray) – Input image array with shape (height, width) or (height, width, num_channels).

Returns:

np.ndarray – Greyscale image array with shape (height, width) and dtype float64.

Raises:

ValueError – If the input image array shape is unsupported.

image_load(path)[source]

Load an image from disk as a numpy array.

Parameters:

path (pathlib.Path or str) – Filesystem path to the image.

Returns:

np.ndarray – Image array with shape (height, width) for greyscale or (height, width, num_channels) for colour images.

image_normalise(image, lower=0.0, upper=1.0)[source]

Normalise finite pixel intensities onto the range [lower, upper].

Parameters:
  • image (np.ndarray) – Input image array with shape (height, width) or (height, width, num_channels).

  • lower (float, optional) – Target lower intensity value. Defaults to 0.0.

  • upper (float, optional) – Target upper intensity value. Defaults to 1.0.

Returns:

np.ndarray – Normalised image array with shape identical to input and dtype float64.

image_resize(image, size)[source]

Resize an image to (width, height) in pixels.

Parameters:
  • image (np.ndarray) – Input image array with shape (height, width) or (height, width, num_channels).

  • size (tuple[int, int]) – Target (width, height) dimensions in pixels.

Returns:

np.ndarray – Resized array with shape (size[1], size[0], ...) matching input dtype.

image_save(path, image, image_type=EImageType.TIFF, bits=8)[source]

Save an image in conventional top to bottom row orientation.

Parameters:
  • path (pathlib.Path or str) – Destination filesystem path.

  • image (np.ndarray) – Image array with shape (height, width) or (height, width, num_channels).

  • image_type (EImageType, optional) – Format extension (default is EImageType.TIFF).

  • bits (int, optional) – Bit depth (8 or 16). Defaults to 8.