Bug 413125 - Color to alpha makes the image lose its original color
Summary: Color to alpha makes the image lose its original color
Status: REPORTED
Alias: None
Product: krita
Classification: Applications
Component: Filters (show other bugs)
Version: 4.2.7.1
Platform: Microsoft Windows Microsoft Windows
: NOR wishlist
Target Milestone: ---
Assignee: Krita Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-10-18 01:59 UTC by acc4commissions
Modified: 2024-11-03 20:48 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments
capture (474.25 KB, image/jpeg)
2019-10-18 01:59 UTC, acc4commissions
Details
Alpha to color effect (386.48 KB, image/png)
2019-10-24 05:37 UTC, vanyossi
Details
Red to Yellow gradient with Orange removed (274.05 KB, image/png)
2024-06-13 14:48 UTC, Estecka
Details

Note You need to log in before you can comment on or make changes to this bug.
Description acc4commissions 2019-10-18 01:59:36 UTC
Created attachment 123304 [details]
capture

SUMMARY
STEPS TO REPRODUCE
1. load any image, preferably the one has some high-saturated colors.
2. Apply Color to Alpha to it, over white background layer.


OBSERVED RESULT
Color changes.

EXPECTED RESULT
The original color is preserved.



Color to Alpha in GIMP does not do this. The color stays exactly the same regardless of its threshold. (Thought It's necessary to change the layer mode to 'legacy' after 2.10 update...)

SOFTWARE/OS VERSIONS
Windows: 
macOS: 
Linux/KDE Plasma: 
(available in About System)
KDE Plasma Version: 
KDE Frameworks Version: 
Qt Version: 

ADDITIONAL INFORMATION
Comment 1 vanyossi 2019-10-18 02:23:32 UTC
did you adjust the trheshold too high??

If you only want to remove pure white you have to adjust threshold to something around 30, any value higher than that will probably make color to alpha remove other colors near white, like yellows.

I do loose some color information if threshold is high.

Tested on 8bit RGB ColorSpace.
Comment 2 acc4commissions 2019-10-18 02:35:59 UTC
(In reply to vanyossi from comment #1)
> did you adjust the trheshold too high??
> 
> If you only want to remove pure white you have to adjust threshold to
> something around 30, any value higher than that will probably make color to
> alpha remove other colors near white, like yellows.
> 
> I do loose some color information if threshold is high.
> 
> Tested on 8bit RGB ColorSpace.

The point is that 'the color shouldn't change as I move the silder'. Sorry for mentioning other applications but in gimp it only scrapes opacity and not the color.
Comment 3 Bug Janitor Service 2019-10-18 04:33:12 UTC
Thanks for your comment!

Automatically switching the status of this bug to REPORTED so that the KDE team
knows that the bug is ready to get confirmed.

In the future you may also do this yourself when providing needed information.
Comment 4 vanyossi 2019-10-24 05:37:57 UTC
Created attachment 123448 [details]
Alpha to color effect

Logic tells me you are right, it should only affect the alpha channel, but In reality as we make a color more transprent it looses saturation to the white below. I don't know how is implemented in gimp 2.10 but it gives me the same results.

Attached image is from gimp Color to alpha. the first two panels I applied  Color to alpha, then converted the alpha from the channel directly into a transparency mask: The first one has the mask turned off, the second one has mask on (in the first on e you see black on fully transparent colors) There is loss in color. The third and last panel: after applying color to alpha I made a selection from that alpha information and applied it as an transparency mask to the original image. The third is with the transparency mask on, and the last one with the transparency mask off (Here we only affect the alpha but we also see loss of color).

Doing the exact same in Krita will yield the same results. Color to Alpha -> Split Alpha -> Alpha into Mask. For the second: Color to Alpha -> Ctrl + Click on layer thumbnail (or Select -> Select Opaque) -> right click on layer: Add Transparency Mask.

However in Krita the preview does seem to shift color. This seems to happen as the Threshold is less agressive and affects much more softly other colors which in turn gives the apperance of a shift in color (less saturated). In Gimp this effect can also be seen but to a lesser extent since the threshold is much more contrasted, in fact its in Krita it is not possible to adjust the threshold to affect the colors in the same way as the gimp.
Comment 5 acc4commissions 2019-10-24 10:06:09 UTC
(In reply to vanyossi from comment #4)
> Created attachment 123448 [details]
> Alpha to color effect
> 
> Logic tells me you are right, it should only affect the alpha channel, but
> In reality as we make a color more transprent it looses saturation to the
> white below. I don't know how is implemented in gimp 2.10 but it gives me
> the same results.
> 
> Attached image is from gimp Color to alpha. the first two panels I applied 
> Color to alpha, then converted the alpha from the channel directly into a
> transparency mask: The first one has the mask turned off, the second one has
> mask on (in the first on e you see black on fully transparent colors) There
> is loss in color. The third and last panel: after applying color to alpha I
> made a selection from that alpha information and applied it as an
> transparency mask to the original image. The third is with the transparency
> mask on, and the last one with the transparency mask off (Here we only
> affect the alpha but we also see loss of color).
> 
> Doing the exact same in Krita will yield the same results. Color to Alpha ->
> Split Alpha -> Alpha into Mask. For the second: Color to Alpha -> Ctrl +
> Click on layer thumbnail (or Select -> Select Opaque) -> right click on
> layer: Add Transparency Mask.
> 
> However in Krita the preview does seem to shift color. This seems to happen
> as the Threshold is less agressive and affects much more softly other colors
> which in turn gives the apperance of a shift in color (less saturated). In
> Gimp this effect can also be seen but to a lesser extent since the threshold
> is much more contrasted, in fact its in Krita it is not possible to adjust
> the threshold to affect the colors in the same way as the gimp.

Can you provide me the original picture of this? In my gimp it only affects the opacity and gives me 0 loss of color. (Remember : You need to change mode of the target layer from 'Default' to 'Legacy' on the top right of the layer docker!)
Comment 6 vanyossi 2019-10-24 23:54:20 UTC
This a link to the original xcf: https://drive.google.com/open?id=1YjfmfWuiI5AMiR7QuYGsZjKx_Wxr-q4u

Im not familiar with the mode you mention in the gimp, but the gimp docs suggests it is a switch to activate legacy blending modes for the dropdown list. If that is the case that would explain why chaning the "mode" does nothing to the ouput of color to Alpha in gimp when I tried out.
Comment 7 acc4commissions 2020-02-24 02:15:07 UTC
https://imgur.com/yabotQ4

Hope this help to reproduce the process.
Comment 8 Estecka 2024-06-13 14:48:19 UTC
Created attachment 170471 [details]
Red to Yellow gradient with Orange removed
Comment 9 Estecka 2024-06-13 14:59:26 UTC
Hi,
I'm a long time user of Gimp, who just started trying out Krita 5.2.2.
Krita's colour to alpha filter indeed works nothing like Gimp's, and no changing the threshold value can fix that:

[Red to Yellow gradient, Orange removed](https://bugs.kde.org/attachment.cgi?id=170471)
At a threshold of 43/255, Krita is both overly agressive on the red side of the gradient, andoverly lenient on the yellow side.
The red side never reaches 100% opacity, while the yellow leaves a large strip that is 100% opaque. Both sides of the gradient still have traces of orange in them, when they should be pure Red or Yellow.

> I don't know how is implemented in gimp 2.10 but it gives me the same results.

As was mentionned, Gimp can be very finicky with its blending, so in order to get the expected result in Gimp you need to either:
- With the Color to Alpha filter, switch the layer's composite space to "Perceptual", or switch the Blend mode to Legacy Normal.
- Or, do not use the Color to Alpha filter, instead use the Bucket Fill tool with the non-legacy "Color Erase" blend mode.

My expectation for this filter is that it should be the opposite operation to the "Behind" blend mode. Removing a colour and then backfilling with the same colour should result in a visually indistinguishable picture. (Safe for arithmetic imprecision.)

I haven't checked the code for Gimp, but intuitively: if the Normal/Behind blend modes are linear interpolations between two colours, then Colour to Alpha/Colour Erase would be a form of linear *extrapolation*. Amongst the line of possible results, it would pick the first colour where any of the RGB channel has reached an extreme (either 0 or 255).
Comment 10 Estecka 2024-11-03 20:48:25 UTC
For fun I tried figuring out how Gimp's colour erase works, and this is what I came up with, and I amble to reproduce the exact same colour code as gimp with this:
https://github.com/Estecka/colour-to-alpha/blob/master/ColourErase.cpp