Py5Image.apply_filter()#

Apply an image filter.

Examples#

example picture for apply_filter()
 1def setup():
 2    global img1
 3    global img2
 4    img1 = py5.load_image("apples.jpg")
 5    img2 = py5.load_image("apples.jpg")
 6    img1.apply_filter(py5.THRESHOLD, 0.3)
 7    img2.apply_filter(py5.THRESHOLD, 0.7)
 8
 9
10def draw():
11    py5.image(img1, 0, 0)
12    py5.image(img2, py5.width//2, 0)
example picture for apply_filter()
 1def setup():
 2    global img1
 3    global img2
 4    img1 = py5.load_image("apples.jpg")
 5    img2 = py5.load_image("apples.jpg")
 6    img2.apply_filter(py5.GRAY)
 7
 8
 9def draw():
10    py5.image(img1, 0, 0)
11    py5.image(img2, py5.width//2, 0)
example picture for apply_filter()
 1def setup():
 2    global img1
 3    global img2
 4    img1 = py5.load_image("apples.jpg")
 5    img2 = py5.load_image("apples.jpg")
 6    img2.apply_filter(py5.INVERT)
 7
 8
 9def draw():
10    py5.image(img1, 0, 0)
11    py5.image(img2, py5.width//2, 0)
example picture for apply_filter()
 1def setup():
 2    global img1
 3    global img2
 4    img1 = py5.load_image("apples.jpg")
 5    img2 = py5.load_image("apples.jpg")
 6    img2.apply_filter(py5.POSTERIZE, 4)
 7
 8
 9def draw():
10    py5.image(img1, 0, 0)
11    py5.image(img2, py5.width//2, 0)
example picture for apply_filter()
 1def setup():
 2    global img1
 3    global img2
 4    img1 = py5.load_image("apples.jpg")
 5    img2 = py5.load_image("apples.jpg")
 6    img2.apply_filter(py5.BLUR, 6)
 7
 8
 9def draw():
10    py5.image(img1, 0, 0)
11    py5.image(img2, py5.width//2, 0)
example picture for apply_filter()
 1def setup():
 2    global img1
 3    global img2
 4    img1 = py5.load_image("apples.jpg")
 5    img2 = py5.load_image("apples.jpg")
 6    img2.apply_filter(py5.ERODE)
 7
 8
 9def draw():
10    py5.image(img1, 0, 0)
11    py5.image(img2, py5.width//2, 0)
example picture for apply_filter()
 1def setup():
 2    global img1
 3    global img2
 4    img1 = py5.load_image("apples.jpg")
 5    img2 = py5.load_image("apples.jpg")
 6    img2.apply_filter(py5.DILATE)
 7
 8
 9def draw():
10    py5.image(img1, 0, 0)
11    py5.image(img2, py5.width//2, 0)

Description#

Apply an image filter.

Filters the image as defined by one of the following modes:

  • THRESHOLD: Converts the image to black and white pixels depending if they are above or below the threshold defined by the level parameter. The parameter must be between 0.0 (black) and 1.0 (white). If no level is specified, 0.5 is used.

  • GRAY: Converts any colors in the image to grayscale equivalents. No parameter is used.

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

  • INVERT: Sets each pixel to its inverse value. No parameter is used.

  • POSTERIZE: Limits each channel of the image to the number of colors specified as the parameter. The parameter can be set to values between 2 and 255, but results are most noticeable in the lower ranges.

  • BLUR: Executes a Gaussian blur with the level parameter specifying the extent of the blurring. If no parameter is used, the blur is equivalent to Gaussian blur of radius 1. Larger values increase the blur.

  • ERODE: Reduces the light areas. No parameter is used.

  • DILATE: Increases the light areas. No parameter is used.

Underlying Processing method: PImage.filter

Syntax#

apply_filter(kind: int, /) -> None
apply_filter(kind: int, param: float, /) -> None

Parameters#

  • kind: int - Either THRESHOLD, GRAY, OPAQUE, INVERT, POSTERIZE, BLUR, ERODE, or DILATE

  • param: float - unique for each filter, see description

Updated on November 12, 2021 11:30:58am UTC