pyvista.compare_images#
- compare_images(im1, im2, threshold=1, use_vtk: bool = True)[source]#
Compare two different images of the same size.
- Parameters:
- im1
str
|numpy.ndarray
|vtkRenderWindow
|vtkImageData
Render window, numpy array representing the output of a render window, or
vtkImageData
.- im2
str
|numpy.ndarray
|vtkRenderWindow
|vtkImageData
Render window, numpy array representing the output of a render window, or
vtkImageData
.- threshold
int
, default: 1 Threshold tolerance for pixel differences. This should be greater than 0, otherwise it will always return an error, even on identical images.
- use_vtkbool, default:
True
When disabled, computes the mean pixel error over the entire image using numpy. The difference between pixel is calculated for each RGB channel, summed, and then divided by the number of pixels. This is faster than using
vtk.vtkImageDifference
but potentially less accurate.
- im1
- Returns:
float
Total error between the images if using
use_vtk=True
, and the mean pixel error whenuse_vtk=False
.
Examples
Compare two active plotters.
>>> import pyvista as pv >>> pl1 = pv.Plotter() >>> _ = pl1.add_mesh(pv.Sphere(), smooth_shading=True) >>> pl2 = pv.Plotter() >>> _ = pl2.add_mesh(pv.Sphere(), smooth_shading=False) >>> error = pv.compare_images(pl1, pl2)
Compare images from file.
>>> import pyvista as pv >>> img1 = pv.read('img1.png') >>> img2 = pv.read('img2.png') >>> pv.compare_images(img1, img2)