RGB Formula Editor

Transform images by applying custom RGB formulas to each pixel.

RGB Formula Editor is a free online tool that allows you to edit images using a custom formula for each color channel (red, green and blue) and the alpha channel.

Enter formulas for red, green, blue and alpha channels and see the changes in real time.

Drop your image here

How to apply a custom RGB formula to each pixel of an image?

  1. Upload the image that you want to transform. The image will load in the canvas above and the options will appear beside the image.
  2. Type the formulas for the red, green, blue and alpha channels. See in the section below the variables that you can use in the formulas.
  3. You can change the formulas and see the result in real time.
  4. Click "Download image" to download the image in PNG format.

Variables

The formulas can contain variables: r, g, b, a, x and y. See the table below for the description of each variable.

VariableDescription
rThe value of the red color channel of the original image, ranging from 0 to 255.
gThe value of the green color channel of the original image, ranging from 0 to 255.
bThe value of the blue color channel of the original image, ranging from 0 to 255.
aThe value of the alpha channel of the original image, ranging from 0 to 255.
xThe horizontal position of the pixel in the image, ranging from 0 to the image width minus 1.
yThe vertical position of the pixel in the image, ranging from 0 to the image height minus 1.

Examples

Below are some examples of images before and after applying the formulas, together with the formulas used.

Original imageImage after applying the formulasDescription and formulas
Example #1

Grayscale

Formulas:
Red(r+g+b)/3
Green(r+g+b)/3
Blue(r+g+b)/3
Alphaa

When RGB value is outside range [0-255]:

Clamp

Example #2

Invert colors.

Formulas:
Red255-r
Green255-g
Blue255-b
Alphaa

When RGB value is outside range [0-255]:

Clamp

Example #3

Red channel.

Formulas:
Redr
Green0
Blue0
Alphaa

When RGB value is outside range [0-255]:

Clamp

Example #4

RGB channel swap. RGB was converted to GRB. In the example image, the grass become reddish and the woman mouth becomes green.

Formulas:
Redg
Greenr
Blueb
Alphaa

When RGB value is outside range [0-255]:

Clamp

Example #5

Color quantization.

Formulas:
Redr>120?255:0
Greeng>160?255:0
Blueb>120?255:0
Alphaa

When RGB value is outside range [0-255]:

Clamp

Example #6

Custom formula.

Formulas:
Redr + x
Greeng + y
Blueb
Alphaa

When RGB value is outside range [0-255]:

Bounce

Configuration parameters

Formulas

FieldDescription
RedThe formula for the red color channel. Must evaluate to a number between 0 and 255.
GreenThe formula for the green color channel. Must evaluate to a number between 0 and 255.
BlueThe formula for the blue color channel. Must evaluate to a number between 0 and 255.
AlphaThe formula for the alpha channel. Must evaluate to a number between 0 and 255.

Additional configuration

FieldDescription
Behaviour when RGB value is outside range [0-255]

The formulas for red, green, blue and alpha channels must evaluate to numbers in the range between 0 and 255.

For any pixel, if a formula evaluate to a value outside this range, the value will be automatically adjusted to be in that range, based on the selected configuration (clamp, bounce or remainder).

This parameter determines how the values will be adjusted to belong to the range, when needed.

OptionDescription.
ClampIf the value is lower than 0, it will be changed to 0 and if the value is greater than 255 it will be changed to 255.
BounceThe value will keep "bouncing" between the min and max values (between 0 and 255).
RemainderIt will be applied the modulo (division remainder).

Related tools

Change image color

Change color of images by changing the red, green and blue components of each pixel of the image.

Change image hue

Adjust the hue of images. Hue rotate images by specifying an angle around the color circle.
Create images using math equations

Create images using math equations

Generate images from mathematical formulas.