Here's a technique you can use to select multiple colors, and get soft edge selections.
I borrowed the idea of using a Vector Math Node set to Length
to measure the similarity of colors from Robin Betts. It also relates to this question about replacing colors.
This is not an exact replica of the formula that's coded into Photoshop, but it achieves the same thing. In Ps the "fuzziness" has a range of values from 0
to 200
, with 100
being the default. While putting together this node setup I got to wondering what "fuzziness" is actually a measurement of, and found out that it is brightness values. In my node setup the fuzziness is represented in a range of 0.0
to 1.0
.
So instead of using Photoshop's eyedropper in additive mode, we place a custom "Select Color" group node for each color we want to add to the color range, and combine them with MixRGB nodes set to Add
and Fac set to 1.0
. We can chain as many as desired.
Note: It is also possible to subtract from the selection by setting a MixRGB node's blend mode to Subtract
(instead of Add
). More about the Subtract
blend mode here.
This is what's happening inside of each "Select Color" Group Node:
The final Math Node set to Subtract
is just inverting the selection so that the selected area is white instead of black.
When dealing with a selection mask or alpha transparency, we want a range of 0.0
to 1.0
, so enable Clamp
on the final Math Node to ensure the values stay within that range.
The final selection (basically a mask) can be used for anything, but in this example I have it factoring a a MixRGB node so that all the selected colors get replaced with a pale green.
Original image (credit):
Selection (mask):
Example result:
That's basically all there is to it, and this can be customized in various ways to select ranges of colors for whatever purpose.
2023/02/16 update:
Blend file added.
(Created with Blender ver. 3.4)
General notes on color mixing and selection
(Things that will be obvious to many people, but maybe not everyone.)
- In my example I am using the Mix node to simply replace the selected area with a solid color fill, however by changing the blend type in the drop-down from
Mix
to another type you can get different effects. For example, Hue
will colorize the selected area with a new hue.
- To change a selection with soft edges to one with hard edges, one simple way is to run it through a Math node set to
Greater Than
and adjust the Threshold.
- To make selection edges harder (but not necessarily completely hard), you can route the selection through an RGB Curves node and shape the curve into an S-curve or a steep linear curve. The steeper the curve, the harder the edges become.