So, I have two images that are nearly identical, the alpha channel should be the same between both images, but one of the images has a white background and the character has a different color, while the other image has a transparent background. Other than that, the alpha channel should be the same between both images.
I've seen a method of how to restore a transparent background with two of the same image when one of the backgrounds is white and the other one is black, but I was wondering if it's possible to restore a transparent background to an image where you have one transparent and the alpha channel should be the same, but for instance, the character's clothes are a different color. Simply copying the alpha channel to the other image doesn't work because it leaves "white residue" from the background in semi-transparent areas.
If possible, would there be a method to restore it if a semi-transparent area is a different color in the image?
Restore transparent background with a different image.
-
- Posts: 27
- Joined: 2016-03-11T07:27:11-07:00
- Authentication code: 1151
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Restore transparent background with a different image.
What version of IM? On what platform?
Please supply sample inputs and desired output.
My pages Inverse composites and Watermarks may be relevant.
Please supply sample inputs and desired output.
My pages Inverse composites and Watermarks may be relevant.
snibgo's IM pages: im.snibgo.com
-
- Posts: 27
- Joined: 2016-03-11T07:27:11-07:00
- Authentication code: 1151
Re: Restore transparent background with a different image.
Image Magick is version 7.0.7-Q16 on 64-bit Windows
Sample input (Transparent)
Sample Input (Background)
Sample Output
Sample input (Transparent)
Sample Input (Background)
Sample Output
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Restore transparent background with a different image.
I've named your "Sample input (Transparent)" as "intrans.png".
I've named your "Sample Input (Background)" as "inback.png". This is fully opaque. The two images are the same size.
I think you want this: copy the alpha channel from intrans.png to inback.png. That's easy: "-compose CopyOpacity -composite". That is fine where alpha is 0.0 or 1.0. The problem is where pixels are partially transparent.
We can regard inback.png as some unknown image inxx.png (that has transparency) flattened (with "-compose Over") against an opaque white background. The task is to find image inxx.png.
Watermarks gives a solution.
First, make an image of the opacity:
... and a white version:
Calculate the unknown image inxx.png:
I've named your "Sample Input (Background)" as "inback.png". This is fully opaque. The two images are the same size.
I think you want this: copy the alpha channel from intrans.png to inback.png. That's easy: "-compose CopyOpacity -composite". That is fine where alpha is 0.0 or 1.0. The problem is where pixels are partially transparent.
We can regard inback.png as some unknown image inxx.png (that has transparency) flattened (with "-compose Over") against an opaque white background. The task is to find image inxx.png.
Watermarks gives a solution.
First, make an image of the opacity:
Code: Select all
magick intrans.png -alpha extract inalpha.png
... and a white version:
Code: Select all
magick intrans.png -fill White -colorize 100 inwhite.png
Code: Select all
call %PICTBAT%findWater2 inwhite.png inback.png inalpha.png inxx.png
snibgo's IM pages: im.snibgo.com