![]() |
I want to achieve 2.10 posturize with color-erase blending mode effect in python - Printable Version +- Gimp-Forum.net (https://www.gimp-forum.net) +-- Forum: GIMP (https://www.gimp-forum.net/Forum-GIMP) +--- Forum: Other graphics software (https://www.gimp-forum.net/Forum-Other-graphics-software) +--- Thread: I want to achieve 2.10 posturize with color-erase blending mode effect in python (/Thread-I-want-to-achieve-2-10-posturize-with-color-erase-blending-mode-effect-in-python) |
I want to achieve 2.10 posturize with color-erase blending mode effect in python - Error - 07-12-2023 Hello, I am attempting to make a script of mine more efficient. I am trying to replicate the output of using posterize with the color-erase blending option in python without leaning heavily on gimp. Below is showing how posterize can influence an image's appearance. ![]() As you can see, this is what it looks like when I take the original photo, remove the alpha channel, and posterize. Below is one of the more interesting outcomes for the color-erase blending option when applied with the posterize tool. ![]() The step, by step instructions to get this effect: 1. Open image 2. Remove alpha channel of image by right clicking in layer menu 3. Select posterize from the color dropdown menu in the main window 4. In the posterize menu, select the color-erase blending mode and put the slider anywhere between 3 and 254. Here's how to programmatically achieve the effect with Python-fu for 2.10: Code: groupLayer = pdb.gimp_layer_group_new(image) I'm interested in anything from theorizing, to gimp source-code that can explain how I could replicate this effect. I am curious how it works. If you've made it this far, thank you for reading my post! RE: I want to achieve 2.10 posturize with color-erase blending mode effect in python - Ofnuts - 07-12-2023 The Color erase mode computes the most transparent pixel under which you can stack the erased color to rebuild the initial color. For instance, yif you Color-erase a purple pixel with red, you are left with a partially transparent blue, and if you put this pixel over the erase red, you get the purple back. [attachment=10063]
In your case the result of the posterization is used as a temporary/virtual color-erase layer. If you had an infinite level of posterization, the posterized image would be identical to the source image, and all pixels would be color-erased by a copy of themselves and would turn fully transparent. With normal posterization levels, you color-erase pixels with whatever color the posterization would color them into, which is fairly random because that depends on the rest f the image and the posterization levels.... The only not-too-random part of the result is that since the pixel is replaced by the closest color in the posterization set it will be likely quite transparent. But since you throw away the alpha channel all you see is the residual color, which v very transparent pixels is not that accurate so you have a bit of randomness here too, especially in 8bpc mode.
IMHO you would get very similar results, by 1) color-indexing the image, and 2) assigning random values in the color map.
RE: I want to achieve 2.10 posturize with color-erase blending mode effect in python - Error - 07-16-2024 (07-12-2023, 07:01 AM)Ofnuts Wrote: The Color erase mode computes the most transparent pixel under which you can stack the erased color to rebuild the initial color. For instance, yif you Color-erase a purple pixel with red, you are left with a partially transparent blue, and if you put this pixel over the erase red, you get the purple back. First of all, thank you Ofnuts for your input. It's been a while since I attempted this project. I have nearly succeeded at my process of replicating the desired posterize + color-erase effect using python, numpy, and PIL. I am currently hung up on replicating the exact output of my gimp process. I am only making a new post here because I am pretty stuck. Seems I may have missed some subtle nature of gimp that could be affecting gimp's output versus my limited understanding of the process. I have theorized that it could be something to do any or none of these processes:
Example: Gimp posterize with 2 levels using color-erase blending option: ![]() Python replication of gimp 2.10 posterize and color erase algorithm: ![]() Original image: ![]() If more information is necessary please let me know. I'm appreciative and open to any suggestions on how I can solve this issue. RE: I want to achieve 2.10 posturize with color-erase blending mode effect in python - Ofnuts - 07-16-2024 You are likely working directly on gamma-corrected values instead of "linear light". See my answers in this thread: https://www.gimp-forum.net/Thread-Layer-Mode-Addition-equation-is-working-differently-to-official-guide. Not included in the referenced post but something equivalent exists for layer masks. The gamma-corrected grayscale value of a 50% opacity layer mask is #BC, and a black layer over white or a white layer over black with a mask with #BC will produce a the middle gray which is also #BC. Some more info here: https://en.wikipedia.org/wiki/SRGB#Transformation The python functions that implement the sRGB transforms (and give identical result to Gimp as far as my tests go): Code: import math ... but if you process whole images I hope you are using numpy or equivalent. RE: I want to achieve 2.10 posturize with color-erase blending mode effect in python - Ofnuts - 07-16-2024 So, I had a writeup on this in the works, and finished it, so you can check it here: https://www.gimp-forum.net/Thread-What-is-the-gamma-encoding-and-why-are-my-color-computations-wrong RE: I want to achieve 2.10 posturize with color-erase blending mode effect in python - Error - 07-17-2024 (07-16-2024, 09:38 PM)Ofnuts Wrote: So, I had a writeup on this in the works, and finished it, so you can check it here: https://www.gimp-forum.net/Thread-What-is-the-gamma-encoding-and-why-are-my-color-computations-wrong You were right on the money here Ofnuts! That was the final piece I needed to finish replicating the color-erase posterize effect in python! Now I can finally move onto something else. I dedicate this next PNG to your supreme helpfulness: ![]() |