Page 1 of 2

[done] Multiplicative opacity between displayed layers?

Posted: Sat Jul 06, 2019 1:18 pm
by Pascal5
A nice feature would be to have the option to stack layers with multiplicative opacity (rather than just additive opacity, as currently done).

With additive opacity, displaying a layer B with opacity h over a layer A renders the final image: (1-h) A + h B.
(Am I right?)

With multiplicative opacity, that should be : (1-h) A + h A x B
(where x is standard color channel multiplication between two images if channels are defined in [0..1] range)

This is just right for combining some map data (hiking maps, labels, routes... provided it's drawn on white background) to base maps or photoimagery, and having these features displayed at full strength without having to fade away the underlying base map on the display.

I personally use that for overlaying SwissTopo or IGN hiking maps over photoimagery, but for now I have to create by my own an atlas containing the "multiplied" imagery before combining it to the standard atlas.

Re: Multiplicative opacity between displayed layers?

Posted: Tue Jul 09, 2019 3:37 pm
by Psyberia-Support
Hi Pascal,
Layers are added one over the other using blending modes.
The current mode is called "Source over" (see last image of the link above). The formula is the one you gave.
Unfortunately the "multiplicative opacity" doesn't exists.
I made a custom blending mode using your formula, but the difference is almost not perceptible (see screenshots). On the other end it's muuuch longer to display as it's done within the app and not natively supported by the system... But I'd be interested to see what differences do you get.
screenshots.jpg
(70.3 KiB) Downloaded 2639 times
However I've added other blending mode, like "Overlay". It will be possible to change modes per layers from the layer transparency view.

Re: [done] Multiplicative opacity between displayed layers?

Posted: Mon Dec 16, 2019 3:14 pm
by Psyberia-Support
Blending mode overlay is available from AQ 2.2.2.

Re: [done] Multiplicative opacity between displayed layers?

Posted: Tue Dec 31, 2019 10:23 pm
by Pascal5
There is the "overlay" blending mode, but I can't see the difference compared to the "normal" mode!

The "multiply" mode does not behave as expected. Reducing opacity fades to black instead of fading to no effect! Looks like you blended with a black image instead of blending with a white one before multiplying.

Thanks for your effort!

Re: [done] Multiplicative opacity between displayed layers?

Posted: Tue Dec 31, 2019 10:56 pm
by Pascal5
OK, I get the difference between "overlay" and "normal".

For simplicity of the app, I suggest to keep the only 3 useful modes:

- "Normal": For cross-fading between two maps.
- "Multiply": For surimposing two maps (typically, a base (photo?) map with an overlay (names, roads...))
- "Screen": For surimposing overlays containing white details on black background over dark areas.

I don't see any practical use for "Lighten" and "Darken", which create disturbing discontinuities highly dependent on the relative colors of the map. "Screen" and "Multiply" do the same work much more gracefully.

"Overlay" is also useless, as "Screen" does a similar job in a much better way.

Actually, for clarity to the average user, I would keep those 3 modes named as follows:

"Normal", the standard blend.
"Darken", which is actually "Multiply" (with the bug fixed).
"Lighten", which is actually "Screen"

Hope this helps...

Re: [done] Multiplicative opacity between displayed layers?

Posted: Sun Jan 12, 2020 1:31 pm
by Psyberia-Support
Hi again, thanks for the update.

First concerning the current "multiply" blending, the result is actually the one expected. The thing is that the opacity slider of the above layer does really control the opacity channel of that layer, but not the amount of the blending effect as you expect.
And the result of the multiply blending when one of the images is transparent, is transparent only. That's why the resulting image disappears when you set the above layer opacity to 0 (and the gray background appears, making it looks like it fades to gray).
I've made some change so the opacity value does control the blending amount, however it's technically more complicated and cannot work in every situations.
It will be available for testing purposes in the next beta that should be released today, I'm not sure I'll keep it like that.

For the other modes, I've been playing around (see screenshots), and I do find:
- "Lighten" (only lighter parts are kept) more clear than "Screen";
- "Multiply" better than "Darken", "Overlay" similar but brighter. Darken has the advantage of being easy to understand (only darker parts are kept), "Multiply" has the disadvantage of not being compatible with complex combinations (layering maps with different map projections).

Images: Google Sat as base map, Open Topo Map as overlay (75% opacity).
(1) Normal - (2) Screen - (3) Lighten
(4) Overlay - (5) Darken - (6) Multiply
blending_1.jpg
(86.97 KiB) Downloaded 2231 times
blending_2.jpg
(97.96 KiB) Downloaded 2231 times

Re: [done] Multiplicative opacity between displayed layers?

Posted: Sun Jan 12, 2020 8:13 pm
by helwin
Great feature, great results! Thank you so much for your work!

Re: [done] Multiplicative opacity between displayed layers?

Posted: Tue Jan 14, 2020 1:33 am
by Pascal5
As I understand "multiply": Given a base layer B and an overlay layer A mixed with a coefficient r, the final image would be: (1-r) B + r B x A. This is like performing a regular blend between B and B x A (instead of between B and A as in standard blend).

So, if I wanted an "as clean as possible" overlay similar to the first row of your pics, I would actually take the OSM layer as base layer and multiply it with the Sat layer using a coefficient 25% ! Maybe the "opacity" term is not appropriate here, since setting it at 100% does not hide away the base layer. We're rather talking about strength. So "strength" means "opacity" only in "normal" blending mode. (Talking "opacity" is maybe the cause of the confusion in our discussion.)

Or, we could obtain the same result the opposite way: Having Sat as a base layer with coefficient 25% (blended with white background), and adding a "multiply" OSM layer with coefficient 100%. Indeed, this is the good thing with this multiplicative mode: Layers can be combined with each having its own strength, if all are in "multiply" mode their order is actually unimportant.

This way of merging various layers is the one I implement in my own apps (I professionally work with GIS software), and actually find it more useful than the "normal" blend! If only one blending mode was available, I would definitely choose this one, since it almost "does it all" with the very simple and intuitive paradigm: Give to each layer its strength in the final mix, regardless of its ordering in the stack.

Controlling opacity with color value: I don't believe this can really be useful. And it's certainly difficult to implement with a not-so-predictable result (unless you have access to several thresholding parameters). I would definitely keep things simple here.

I don't understand the problem of "multiply" with "complex combinations". Computing B x A is available in all API's I know. Isn't it the case in your SDK? Or maybe we still don't have the same understanding of "multiply".

Also, in the current implementation of "multiply", the result is inconsistant. Setting r to 1% gives me an almost black image, while setting it to 0% gives me the unaltered base layer! Actually, you would get the proper result if the coefficient blends the layer to white instead of to black prior to multiplication.


Anyhow, thank you for your dedication in trying to make your piece of software perfect!

Re: [done] Multiplicative opacity between displayed layers?

Posted: Tue Jan 14, 2020 2:33 pm
by Psyberia-Support
Here is the formula for "Multiply" in the Android API: https://developer.android.com/reference ... e#MULTIPLY
There is no coefficient r.

By "complex combinations" I mean where the base map and overlay map pixels do not mach (if both have different map projection). In this case the overlay map must be drawn over the base map using a projection matrix, and in this case I cannot use the "homemade" multiply method described above.

Re: [done] Multiplicative opacity between displayed layers?

Posted: Tue Jan 14, 2020 9:11 pm
by Pascal5
"Here is the formula for "Multiply" in the Android API"

Exactly! This is the "Multiply" I meant. So, you introduce the coefficient r as a linear blend between the base layer B only (for 0%, no effect) and the combined layers B x A (for 100%, full effect). Hence, the formula (1-r) B + r B x A as I stated previously.

It seems that what's implemented in the current software is only r B x A. I guess there should be no much work for correcting this to the proper formula. Doing so, you will quickly find out that "Multiply" is indeed the best tools for performing overlays, particularly if the overlay layer contains features drawn in bright and light colors.

BTW, "Screen" is actually "Multiply" performed on the negative of the image. This is already working as it should in your current version of the software!

Thanks!

Re: [done] Multiplicative opacity between displayed layers?

Posted: Tue Jan 14, 2020 9:16 pm
by Pascal5
... Or, you may also formulate "Multiply" as follows:

(1-r) B + r B x A = B x ((1-r) I + r A) , if this is more convenient to implement. (I is plain white image).

Re: [done] Multiplicative opacity between displayed layers?

Posted: Fri Jan 17, 2020 3:19 pm
by Psyberia-Support
So, you introduce the coefficient r as a linear blend between the base layer B
This is what I've done in the current beta (should be available very soon) and what is shown on my previous screen shots.
It's just that written like this seems easy, but technically not, because you cannot work with the main image canvas (the multiply blend is destructive, so you need to make copies no the fly and work with those copies).

Re: [done] Multiplicative opacity between displayed layers?

Posted: Fri Jan 17, 2020 11:19 pm
by Pascal5
I don't know exactly the constraints you have from the Java API, but I would do the following:

* Use r to do a normal blend between I (plain white) and A (the current layer).
* Multiply the result with B (the base layer).

You should be fine like this, with no need to to access any layer two times! This is actually how I implement it in my own software.

Some small other matters...

More generally, in the interface, I would rename the "Opacity" parameter as "Visibility", which is actually the general behavior of this parameter for all blending modes. The "Opacity" term has pertinence only for the "Normal" mode!

Finally, is there a way to change the visibility of the default base layer? It seems stuck at 50%. A minor issue resulting from this is happens when I mix two layers. When I need to reduce the visibility of the lower layer in my mix, the unwanted default base layer sometimes shows up in my mix. Fortunately, this only happens at lower zoom levels where the base layer is visible. Still, it would be nice to have a user-accessible visibility slider for the base layer similarly to any other layer!


Again, I have to thank you for your tremendous effort in trying to bring your app close to perfection!!! ;)

Re: [done] Multiplicative opacity between displayed layers?

Posted: Mon Jan 20, 2020 11:36 am
by Psyberia-Support
Thanks for the multiply tip. I like it better this way.
I also have remove the "Screen" mode.

For the base map opacity, right now you cannot change this but I'll add an user setting for this in next update.
Note that from zoom level 7, the base map is not displayed at all anyway.

Re: [done] Multiplicative opacity between displayed layers?

Posted: Tue Jan 21, 2020 11:01 am
by Pascal5
Errr... No, please keep the Screen mode available! It is just fine as it is!

Agreed, it's less useful than the Multiply mode, but it can be very handy when adding light details and labels on a dark map (typically photoimagery), or when I need to mask out certain regions of a map to white or lighter areas.

Personally, what I find useful to do on photoimagery is to Screen over it the negative image of an overlay containing marks and labels. Those labels will appear white, or with light colors over the dark imagery. To have this in your software, you only need to add a "Negative" checkbox for each layer!

The modes I consider "less" useful are the Darken and Lighten modes, as Multiply and Screen do almost the same. Also, the Overlay mode is a bit hard to apprehend and to use in practical situations. Well, it's up to you to decide to keep them or not...

Thanks!