Removing Alpha Channel? - Printable Version +- Gimp-Forum.net (https://www.gimp-forum.net) +-- Forum: GIMP (https://www.gimp-forum.net/Forum-GIMP) +--- Forum: Extending the GIMP (https://www.gimp-forum.net/Forum-Extending-the-GIMP) +---- Forum: Scripting questions (https://www.gimp-forum.net/Forum-Scripting-questions) +---- Thread: Removing Alpha Channel? (/Thread-Removing-Alpha-Channel--7110) Pages:
1
2
|
Removing Alpha Channel? - david - 07-26-2022 I have been trying to write a script to automate colour cast removal. If an image has transparency it "dilutes" the colour cast I am trying to remove. When I run the following code Code: layerClean = pdb.gimp_layer_new_from_drawable(layer, image) # layer to be cleaned of alpha channel I can look in the channels palette and the alpha channel has gone. In the layers palette I can right-click on the layer and it gives me the option to add an alpha channel. However, if I carry out any action, such as adding a layer, the alpha channel re-appears in the channel palette. I have tried running the code and then doing a "Save as". On loading the saved file, the alpha channel is again in the layers palette. I created an xcf file where the alpha channel was filled with 50% grey (7f7f7f Hex) in order to test. [attachment=8403] I put this into general queries as the same occurs when the actions are carried out manually. Operating system: Ubuntu 20.04 GIMP: 2.10.32 RE: Removing Alpha Channel? - Ofnuts - 07-26-2022 The alpha channel in Channels exists as soon as a layer has an alpha channel (even if fully opaque). However this channel is virtual, it is the composite of all the alpha channels of the visible layers and in itself it has little influence over the output. What you really work with is the alpha channel of individual layers, so you don't have to worry about that one. RE: Removing Alpha Channel? - david - 07-26-2022 @Ofnuts, I probably was not clear with my explanation. I know that the alpha channel in the channels palette is largely virtual. When I clear the alpha channel with the code above the channels palette is as in this image. [attachment=8404] In the layers palette I can right-click and it gives me the option - Add Alpha Channel. If I add a new layer, or if I save and reload the image it shows a 50% grey alpha channel in the layers palette - the same alpha channel that I removed with the above code. But right-clicking in the layers palette still gives me the option Add Alpha Channel. It appears to be a "ghost" alpha channel. If it was the default, I would expect it to be white and I would not have the option Add Alpha Channel. [attachment=8405] Running my routine for removing colour cast on the original image and the one to which I added the 50% alpha layer gives different results which suggests that the colour cast has been diluted by the "ghost" alpha channel. RE: Removing Alpha Channel? - Ofnuts - 07-26-2022 This still means that your problem is with a layer, not with the whole image. The real problem is likely in the code before this. Can you show the whole code? RE: Removing Alpha Channel? - david - 07-26-2022 Code: from gimpfu import * Here is the total code. The same as you have seen already, apart from the parameters of the original image. The subsequent code would create a new layer, pixelated to the maximum dimensions of the image, colour inverted and changed to overlay mode. RE: Removing Alpha Channel? - PixLab - 07-27-2022 (07-26-2022, 08:14 PM)david Wrote: Oh... It's for that thread, that's very nice from you, BTW that's a cool trick with the big pixel averaging the color cast I'm not programmer, but if I may... I would take/compare the longest side of the image after taking the width and the height (on your code) to pixelate at the longest side+1 to sure sure to pixelate a big one pixel to the whole image whatever is portrait or paysage. Maybe something like that? (don't forget, no programmer here, no python knowledge and so, please forgive syntax and error) Code: width = image.width Also, do you really need to "touch" the alpha channel? If a picture has an alpha channel but is opaque (like this photo on your first post), the pixelisation will work just fine. If a picture has an alpha channel with some transparencies parts, removing the alpha channel will fill the transparency with the active BG color, thus if the active BG color was set to something exotic(or not), when the pixel will average the color cast, it will take in count the BG fill of the transparency as well, thus the averaging will be off, no? Just a thought RE: Removing Alpha Channel? - david - 07-27-2022 @PixLab, All credit for using pixelate to average the colour of an image must go to Krikor. He came up with the idea and Tin Tran programmed it into a plug-in. I decided that I could create a plug-in with a little more flexibility by adding a desaturated layer of the original image in overlay mode (initially set at 50% opacity) which allows subsequent adjustment of contrast. This works quite well as a one-click way of removing a colour cast. The next step was to make it work for images with an alpha channel (and ideally re-instate the alpha channel on completion), because transparency "dilutes" the effect of the colour cast reduction. This was where my problems started! You say that you are not a programmer - I suspect you have more programming knowledge than I do. My only programming experience was some 40 years ago, in assembly language on 8 and 16 bit processors, which was simple and logical! I attach the plug-in which works OK for images without alpha channel in case it is of interest to you. [attachment=8411] RE: Removing Alpha Channel? - rich2005 - 07-27-2022 Dare I mention but Ofnuts has a good averaging plugin ofn-average-fill.py dated 2017-01-09 ...from the usual place http://sourceforge.net/projects/gimp-tools/files/scripts/ (hate those smart links, spent endless hours telling my sister not to click on them) RE: Removing Alpha Channel? - david - 07-27-2022 Update! By copying my original layer into a new RGB layer (and I delete the original) I get the same result on images with or without alpha channel. I have yet to find out how to save the alpha channel and re-insert it at the end of the program. The latest version: [attachment=8414] RE: Removing Alpha Channel? - Ofnuts - 07-27-2022 Tried with an image of mine and results with and without an alpha channels are identical. Now, there is an alpha channel, and there are partially opaque pixels, you can have the first without the second. So if you problem is that partially opaque pixels in the copies (layer_copy and layer_copy1) are skewing the result of the contrast/color layers overlay, you can just make these two layers totally opaque by using : Code: if layer.has_alpha: |