machinevisiontoolbox.Image.__getitem__

Image.__getitem__(key)[source]

Extract slice of image

Parameters:

key – slice to extract

Returns:

slice of image

Return type:

Image

Create a new image from the selected slice of the image, either a plane or a region of interest. If key is:

  • an int, select this plane

  • a string, select this named plane or planes

  • a 2-tuple of slice objects, select this uv-region across all planes

  • a 3-tuple of slice objects, select this region of uv and planes

Example:

>>> from machinevisiontoolbox import Image
>>> img = Image.Read("flowers4.png") # in RGB order
>>> red = img[0] # red plane
>>> red
Image: 640 x 426 (uint8)
>>> green = img["G"]
>>> green
Image: 640 x 426 (uint8)
>>> roi = img[100:200, 300:400]
>>> roi
Image: 100 x 100 (uint8), R:G:B
>>> roi = img[100:200, 300:400, 1:]
>>> roi
Image: 100 x 100 (uint8), G:B
Seealso:

red green blue plane roi