07-12-2023, 01:37 AM
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:
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!
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)
srcLayer = pdb.gimp_layer_copy(image.layers[0], False)
eraseLayer = pdb.gimp_layer_copy(image.layers[0], False)
#Insert layer group with two layers inside
pdb.gimp_image_insert_layer(image,groupLayer, None, -1)
pdb.gimp_image_insert_layer(image, srcLayer, image.layers[0], -1)
pdb.gimp_image_insert_layer(image, eraseLayer, image.layers[0], -1)
#Posterize erase layer, then set paint mode to Color Erase
pdb.gimp_layer_set_mode(eraseLayer, 57)
pdb.gimp_drawable_posterize(eraseLayer, amount)
#transfer grouplayer alpha to new mask, then fill alpha with white
mask = pdb.gimp_layer_create_mask(groupLayer, 3)
pdb.gimp_layer_add_mask(groupLayer, mask)
pdb.gimp_drawable_edit_fill(mask, 2)
# Apply mask and merge group
pdb.gimp_image_merge_layer_group(image, image.layers[0])
pdb.gimp_layer_remove_mask(image.layers[0], 0)
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!