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

Compare simple transformations, investigate why they fail or succeed under particular requirements, and examine whether a general mathematical obstruction exists.

Alternative variant of the 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?

Research Question

Can a continuous function from the RGB cube to itself maintain a positive minimum Euclidean distance between every input colour and its output, and what does the answer imply for discrete 24-bit RGB colours?

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 this 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

5. Proving the impossibility

5.1. One-dimensional simplified case

5.2. 3D: Browuser’s fixed point theorem

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.