Reference filter()

filter()

Applies an image filter to the image.

The preset options are:

INVERT Inverts the colors in the image. No parameter is used.

GRAY Converts the image to grayscale. No parameter is used.

THRESHOLD Converts the image to black and white. Pixels with a grayscale value above a given threshold are converted to white. The rest are converted to black. The threshold must be between 0.0 (black) and 1.0 (white). If no value is specified, 0.5 is used.

OPAQUE Sets the alpha channel to be entirely opaque. No parameter is used.

POSTERIZE Limits the number of colors in the image. Each color channel is limited to the number of colors specified. Values between 2 and 255 are valid, but results are most noticeable with lower values. The default value is 4.

BLUR Blurs the image. The level of blurring is specified by a blur radius. Larger values increase the blur. The default value is 4. A gaussian blur is used in P2D mode. A box blur is used in WEBGL mode.

ERODE Reduces the light areas. No parameter is used.

DILATE Increases the light areas. No parameter is used.

Examples

Syntax

filter(filterType, [filterParam])

Parameters

filterType

either THRESHOLD, GRAY, OPAQUE, INVERT, POSTERIZE, ERODE, DILATE or BLUR.

filterParam

parameter unique to each filter.

Notice any errors or typos? Please let us know. Please feel free to edit src/image/p5.Image.js and open a pull request!

Related References