pyimagetest
¶
-
class
pyimagetest.
ImageBackend
¶ ABC for image backends.
Each subclass has to implement the
native_image_type
as well as the basic I/O methodsimport_image()
andexport_image()
.-
abstract
export_image
(image: Any) → numpy.ndarray¶ Exports an image to
numpy.ndarray
.The output is of
shape == (height, width, channels)
and ofdtype == 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.
-
abstract
-
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 duplicatenative_image_type
s is performed. Defaults toFalse
.
- Raises
RuntimeError – If another
ImageBackend
with the samenative_image_type
already present andallow_duplicate_type
isFalse
.
Note
If you add an
ImageBackend
with a duplicatenative_image_type
, the automatic backend inference withinfer_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
image1 – Image 1
image2 – Image 2
mae – Maximum acceptable mean absolute error (MAE). Defaults to
1e-2
.backend1 –
ImageBackend
or its name forimage1
. If omitted, the backend is inferred fromimage1
withinfer_image_backend()
.backend2 –
ImageBackend
or its name forimage2
. If omitted, the backend is inferred fromimag2
withinfer_image_backend()
.
- Raises
AssertionError – If image1 and image2 are not equal up to the acceptable MAE.