Skip to content

Invert

Fact Value
Also called Negative, Image negative
Status Implemented and tested
Family Enhancement, illumination and color
Engine Browser
Type Nonlinear, point, negative transfer
Output Image
Operator shown as point-transfer (exact)
Support radius 0
Code web/src/core/filters/enhancement/point-ops.ts, invertFilter
Operator code web/src/core/filters/enhancement/point-ops.ts, invertTransfer
Channels RGB, Brightness only

Overview

Invert turns the image into its negative. Black becomes white, white becomes black, and each color turns into its complement. Inverting twice gives the image back.

Two panels: bright disks on a dark background, and the inverted image with dark disks on a bright background. Two panels: bright disks on a dark background, and the inverted image with dark disks on a bright background.
Disks and their negative.

How it works

  1. Subtract every value from 255.

Mathematical foundation

\[ I_{\text{out}} = 255 - I \]

The formula shows the default parameter values.

where

  • \(I\): Input value from 0 to 255

The image negative of Gonzalez and Woods, with L - 1 = 255. Each value is mirrored around the middle of the range. With RGB scope every color turns into its complement. With the brightness scope only luma is mirrored, so hues stay and light and dark swap.

Gonzalez and Woods call this the image negative, s = L - 1 - r. It is a straight line with slope -1, so it keeps all contrast and only reverses its sign.

Kernel or operator

The Inspector draws the transfer curve for the current settings, with the input value on the horizontal axis and the output on the vertical axis. The Point-op curve in the Learn panel draws the same curve with the histograms of the open image before and after.

Algorithm

  1. Subtract every value from 255.

Parameters

Parameter Default Values Meaning
Channels channelScope RGB RGB, Brightness only Which part of the color image the filter changes.

Implementation

invertFilter in web/src/core/filters/enhancement/point-ops.ts uses invertTransfer. The filter is a point filter: the runner builds a table of 256 outputs once and looks up each pixel. Values between two levels, as luma often is, go through the curve directly.

Worked example

Input 0 30 128 220 255
255 - I 255 225 127 35 0
Pixel 255 225 127 35 0

The disks of the figure have value 220 on a background of 30, so they become 35 on 225.

Complexity

  • Time: \(O(N)\)
  • Memory: \(O(1)\)

N is the number of pixels. The 256-entry table makes each pixel a single lookup.

Artifacts and limitations

Limitations

  • Does not undo the orange mask of color film negatives.

Artifacts

  • None.

Tests

The reference writes the same curve with NumPy and applies it to the random test plane. Before the cases are written, the curve is checked against Pillow's ImageOps.invert on all 256 levels.

References