Search code examples
openimageio

Combine image channels of two images using oiiotool


There is command in the oiiotool to swap the channels of a image by using the --ch command like so:

oiiotool rgba.tif --ch R=B,G,B=R,A -o bgra.tif

What Im asking is if there is an option to load two images to the stack and add lets say the Red channel from Image A to the green channel of image B.


Solution

  • In case somebody needs the answer here it is:

    oiiotool A.exr --ch R  B.exr --ch B  --chappend  A.exr --ch G  --chappend  --chnames R,G,B  -o mix.exr
    

    To break down what that means,

    * read A, take just its R channel
    * read B, take just its G channel
    * Append channels of the the top two images, yielding A.r,B.g on the top of the stack
    * read A again, take just its B channel
    * Append the channels of the top two images, now you have A.r,B.g,A.b
    * Force new channel names R,G,B just in case they carry their old names or got confused
    * Output to mix.exr