Making all green areas of a PNG transparent
Posted: 2017-07-04T12:33:54-07:00
Hello --
I am trying to make all green areas of a PNG file transparent. That would include any pixels where the green is mixed with another color for anti-aliasing purposes. Here's what I initially tried:
This works almost as expected. However, I can see some light transparent green pixels around the edges of objects where there was anti-aliasing. I have seen solutions where the fuzz switch is used; this is an unacceptable solution because I want the input image to resemble the output image as closely as possible. I just want the green channel gone.
I have a workaround, which assumes that the final image is grayscale, but I would like to come up with a solution that will work with color images as well. Here's my workaround:
Again, this workaround is not ideal. How can I swap out all of the green with the appropriate level of transparency and not resort to using the fuzz switch?
I am trying to make all green areas of a PNG file transparent. That would include any pixels where the green is mixed with another color for anti-aliasing purposes. Here's what I initially tried:
Code: Select all
convert.exe "D:\junk\01_original.png" -colorspace RGB -separate -negate "D:\junk\02_mask.png"
convert.exe "D:\junk\01_original.png" -alpha Off "D:\junk\02_mask-1.png" -compose CopyOpacity -composite PNG32:"D:\junk\03_alpha.png"
I have a workaround, which assumes that the final image is grayscale, but I would like to come up with a solution that will work with color images as well. Here's my workaround:
Code: Select all
convert.exe "D:\junk\01_original.png" -colorspace RGB -separate -negate "D:\junk\02_mask.png"
convert.exe "D:\junk\01_original.png" -alpha Off "D:\junk\02_mask-1.png" -compose CopyOpacity -composite PNG32:"D:\junk\03_alpha.png"
convert.exe "D:\junk\03_alpha.png" -colorspace Gray "D:\junk\04_alpha_grayscale.png"
convert.exe "D:\junk\04_alpha_grayscale.png" -colorspace RGB "D:\junk\05_final.png"