compare_images

compare_images(im1, im2, threshold=1, use_vtk=True)

Compare two different images of the same size.

Parameters
im1filename, numpy.ndarray, vtkRenderWindow, or vtkImageData

Render window, numpy array representing the output of a render window, or vtkImageData.

im2filename, numpy.ndarray, vtkRenderWindow, or vtkImageData

Render window, numpy array representing the output of a render window, or vtkImageData.

thresholdint, optional

Threshold tolerance for pixel differences. This should be greater than 0, otherwise it will always return an error, even on identical images.

use_vtkbool, optional

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.

Returns
float

Total error between the images if using use_vtk=True, and the mean pixel error when use_vtk=False.

Examples

Compare two active plotters.

>>> import pyvista
>>> pl1 = pyvista.Plotter()
>>> _ = pl1.add_mesh(pyvista.Sphere(), smooth_shading=True)
>>> pl2 = pyvista.Plotter()
>>> _ = pl2.add_mesh(pyvista.Sphere(), smooth_shading=False)
>>> error = pyvista.compare_images(pl1, pl2)

Compare images from file.

>>> import pyvista
>>> img1 = pyvista.read('img1.png')  
>>> img2 = pyvista.read('img2.png')  
>>> pyvista.compare_images(img1, img2)