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:
- Raises:
FileNotFoundError – file is neither in the current folder nor in the mvtb-data
imagesfolderValueError – 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.Changed in version 2.5.0: A file that cannot be found raises
FileNotFoundError, with a short traceback and the names of similar files, instead ofValueError.Examples
>>> 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.Note
The image data is a C-contiguous array of pixels, so the
draw_*methods and OpenCV functions can operate on it directly.Warning
In an ipython environment, eg.
mvtbtool, the file-browser dialogue may not work. In this case, specify the filename as a string.See also