I have a set of normal maps that were separated into their red and green channels for upscaling. Now I want to recombine them with an solid white blue channel, but I'm struggling to find an efficient way to make that white blue channel.
My current code does actually work:
magick "file_r.png" "file_g.png" ( -size 2048x2048 xc:white ) -combine "file.png"
But having to create that image for the blue channel doesn't seem ideal. Is there a better way?
(Also the size isn't static, so it would have to be retrieved each time -- entirely doable since it's being run by a powershell script and I can at the very least run an identify command (magick identify -ping -format "%[w]x%[h]" "file_r.png"
, which I fear may be legacy code but can't work out how to convert it to v7) beforehand to generate the dimensions, but it seems like more overhead. (I also tried putting an identify command after -size
to put the dimensions in the command dynamically, but I couldn't get the syntax right. It also doesn't necessarily solve the efficiency issue, but if there's a way to do it I would love to know!))
This thread on the legacy ImageMagick forums seemed like a better solution: it says that any channels undefined by -channel
would become the -background
colour, which seems to me like it would be more efficient since it wouldn't have to create an image (I could be wrong, it could be doing the exact same thing internally). This is their code:
convert r.jpg g.jpg -background black -channel RG -combine combined.jpg
But when I tried, the red and green channels were perfect but the blue channel had the red file's image as well rather than pure white:
magick "file_r.png" "file_g.png" -background white -channel RG -combine "file.png"
Has this behaviour changed in version 7, or (more likely) am I doing it wrong? The input files are sRGB rather than grey since that's what the upscaler outputs; perhaps the blue channel of the red channel's image (which is identical to its other channels since it was originally grey) is being put there instead? I've played around with that command by trying to specify individual channels of the two images for the inputs but I couldn't get it to work (which may be my syntax; I'm new to ImageMagick and I've been struggling with its commands even with the documentation).
Thank you!
Perhaps this is what you want in ImageMagick.
magick r.png g.png g.png -combine -channel b -evaluate set 100% +channel result.png