Image.plane#
- Image.plane(planes: int | str | list[int] | tuple[int, ...], copy: bool = False) Image[source][source]#
Extract plane(s) from color image
- Parameters:
- Raises:
ValueError – if image is not color
- Return out:
image containing only the selected planes
- Return type:
Create a new image from the selected planes of the image.
Examples
>>> from machinevisiontoolbox import Image >>> img = Image.Read("flowers4.png") # in RGB order >>> img.colororder_str 'R:G:B' >>> img.nplanes 3 >>> red = img.plane(0) # red plane >>> red Image(size=(640, 426), dtype=uint8) >>> red.iscolor False >>> red.nplanes 1 >>> green_blue = img.plane('G:B') # green and blue planes >>> green_blue Image(size=(640, 426), dtype=uint8, nplanes=2, colororder=G:B) >>> green_blue.iscolor True >>> green_blue.nplanes 2 >>> red_blue = img.plane([0, 2]) # red and blue planes >>> red_blue Image(size=(640, 426), dtype=uint8, nplanes=2, colororder=R:B) >>> bgr = img.plane("BGR") # planes reordered >>> bgr.colororder_str 'B:G:R'
Note
This can also be performed using the overloaded
__getitem__operator.To select more than one plane, use either a sequence of integers or a string of colon separated plane names.
For a single-plane image the index must be zero.
By default a single plane, selected by an int or a name, is a view that shares its pixels with the image. Several planes, selected by a name string or a list, are a new array, but a planar one. Neither is C-contiguous, so drawing into the result raises a
ValueError. Withcopy=Truethe result is always an independent, C-contiguous copy that can be drawn into, and changing it does not change the image. SeeImage.
Changed in version 2.5.0: Added the
copyoption.See also