Masks not very effective in 2.9 scheme script

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Masks not very effective in 2.9 scheme script

Ken Moffat
Hi,

TL;DR - using masks in a 2.8 scheme script works as intended to
extract parts of an image, but after converting it for 2.9 it does
much less.

One of my interests is photos - particularly trains, and for that I
like to resurrect as much detail as possible.  Fortunately, I've
been taking raw photos for several years.  Towards 2 years ago I
found out how to use three versions of the same raw image : correct
exposure (for the intended subject), overexposed to add shadow
detail, similarly underexposed to restore the highlights.  For the
overexposed image I make a mask from itself, desaturated and
inverted, and for the underexposed one I just desaturate the mask.

At that time I was doing it all manually (and that still worked fine
when I last tried it in 2.9.4).  There is of course a problem with
this approach which may make it unsuitable for some uses - the
resulting image lacks contrast, but there are ways around that.

Eventually I decided that I wanted to script this.  By that stage I
had started to use 2.9.  I got the script working ok on another
machine using 2.8, but after making changes for 2.9.4 it seemed to
do almost nothing.  At that stage I was still hoping to make the
masks from the "correct" exposure (it sounded like the right thing,
but turns out to give "too much of everything").  I then simplified
the 2.8 script, used it, decided it was ok.  Somebody sent me fixes
for 2.9 (change NORMAL to NORMAL-MODE, and gimp-desaturate-full to
gimp-drawable-desaturate).

The 2.8 version, and some examples (with a faulty process! - I had
assumed the G'MIC tone mapping was similar to Advanced Tone Mapping,
Doh!) are at http://zarniwhoop.uk/three-exposures.html - the plugin
for 2.8 is linked from the bottom of that page.

BUT (at last!) this still does much less than in 2.8.  I've been
using git 14795c1f72 from 26th June.  By turning off the undo group
I've been able to look at steps along the way.  The problem shows in
the attached 800x602 example pngs when I do the shadow layer:  The
overexposed image, and the desaturated and inverted images I'm going
to use as the masks look the same, but when I apply the mask not
very much happens.

Originally I was going to attach some 800x602 pngs, but the list
would not let me do that (mail too big), so instead I've created a
temporary page showing the good 2.8 side by side with 2.9 :

http://zarniwhoop.uk/problem.html

The files are:

x-2.{8,9}-three.png - what the plugin produces.  In 2.9 it is not
very different from the base image without the plugin.

x-2.{8,9}-shadow-mask.png - the masks for the shadow layer (i.e.
for the overexposed image).  These appear to be similar, so the
different desaturate command is probably not an issue.

x-2.{8,9}-overexp.png - the overexposed image, after masking, with
the other layers deleted and then superimposed on a white background
to see it more clearly.  In 2.9 there is seems to be less of
everything.

I've also put links to the 2.8 and 2.9 scripts at the bottom left of
that page.

I notice that the file sizes of pngs from 2.9 are a lot bigger, but
I'm sure that you already know that.

From looking at the script you can probably tell that I don't
understand scheme, so maybe I'm doing things wrong - this was just
an attempt to convert my manual steps into a script.

Any suggestions, please ?

ĸen
--
I live in a city. I know sparrows from starlings.  After that
everything is a duck as far as I'm concerned.  -- Monstrous Regiment
_______________________________________________
gimp-developer-list mailing list
List address:    [hidden email]
List membership: https://mail.gnome.org/mailman/listinfo/gimp-developer-list
List archives:   https://mail.gnome.org/archives/gimp-developer-list
Reply | Threaded
Open this post in threaded view
|

Re: Masks not very effective in 2.9 scheme script

Developers mailing list
On Tue, 11 Jul 2017 00:38:17 +0100
Ken Moffat <[hidden email]> wrote:

> Hi,
>
> TL;DR - using masks in a 2.8 scheme script works as intended to
> extract parts of an image, but after converting it for 2.9 it does
> much less.

The most likely reason for the different results, is that in 2.9 masks
use the pixels' linearized intensity as the alpha value, while in 2.8
they use the gamma-corrected intensity.  The linearized intensity
values are generally lower than the gamma-corrected ones, so the
resulting mask values, after pasting a desaturated image into the mask,
are lower in 2.9 than they would be in 2.8, resulting in a subtler
effect.  Note that these sorts of interactions is something we're still
working on.

For now, you have several options:  You can cast the mask values from
gamma-corrected ones to linear ones.  While there's no "obvious" way to
do that, there are several hackish ways.  For example, you could use
"colors -> components -> extract component", select any of the RGB
components, and enable "linear output".  You can do that either before
or after pasting the desaturated image into the mask; either way, you
should make sure to use high precision ("image -> precision"),
preferably floating point, or else there'll be notable data loss in
the intermediary results, in either the dark or the bright areas.
Unfortunately, this operation is not currently available to scripts.
You can get a good approximation for it using the levels tool instead
("colors -> levels"), with a gamma of 2.2.

Alternatively, you can avoid masks and use other forms of layer
compositing, although this might be more cumbersome.  Instead of
attaching a mask to a layer, keep both the masked layer and the mask as
ordinary layers, and put them in their own layer group, with the "mask"
layer below the "masked" layer.  Use "colors -> color to alpha", with
black color, on the mask, to turn black into transparency.  Then, set
the upper layer's mode to "multiply", or, alternatively, to
"normal" (from the default group), while also setting its composite
mode to "source atop" (in the layer attributes dialog).  If you want to
keep the mask layer opaque, then instead of using "color to alpha", add
a black layer above it, set its layer mode to "color erase" (from the
default group), and set its blend space to "RGB (perceptual)" (in the
layer attributes dialog).

All of the above (except as noted) is doable through a script, although
I'll leave it to you to work out the details :)  The procedure browser
is your friend.

--
Ell
_______________________________________________
gimp-developer-list mailing list
List address:    [hidden email]
List membership: https://mail.gnome.org/mailman/listinfo/gimp-developer-list
List archives:   https://mail.gnome.org/archives/gimp-developer-list
Reply | Threaded
Open this post in threaded view
|

Re: Masks not very effective in 2.9 scheme script

Developers mailing list
On Sat, Jul 15, 2017 at 08:21:32AM -0400, Ell via gimp-developer-list wrote:

> On Tue, 11 Jul 2017 00:38:17 +0100
> Ken Moffat <[hidden email]> wrote:
>
> > Hi,
> >
> > TL;DR - using masks in a 2.8 scheme script works as intended to
> > extract parts of an image, but after converting it for 2.9 it does
> > much less.
>
> The most likely reason for the different results, is that in 2.9 masks
> use the pixels' linearized intensity as the alpha value, while in 2.8
> they use the gamma-corrected intensity.  The linearized intensity
> values are generally lower than the gamma-corrected ones, so the
> resulting mask values, after pasting a desaturated image into the mask,
> are lower in 2.9 than they would be in 2.8, resulting in a subtler
> effect.  Note that these sorts of interactions is something we're still
> working on.
>

Thanks for the detailed reply.  I'll have to get back on the 2.9
machine at some point to work through the options.  Meanwhile, I've
saved a full copy of your mail in my notes.

Cheers.

ĸen
--
I live in a city. I know sparrows from starlings.  After that
everything is a duck as far as I'm concerned.  -- Monstrous Regiment
_______________________________________________
gimp-developer-list mailing list
List address:    [hidden email]
List membership: https://mail.gnome.org/mailman/listinfo/gimp-developer-list
List archives:   https://mail.gnome.org/archives/gimp-developer-list