pyvale.render.imagetools module¶
User facing image and texture loading, saving, and preparation helpers.
- class EImageType(*values)[source]¶
Bases:
EnumImage 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 dtypefloat64.- 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.Pathorstr) – 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:
- Returns:
np.ndarray– Normalised image array with shape identical to input and dtypefloat64.
- 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.Pathorstr) – Destination filesystem path.image (
np.ndarray) – Image array with shape(height, width)or(height, width, num_channels).image_type (
EImageType, optional) – Format extension (default isEImageType.TIFF).bits (
int, optional) – Bit depth (8 or 16). Defaults to 8.