ImageOps Module
The ImageOps
module contains a number of ‘ready-made’ imageprocessing operations. This module is somewhat experimental, and most operatorsonly work on L and RGB images.
Only bug fixes have been added since the Pillow fork.
1.1.3 新版功能.
PIL.ImageOps.
autocontrast
(image, cutoff=0, ignore=None)[源代码]- Maximize (normalize) image contrast. This function calculates ahistogram of the input image, removes cutoff percent of thelightest and darkest pixels from the histogram, and remaps the imageso that the darkest pixel becomes black (0), and the lightestbecomes white (255).
参数:
- image – The image to process.
- cutoff – How many percent to cut off from the histogram.
- ignore – The background pixel value (use None for no background).返回:
An image.
PIL.ImageOps.
colorize
(image, black, white, mid=None, blackpoint=0, whitepoint=255, midpoint=127)[源代码]- Colorize grayscale image.This function calculates a color wedge which maps all black pixels inthe source image to the first color and all white pixels to thesecond color. If mid is specified, it uses three-color mapping.The black and white arguments should be RGB tuples or color names;optionally you can use three-color mapping by also specifying mid.Mapping positions for any of the colors can be specified(e.g. blackpoint), where these parameters are the integervalue corresponding to where the corresponding color should be mapped.These parameters must have logical order, such thatblackpoint <= midpoint <= whitepoint (if mid is specified).
参数:
- image – The image to colorize.
- black – The color to use for black input pixels.
- white – The color to use for white input pixels.
- mid – The color to use for midtone input pixels.
- blackpoint – an int value [0, 255] for the black mapping.
- whitepoint – an int value [0, 255] for the white mapping.
- midpoint – an int value [0, 255] for the midtone mapping.返回:
An image.
PIL.ImageOps.
crop
(image, border=0)[源代码]- Remove border from image. The same amount of pixels are removedfrom all four sides. This function works on all image modes.
参见
参数:
- image – The image to crop.
- border – The number of pixels to remove.返回:
An image.
PIL.ImageOps.
deform
(image, deformer, resample=2)[源代码]- Deform the image.
参数:
- image – The image to deform.
- deformer – A deformer object. Any object that implements agetmesh method can be used.
- resample – An optional resampling filter. Same values possible asin the PIL.Image.transform function.返回:
An image.
PIL.ImageOps.
equalize
(image, mask=None)[源代码]- Equalize the image histogram. This function applies a non-linearmapping to the input image, in order to create a uniformdistribution of grayscale values in the output image.
参数:
- image – The image to equalize.
- mask – An optional mask. If given, only the pixels selected bythe mask are included in the analysis.返回:
An image.
PIL.ImageOps.
expand
(image, border=0, fill=0)[源代码]- Add border to the image
参数:
- image – The image to expand.
- border – Border width, in pixels.
- fill – Pixel fill value (a color value). Default is 0 (black).返回:
An image.
PIL.ImageOps.
fit
(image, size, method=0, bleed=0.0, centering=(0.5, 0.5))[源代码]- Returns a sized and cropped version of the image, cropped to therequested aspect ratio and size.
This function was contributed by Kevin Cazabon.
参数:
- image – The image to size and crop.
- size – The requested output size in pixels, given as a(width, height) tuple.
- method – What resampling method to use. Default is
PIL.Image.NEAREST
. - bleed – Remove a border around the outside of the image from allfour edges. The value is a decimal percentage (use 0.01 forone percent). The default value is 0 (no border).Cannot be greater than or equal to 0.5.
- centering – Control the cropping position. Use (0.5, 0.5) forcenter cropping (e.g. if cropping the width, take 50% offof the left side, and therefore 50% off the right side).(0.0, 0.0) will crop from the top left corner (i.e. ifcropping the width, take all of the crop off of the rightside, and if cropping the height, take all of it off thebottom). (1.0, 0.0) will crop from the bottom leftcorner, etc. (i.e. if cropping the width, take all of thecrop off the left side, and if cropping the height takenone from the top, and therefore all off the bottom).返回:
An image.
PIL.ImageOps.
flip
(image)[源代码]- Flip the image vertically (top to bottom).
参数:image – The image to flip.返回:An image.
PIL.ImageOps.
grayscale
(image)[源代码]- Convert the image to grayscale.
参数:image – The image to convert.返回:An image.
PIL.ImageOps.
invert
(image)[源代码]- Invert (negate) the image.
参数:image – The image to invert.返回:An image.
PIL.ImageOps.
mirror
(image)[源代码]- Flip image horizontally (left to right).
参数:image – The image to mirror.返回:An image.
PIL.ImageOps.
posterize
(image, bits)[源代码]- Reduce the number of bits for each color channel.
参数:
- image – The image to posterize.
- bits – The number of bits to keep for each channel (1-8).返回:
An image.
PIL.ImageOps.
solarize
(image, threshold=128)[源代码]- Invert all pixel values above a threshold.
参数:
- image – The image to solarize.
- threshold – All pixels above this greyscale level are inverted.返回:
An image.
当前内容版权归 ComingSpring 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 ComingSpring .