machinevisiontoolbox.Image.Read

classmethod Image.Read(filename, alpha=False, rgb=True, **kwargs)

Read image from file

Parameters:
  • filename (str) – image file name

  • alpha (bool, optional) – include alpha plane if present, defaults to False

  • rgb (bool, optional) – force color image to be in RGB order, defaults to True

  • kwargs – options applied to image frames, see convert

Raises:

ValueError – file not found

Returns:

image from file

Return type:

Image

Load monochrome or color image from file, many common formats are supported. A number of transformations can be applied to the image loaded from the file before it is returned.

Example:

>>> from machinevisiontoolbox import Image
>>> Image.Read('street.png')
Image: 1280 x 851 (uint8) [.../images/street.png]
>>> Image.Read('flowers1.png')
Image: 640 x 426 (uint8), R:G:B [.../images/flowers1.png]
>>> Image.Read('flowers1.png', grey=True)
Image: 640 x 426 (uint8) [.../images/flowers1.png]
>>> Image.Read('flowers1.png', dtype='float16')
Image: 640 x 426 (float16), R:G:B [.../images/flowers1.png]
>>> Image.Read('flowers1.png', reduce=4)
Image: 160 x 107 (uint8), R:G:B [.../images/flowers1.png]
>>> Image.Read('flowers1.png', gamma='sRGB') # linear tristimulus values
Image: 640 x 426 (uint8), R:G:B [.../images/flowers1.png]
Note:

If the path is not absolute it is first searched for relative to the current directory, and if not found, it is searched for in the images folder of the mvtb_data package.

Seealso:

iread convert cv2.imread