Read Image Files

Read and plot image files (JPEG, TIFF, PNG, etc).

import pyvista as pv
from pyvista import examples

PyVista fully supportes reading images into their own spatially referenced data objects (this example) as well as supports texture mapping of images onto datasets (see Applying Textures).

Download a JPEG image of a puppy and load it to pyvista.UniformGrid. This could similarly be implemented with any image file by using the pyvista.read() function and passing the path to the image file.

image = examples.download_puppy()
# or...
# image = pv.read('my_image.jpg')

When plotting images stored in pyvista.UniformGrid objects, it is important to specify usign the rgb option when plotting to ensure that the image’s true colors are used and not mapped.

# True image colors
image.plot(rgb=True, cpos="xy")
../../_images/sphx_glr_read-image_001.png
# Mapped image colors
image.plot(cpos="xy")
../../_images/sphx_glr_read-image_002.png

Total running time of the script: ( 0 minutes 22.800 seconds)

Gallery generated by Sphinx-Gallery