# Module PIL.ImageOps

#### Module Summary:

    def autocontrast(image, cutoff=0, ignore=None)

> Maximize (normalize) image contrast.

    def colorize(image, black, white)

> Colorize grayscale image.

    def crop(image, border=0)

> Remove border from image.

    def deform(image, deformer, resample=2)

> Deform the image.

    def equalize(image)

> Equalize the image histogram.

    def expand(image, border=0, fill=0)

    def fit(image, size, method=0, bleed=0.0, centering=(0.5, 0.5))

> Returns a sized and cropped version of the image, cropped to the requested aspect ratio and size.

    def flip(image)

> Flip the image vertically (top to bottom).

    def grayscale(image)

> Convert the image to grayscale.

    def invert(image)

> Invert (negate) the image.

    def mirror(image)

> Flip image horizontally (left to right).

    def posterize(image, bits)

> Reduce the number of bits for each colour channel.

    def solarize(image, threshold=128)

> Invert all pixel values above a threshold.

## Functions

### autocontrast

    autocontrast(image, cutoff=0, ignore=None)

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).

#### Parameters:

`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).

#### Returns:

An image.

### colorize

    colorize(image, black, white)

Colorize grayscale image. The black and white arguments should be RGB tuples; this function calculates a colour wedge mapping all black pixels in the source image to the first colour, and all white pixels to the second colour.

#### Parameters:

`image` -- The image to colourize.

`black` -- The colour to use for black input pixels.

`white` -- The colour to use for white input pixels.

#### Returns:

An image.

### crop

    crop(image, border=0)

Remove border from image. The same amount of pixels are removed from all four sides. This function works on all image modes.

#### Parameters:

`image` -- The image to crop.

`border` -- The number of pixels to remove.

#### Returns:

An image.

### deform

    deform(image, deformer, resample=2)

Deform the image.

#### Parameters:

`image` -- The image to deform.

`deformer` -- A deformer object.

`resample` -- What resampling filter to use.

#### Returns:

An image.

### equalize

    equalize(image)

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.

#### Parameters:

`image` -- The image to equalize.

#### Returns:

An image.

### expand

    expand(image, border=0, fill=0)

Add border to the image

#### Parameters:

`image` -- The image to expand.

`border` -- Border width, in pixels.

`fill` -- Pixel fill value (a colour value). Default is 0 (black).

#### Returns:

An image.

### fit

    fit(image, size, method=0, bleed=0.0, centering=(0.5, 0.5))

Returns a sized and cropped version of the image, cropped to the requested aspect ratio and size.

The fit function was contributed by Kevin Cazabon.

#### Parameters:

`size` -- The requested output size in pixels, given as a (width, height) tuple.

`method` -- What resampling method to use. Default is Image.NEAREST.

`bleed` -- Remove a border around the outside of the image (from all four edges. The value is a decimal percentage (use 0.01 for one percent). The default value is 0 (no border).

`centering` -- Control the cropping position. Use (0.5, 0.5) for center cropping (e.g. if cropping the width, take 50% off of the left side, and therefore 50% off the right side). (0.0, 0.0) will crop from the top left corner (i.e. if cropping the width, take all of the crop off of the right side, and if cropping the height, take all of it off the bottom). (1.0, 0.0) will crop from the bottom left corner, etc. (i.e. if cropping the width, take all of the crop off the left side, and if cropping the height take none from the top, and therefore all off the bottom).

#### Returns:

An image.

### flip

    flip(image)

Flip the image vertically (top to bottom).

#### Parameters:

`image` -- The image to flip.

#### Returns:

An image.

### grayscale

    grayscale(image)

Convert the image to grayscale.

#### Parameters:

`image` -- The image to convert.

#### Returns:

An image.

### invert

    invert(image)

Invert (negate) the image.

#### Parameters:

`image` -- The image to invert.

#### Returns:

An image.

### mirror

    mirror(image)

Flip image horizontally (left to right).

#### Parameters:

`image` -- The image to mirror.

#### Returns:

An image.

### posterize

    posterize(image, bits)

Reduce the number of bits for each colour channel.

#### Parameters:

`image` -- The image to posterize.

`bits` -- The number of bits to keep for each channel (1-8).

#### Returns:

An image.

### solarize

    solarize(image, threshold=128)

Invert all pixel values above a threshold.

#### Parameters:

`image` -- The image to posterize.

`threshold` -- All pixels above this greyscale level are inverted.

#### Returns:

An image.