Replace/Copy by Color Mask
Posted: 2017-01-19T07:35:50-07:00
Hello.
I need to partially replace first image by second. Both have transparency. But second image have build-in mask which is flat color (for example magenta). This part should stay untoched from first image and all other must be completely replaced (including transparency). I've tried many different methods but none give correct result.
Most closely to ideal result is:
convert i0.png i1.png -fx "u[1].r==1 && u[1].g==0 && u[1].b==1 && u[1].a==1 ? u[0] : u[1]" r.png
But it very slow and dispose of transparent color which make edges little sharper.
Also simple:
convert i0.png i1.png m.png -compose copy -composite r.png
(m.png is extracted mask from second image)
Doesn't copy alpha channel from second image.... Isn't it should? ("This operator is also very similar to 'Over', except that the transparency of the source image is also copied, replacing the background image completely.")
Is there a correct solution for this? (ImageMagick-7.0.4-Q16 Win7)
I need to partially replace first image by second. Both have transparency. But second image have build-in mask which is flat color (for example magenta). This part should stay untoched from first image and all other must be completely replaced (including transparency). I've tried many different methods but none give correct result.
Most closely to ideal result is:
convert i0.png i1.png -fx "u[1].r==1 && u[1].g==0 && u[1].b==1 && u[1].a==1 ? u[0] : u[1]" r.png
But it very slow and dispose of transparent color which make edges little sharper.
Also simple:
convert i0.png i1.png m.png -compose copy -composite r.png
(m.png is extracted mask from second image)
Doesn't copy alpha channel from second image.... Isn't it should? ("This operator is also very similar to 'Over', except that the transparency of the source image is also copied, replacing the background image completely.")
Is there a correct solution for this? (ImageMagick-7.0.4-Q16 Win7)