ofn-luminosity-masks

Purpose

This plug-in creates a selection mask based on the luminosity of pixels.

These selection masks are called "Luminosity masks" and are a very powerful technique to perform smooth and natural color changes in a picture. This technique is very well explained in PatDavid's canonical tutorial on the subject.

This plug-in creates the masks shown in the tutorial, among others

Unlike the tutorial, and unlike most Gimp scripts based on this tutorial,

A side benefit of the single-mask approach is that the selection can be automatically set from the mask and this saves a few mouse clicks.

Operation

Defining your own masks

Defining a luminosity mask is exactly equivalent to defining a "curve", the only difference being how the curve is interpreted.

The usual masks correspond to simple curves:

standard masks][1

But you can make arbitrary ones, for instance, if you want to deal with things that are light, but not very light (according to some authors, S-shaped sides make for smoother transitions):

arbitrary masks][1

For a one-shot usage, you would:

But if you often use the same mask this gets tedious. You can of course save the curve as a preset of the Curves tool, but this plug-in lets you define your own curves by putting them in a plug-in configuration file.

The file structure is simple. Lines are either

It would be tedious to copy points coordinates between the Curves display and the configuration file, but there is an easy way: if you apply the curve once (for instance when using the "quickmask", as mentioned above), it is saved as a preset, and this preset is the first that appears in the Presets selector (you can also save it and give it a name by clicking the + icon).

The presets are saved in a text file: in 2.10 this is {your Gimp profile}/filters/GimpCurvesConfig.settings.

(GimpCurvesConfig "2019-11-16 00:11:19"
    (time 1573859479)
    (linear no)
    (channel value)
    (curve
        (curve-type smooth)
        (points 14 0 0 0.43941411451398138 0.2421875 0.5352862849533957 0.875 0.61651131824234351⏎
        0.98828125 0.69241011984021306 0.88671875 0.76964047936085211 0.30078125 1 0)
        (point-types 7 smooth smooth smooth smooth smooth smooth smooth)
        (n-samples 256)
[... snip ...]

The top item is the last saved preset. The line that starts with (points is the one of interest. Its contents (minus the opening (points, the first number (14), and the closing )) can be used directly in the plug-in configuration:

Example/Middle-Light;Light mediums;0 0 0.43941411451398138 0.2421875⏎ 
0.5352862849533957 0.875 0.61651131824234351 0.98828125 0.69241011984021306⏎
0.88671875 0.76964047936085211 0.30078125 1 0

(the line above is folded for readability, this should be one single line). There is no need to be this accurate in practice, the values can be rounded to a couple of decimals to make the line an easier read:

Example/Middle-Light;Light mediums;0 0 0.44 0.24 0.54 0.86 0.62 0.99 0.69 0.89 0.77 0.30 1 0

In practice