How about this:
#!/usr/bin/env python
import sys
import OpenImageIO as oiio
# Just take the arg of the input filename.
# Exercise for the reader: alter this program to loop over all arguments
# so you can use wildcards on the command line.
infilename = sys.argv[1]
# Read the image
img = oiio.ImageBuf (infilename)
# For each channel...
for ch in range(img.spec().nchannels) :
# extract just one channel into a second ImageBuf
onechan = oiio.ImageBuf()
oiio.ImageBufAlgo.channels (onechan, img, (ch,))
# optionally change bit depth, e.g.:
# onechan.set_write_format (oiio.UINT8)
# Write the extracted channel as a new image, prepending the
# channel name on the front of the original file name.
chname = img.spec().channelnames[ch]
outfilename = chname + "." + infilename
onechan.write (outfilename)
print ("Channel {} is {} -> {}".format (ch, chname, outfilename))
> On Jun 13, 2016, at 4:27 PM, Sebastian Kral <[email protected]> wrote:
>
> Fully general unfortunately.
>
> I have to find a good way to configure which channels it should down convert
> to a lower bit depth too. Not eager to tackle that though.
>
> On Monday, 13 June 2016, Larry Gritz <[email protected]
> <mailto:[email protected]>> wrote:
> It can certainly split the channels. The question is how much you can script
> totally on the oiiotool command line, or whether it's easier to write a (very
> short) Python script to do it.
>
> Do you already know the number/names of the input channels? Or do you need
> something fully general that will work with any input?
>
>
> > On Jun 13, 2016, at 4:18 PM, Sebastian Kral <[email protected]
> > <javascript:;>> wrote:
> >
> > Hi,
> >
> > I searched through the archive but couldn't find a good answer. Is OIIO the
> > right tool to split our multi channel EXR (tiled) into single channel EXRs
> > (scanline)? Or would you guys recommend something else?
> >
> > If it is the right tool, is there a way to give it a path with a wildcard
> > which it uses to save the channel to?
> >
> > Sorry if the question was answered before. I would think we are definitely
> > not the first to think about this.
> >
> > Cheers,
> > Sebastian
> >
> >
>
> --
> Larry Gritz
> [email protected] <javascript:;>
>
>
> _______________________________________________
> Oiio-dev mailing list
> [email protected] <javascript:;>
> http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org
> <http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org>
>
>
> --
> Sent from mobile device
> _______________________________________________
> Oiio-dev mailing list
> [email protected]
> http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org
--
Larry Gritz
[email protected]
_______________________________________________
Oiio-dev mailing list
[email protected]
http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org