Mathematics: Analysis and Approaches Higher Level
Internal Assessment

Can a continuous RGB transformation always produce a contrasting colour?

Session: May 2026
№ of pages: tbd



1. Introduction

Personal interest

I was interested in colour spaces and video-processing algorithms.

I saw many watermarks in my life. And I often thought “why are they so ugly”? Why do most of them apply 2 effects (e.g. lightening the inside and darkening the contour), when for every colour it’s guaranteed that there is a contrasting colour? Why would they not just make an algorithm that creates a contrasting colour for every input colour?

I mean, there were some watermarks with “1 effect applied”, but at some point they would flicker to another effect (e.g. if the effect was to darken the image, but the underlying video became too dark, so the output of the effect would go out of the colour space, so the effect changed to lightening).

I thought such an effect is possible, since the RGB space is 3-dimensional. I thought it was somewhere around the 4-color theorem, which works in 2 dimensions, but does not have a corresponding theorem in 3 dimensions:

4-color theorem in 2Dvisual proof that such a theorem doesn’t exist in 3D

But then I decided to find out if this image effect is actually possible.

I remembered the [video by 3Blue1Brown] about the Hairy Ball Theorem that I’ve watched recently. I thought that my question is related to this theorem, and that creating the desired image effect is a form of combing a hairy ball, and thus is impossible.

I asked Gemini about it (mentioning my assumption about the Hairy Ball Theorem), and, as it turns out, the answer is no. The function that would satisfy all of my criteria is actually mathematically impossible.

In this mathematical exploration I will show this impossibility in detail.

2. Aim & Research Question

Aim

Determine whether it’s possible to create the desired function.

Research Question

To what extent is it possible to construct a continuous transformation of RGB colour space that guarantees a minimum contrast between every input colour and its output?

3. Mathematical model and requirements

3.1. The 24-bit RGB colour space and its discreteness

A 24-bit RGB colour is an ordered triple , where each coordinate is an integer from 0 to 255 (8 bits, ). The set of possible colours is

These are lattice points in a cube.

3.2. The function

Let’s define the desired watermark effect as a function that takes the input color and outputs a contrasting colour .

3.3. A definition of contrast

I will use Euclidean distance as a geometric measure of contrast:

For two colours and to be contrasting, the distance between them should be not less than a constant .

The actual value of constant doesn’t play a big role. I gotta assign it some value, though, todo .

3.4. The continuity of the function

Technically speaking, if the space we’re working in is discrete, then any function on that space is continuous [citation needed].

Hence, we will introduce another space that isn’t discrete (so ). Values between integers are permitted in this mathematical model, although they are not themselves 8-bit channel values.

On , continuity expresses that sufficiently small changes in input (of the function) produce small changes in output.

3.5. Table of designations todo

SymbolDescriptionFormulae
Input colour in discrete model;
independent variable
Output colour in the discrete model
Input colour in continuous model;
independent variable
Output colour in the continuous model;
dependent variable
Euclidean distance in RGB coordinate units
Input–output distance
Chosen minimum distance requirement; controlled variable

3.6. Model limitations

The desired function on itself works on one pixel only.
The intended way of applying the watermark is the following:

  • take a 1 bit / pixel watermark image
    (where 0 is transparent and 1 is opaque);
  • place it over the watermark area;
  • apply the function to the background pixels that lie under the watermark pixels that have the value of 1.

Therefore, the model doesn’t support watermark images with higher bit / pixel ratio.

This Mathematics Exploration focuses only on transformation done with 1 pixel, the implementation of the function to a video is beyond the scope.

Also I do not account for abrupt changes of the background video colour, because they can result in unwanted flickering. I only intend the function to be used on continuous colour input.

4. Attempts to create the function

4.1. Reflection through the centre

The first thing that comes to mind when we think of creating the function that outputs a contrasting colour for every input colour is the function of the basic colour inversion.

Example of the invert transformation

The mathematical notation of this function looks like this:

It works on each colour channel separately, by reflecting it about the centre of the space.

From here arises its main problem: for input points near the centre of the space, the contrast with the output point will be small. And if the input is from the very centre of the cube, then the function will output the exact same point, so the contrast will be 0.

Mathematically, it looks like this:

Note

The literal fixed point for this function exists only in continuous space . In the discrete space there are 8 adjacent points, each of which will have the contrast with the output of , which is almost unnoticeable by a human eye.

4.2. Shifting with wraparound

The next thing that comes to mind is just offsetting the value of each colour channel by a constant:

Example of the shift transformation

Yet the construction has a discontinuity in output between the inputs 127 and 128:
while

And this discontinuity holds true for all the other constants we choose instead of 128.

5. Proving the impossibility

5.1. One-dimensional simplified case

Before trying to create the desired function in RGB, I can firstly try to make a similar function in black-and-white (in one dimension).

Aforementioned transformations:
invert
shift
where is the luminosity (from 0 to 255).

For black-and-white, we can plot the graph of the entire desired function on a 2D graph. The function should be continuous (a.k.a. a smooth curve) and should not touch the axis (shown below in red).

Let’s look closer at the minimum and maximum input values.

At the function must output a value different from . Since there are no values below in range, the function must output a value above .

Same goes for the maximum input value — the function must output a value less than :

So we end up with a situation where a continuous function with limited domain has points above and below a straight line. And according to the intermediate value theorem [citation needed], this function must cross the straight line.

So in the 2-dimensional case, the desired function is impossible.

5.2. Brouwer’s fixed point theorem [3D]

The intermediate point theorem is actually a special case of Brouwer’s fixed point theorem for 1 dimension [citation needed].

For any continuous function mapping a nonempty compact convex set to itself, there is a point such that .

Brouwer’s fixed point theorem works in 3 dimensions too.

But out desired function wasn’t supposed to have a fixed point. Therefore it’s impossible.
This paragraph needs rewriting, I think

As I mentioned in 3.1, for our 24-bit discrete 3D space, there is no literal fixed point, but there are points with unacceptably low contrast.

5.3?

6. Reflection

The desired function is indeed impossible.

I guess, we will have to use 2+ transformations–watermarks. Or accept the discontinuity.

A topic for a further research might be investigating the possibility of such function, but with memory: the input will also include 1 or more preceding frames. But this is beyond the scope of this exploration.