image_load

paddle.vision. image_load ( path, backend=None ) [source]

Load an image.

Parameters
  • path (str) – Path of the image.

  • backend (str, optional) – The image decoding backend type. Options are cv2, pil, None. If backend is None, the global _imread_backend specified by set_image_backend will be used. Default: None.

Returns

Loaded image.

Return type

PIL.Image or np.array

Examples

>>> import numpy as np
>>> from PIL import Image
>>> from paddle.vision import image_load, set_image_backend

>>> fake_img = Image.fromarray((np.random.random((32, 32, 3)) * 255).astype('uint8'))

>>> path = 'temp.png'
>>> fake_img.save(path)

>>> set_image_backend('pil')

>>> pil_img = image_load(path).convert('RGB')

>>> print(type(pil_img))
<class 'PIL.Image.Image'>

>>> # use opencv as backend
>>> set_image_backend('cv2')

>>> np_img = image_load(path)
>>> print(type(np_img))
<class 'numpy.ndarray'>