Possibly misunderstood the question in previous answer:
Quick and somewhat dirty method:
Use the Color selector, and set the "Select by" criterion to HSV saturation
or LCH chroma
. Then click anywhere on the background. This will only select pixels with a very low saturation, ie, the grayscale ones.
Then Color > Invert
. However, this leaves a few pixels untouched around the color bars.

PS: The problem with the answer you point to is that the "Color" blend mode (or its equivalents in 2.10, HSL Color
and LCH Color
) keep the value of the underlying layer, so you start with for instance a light green, the Color > Invert
transforms it to a dark purple, and then the Color
blend mode transforms the dark purple into... a dark green, because it won't change the value.
To be more specific, use the Pointer dialog to check the
"V" Component in the HSV model at the ends of the two lines:
Initial image:
Red -> yellow:-> 100 -> 100
Turquoise -> yellow:-> 50 -> 100
After Color > Invert
:
Red -> yellow:-> 100 -> 100
Turquoise -> yellow:-> 97 -> 60
So, no big change of Value in the first bar, but a swap of values in the other one. Applying HSV Color
:
Red -> yellow:-> 100 -> 100
Turquoise -> yellow:-> 97 -> 60
HSV Color
applied Hue/Saturation, but didn't change the Value, so the luminosity gradient in the turquoise-yellow bar remains inverted. You get similar results if you use LCh instead of HSV.