Image.Read#
- classmethod Image.Read(filename: str | Path | None = None, alpha: bool = False, rgb: bool = True, **kwargs: Any) Self[source]#
Read image from file
- Parameters:
filename (str or Path, optional) – image file name, if not given a file browser is opened
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, or no file selected in browser
ImportError –
filenameomitted but tkinter is unavailable
- Returns:
image from file
- Return type:
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.
If
filenameis omitted a native file-browser dialogue is opened, initially showing theimagesfolder of themvtb_datapackage.Example:
>>> from machinevisiontoolbox import Image >>> Image.Read('street.png') Image(size=(1280, 851), dtype=uint8, name='.../images/street.png') >>> Image.Read('flowers1.png') Image(size=(640, 426), dtype=uint8, nplanes=3, colororder=R:G:B, name='.../images/flowers1.png') >>> Image.Read('flowers1.png', grey=True) Image(size=(640, 426), dtype=uint8, name='.../images/flowers1.png') >>> Image.Read('flowers1.png', dtype='float16') Image(size=(640, 426), dtype=float32, nplanes=3, colororder=R:G:B, name='.../images/flowers1.png') >>> Image.Read('flowers1.png', reduce=4) Image(size=(160, 107), dtype=uint8, nplanes=3, colororder=R:G:B, name='.../images/flowers1.png') >>> Image.Read('flowers1.png', gamma='sRGB') # linear tristimulus values Image(size=(640, 426), dtype=uint8, nplanes=3, colororder=R:G:B, name='.../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
imagesfolder of the mvtb_data package.Warning
In an ipython environment, eg.
mvtbtool, the file-browser dialogue may not work. In this case, specify the filename as a string.- Seealso: