# NodeBox

Create visual output with Python programming code
Home Download Reference Tutorial Library Gallery About

# photobot.Layer.pixels.convolute()

## Syntax

    canvas.layers[i].pixels.convolute(kernel, scale=None, offset=0)

## Description

A convolution kernel is a matrix that transforms pixels. Essentially, such a matrix can be used to define custom filters, the central pixel in the matrix derives its new value from the surrounding pixels multiplied by the weights in the matrix.

The kernel parameter is a list of either 9 (3x3) or 25 (5x5) integer or floating-point numbers.

## Example

A simple convolution kernel is the Gaussian blur:

    kernel = [0, 1, 0,
              1, 4, 1,
              0, 1, 0]

    import photobot
    canvas = photobot.canvas(100,100)
    canvas.layer("robot.jpg")
    canvas.layers[1].pixels.convolute(kernel)