Extracting Colors from an Image
GIMP USE CASE
Sample output ("Yellow channel") (gray background to see details)
Sample use case (Color exchanging)
As colors are the focus of attention in this kind of workflow, please ever set the 16 bit color depth mode AT THE MINIMUM before any manipulation, and make sure to work in a copy of the original layer only.
Image > Precision > 32 bit integer
1. CMYK Decompose
When working with this image, we will take out the YELLOW color, so for practical reasons the CMYK Channels will be more useful than other methods, however, being this extracts out the light-information channel
K, it's better to use it even for RGB colors instead.
Select the original layer > Layer > Duplicate Layer
Select the duplicate layer > Colors > Components > Decompose...
Color mode: CMYK
Decompose to layers: YES
2. Select your color, and select it well
You will notice there is a lot of artifacts all around the first three layers, however, the
black layer is which has the biggest amount of detailed information as it comes from the combination (and not sub-product) of the three RGB channels we had. Please
show the layers as you use them to better understand what's happening.
As we only need the yellow, and in all those layers the black means "it has not that color" while white implies "full of that color", we need to "clean" the non-yellow "channels" as follows:
Set your background color to black
Select the cyan layer
Edit > Fill with FG color
Select the magenta layer
Edit > Fill with FG color
As an exercise, we will compose the image at this point to take a look at why is his wrong at this state.
Colors > Components > Compose
As white is a combination of all RGB colors, there is no information about the difference between a bluish-white and a reddish-white. It's just X-Level of lightness, and the colors is on other channels.
This means this composition has lights of colors that aren't yellow, which means if we convert all blacks to alpha we will get visible white artifacts:
Colors > Color to alpha
Transparency threshold: 0.000
Opacity threshold: 1.000
White zones given from non-yellow bluish-withes
The solution to this is almost simple, and for this the CMYK Decomposition is key. If we have all pixels with whites and we only need pixels that has yellows, how can we
rest the pixels that are not in a yellowish zone?
Multiply mode multiplies the pixel values of the upper layer with those of the layer below it and then divides the result by 255. The result is usually a darker image. If either layer is white, the resulting image is the same as the other layer (1 * I = I). If either layer is black, the resulting image is completely black (0 * I = 0).
As we have Black and White images, we can multiply our
yellow layer with the
black layer to dark all zones of
black where is no yellow color. For this we need to invert
black because is same as an light layer inverted (the whitest, the more black tint will blend), while CMY are colors, so the absence of color is white. Remember we are working with RGB values over CMYK "channels":
Select the black layer
Colors > Invert (You now see a lightness layer)
Select the yellow layer
Layers > duplicate
Put it on top of the black layer
Change its blend mode to Multiply
Layers > Merge Down
You have reached a lightness channels for yellowish-pixels only. It should look like this:
See how completely white zones are overridden. This is because white is not a color itself. It's (in CMYK) the absence of it (because papers are white).
Now revert the state of the
black and recompose:
Select the black layer > Colors > Invert
Colors > Components > Compose (Defaults should be ok)
4. Use it
How you use this result depends on your needs, but as before, I would convert it to alpha with
Colors > Color to alpha as this is simplest and quick (And I don't know how to replicate that result with layers):
For the example above, I have changed its hue, putted it on top of the original image, then set its blend mode to
With this workflow you can process Cyan, Magenta, and Yellow colors easily, however, if you want to process Blue, Red, Green... for example, you will need a mix of layers. This is good news and bad news because you can see the CMYK values of whatever color you want to extract and distort the amount of white of the CMY layers in proportion, then multiply them all over the
black channel. But it's as time-consuming as precise.
This is a very viable way to literally modify the lights of an scene with lots of reflecting objects, just like changing the lamp or its properties, with a layer. Same with colors of objects, without the need of paths or selection tools.