3.3 KiB
Image Class
convert(self, mode=None, matrix=None, dither=None, palette=0, colors=256) Returns a converted copy of this image. For the "P" mode, this method translates pixels through the palette. If mode is omitted, a mode is chosen so that all information in the image and the palette can be represented without a palette.
The current version supports all possible conversions between
"L", "RGB" and "CMYK." The **matrix** argument only supports "L"
and "RGB".
crop(self, box=None)
Returns a rectangular region from this image. The box is a
4-tuple defining the left, upper, right, and lower pixel
coordinate. See :ref:coordinate-system
.
Note: Prior to Pillow 3.4.0, this was a lazy operation.
:param box: The crop rectangle, as a (left, upper, right, lower)-tuple.
:rtype: :py:class:`~PIL.Image.Image`
:returns: An :py:class:`~PIL.Image.Image` object.
getextrema(self) Gets the the minimum and maximum pixel values for each band in the image.
:returns: For a single-band image, a 2-tuple containing the
minimum and maximum pixel value. For a multi-band image,
a tuple containing one 2-tuple for each band.
histogram(self, mask=None, extrema=None) Returns a histogram for the image. The histogram is returned as a list of pixel counts, one for each pixel value in the source image. If the image has more than one band, the histograms for all bands are concatenated (for example, the histogram for an "RGB" image contains 768 values).
save(self, fp, format=None, **params) Saves this image under the given filename. If no format is specified, the format to use is determined from the filename extension, if possible.
Keyword options can be used to provide additional instructions
to the writer. If a writer doesn't recognise an option, it is
silently ignored. The available options are described in the
:doc:`image format documentation
<../handbook/image-file-formats>` for each writer.
show(self, title=None, command=None) Displays this image. This method is mainly intended for debugging purposes.
On Unix platforms, this method saves the image to a temporary
PPM file, and calls the **display**, **eog** or **xv**
utility, depending on which one can be found.
On macOS, this method saves the image to a temporary PNG file, and
opens it with the native Preview application.
ImageOps Module
The ImageOps module contains a number of ‘ready-made’ image processing operations. This module is somewhat experimental, and most operators only work on L and RGB images.
Only bug fixes have been added since the Pillow fork.
New in version 1.1.3.
PIL.ImageOps.autocontrast(image, cutoff=0, ignore=None)[source] Maximize (normalize) image contrast. This function calculates a histogram of the input image, removes cutoff percent of the lightest and darkest pixels from the histogram, and remaps the image so that the darkest pixel becomes black (0), and the lightest becomes white (255).
PIL.ImageOps.equalize(image, mask=None)[source] Equalize the image histogram. This function applies a non-linear mapping to the input image, in order to create a uniform distribution of grayscale values in the output image.