pyimagetest

class pyimagetest.ImageBackend

ABC for image backends.

Each subclass has to implement the native_image_type as well as the basic I/O methods import_image() and export_image().

abstract export_image(image: Any)numpy.ndarray

Exports an image to numpy.ndarray.

The output is of shape == (height, width, channels) and of dtype == numpy.float32.

Parameters

image – Image to be exported.

abstract import_image(file: str) → Any

Imports an image from file.

Parameters

file – Path to the file that should be imported.

abstract property native_image_type

Native image type of the backend.

This is used to infer the ImageBackend from a given image.

pyimagetest.add_image_backend(name: str, backend: pyimagetest.backends.ImageBackend, allow_duplicate_type: bool = False)None

Adds custom backend to the available backends.

Parameters
  • name – Name of the backend

  • backend – Backend

  • allow_duplicate_type – If True, no check for duplicate native_image_type s is performed. Defaults to False.

Raises

RuntimeError – If another ImageBackend with the same native_image_type already present and allow_duplicate_type is False.

Note

If you add an ImageBackend with a duplicate native_image_type, the automatic backend inference with infer_image_backend() might not work correctly.

pyimagetest.remove_image_backend(name: str)None

Removes a backend from the known backends.

Parameters

name – Name of the backend to be removed

pyimagetest.infer_image_backend(image: Any) → pyimagetest.backends.ImageBackend

Infers the corresponding backend from the image.

Parameters

image – Image with type of any known backend

Raises

RuntimeError – If type of image does not correspond to any known image backend

pyimagetest.assert_images_almost_equal(image1: Any, image2: Any, mae: float = 0.01, backend1: Optional[Union[pyimagetest.backends.ImageBackend, str]] = None, backend2: Optional[Union[pyimagetest.backends.ImageBackend, str]] = None)None

Image equality assertion.

Parameters
Raises

AssertionError – If image1 and image2 are not equal up to the acceptable MAE.