0

I'm trying to convert a bunch of 32bit OpenExr files to 8 bit tifs.

For the conversion process, I used the python recipes provided in the oiio documentation.

The conversion from exr to tif worked fine, but I get nothing if I add in the bit rate that I wanted as a parameter (exactly following the python formula from documentation)

I then later tried just converting the file formats first, then using the ImageBufAlgo.colorconvert but I just get thrown a lot of error messages instead.

What I wanted to do was just turn the 32bit image and reduce it to 8bit with the correct gamma setting.

First I tried

    python
image = 'C/.../image.exr' # grabbing file from network
buf = oiio.ImageBuf(image)
buf.write(texture_directory + 'outImage.tif', "uint8")

This didn't work at all. The code ran, but there was no images in the directory I specified.

Then I changed it to

    python
image = 'C/.../image.exr' # grabbing file from network
buf = oiio.ImageBuf(image)
buf.write(texture_directory + 'outImage.tif')

And this worked! I had the images, except they are all 32bit files, which I need to change to 8bit.

So I thought I would try looping over the new tif images and then doing the color conversion in seperate steps. I tested out just one image to see if I could even get the colorconvert function working.

    python
new_buf = oiio.ImageBuf('outImage.tif')
dst = oiio.ImageBufAlgo.colorconvert(new_buf, "sRGB", "linear")

Exactly as the documentation had it. Instead what I got was a bunch of error messages that weren't too dis-similiar to the ones I had been getting in the extract pixel color problem I had yesterday initially


Error: Python argument types in
#     ImageBufAlgo.colorconvert(ImageBuf, str, str)
# did not match C++ signature:
#     colorconvert(class OpenImageIO::v1_5::ImageBuf {lvalue} dst, class OpenImageIO::v1_5::ImageBuf src, class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > from, class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > to, bool unpremult=False, struct OpenImageIO::v1_5::ROI roi=<OpenImageIO.OpenImageIO.ROI object at 0x00000257C97A6348>, int nthreads=0)
# Traceback (most recent call last):
#   File "<maya console>", line 27, in <module>
# ArgumentError: Python argument types in
#     ImageBufAlgo.colorconvert(ImageBuf, str, str)
# did not match C++ signature:
#     colorconvert(class OpenImageIO::v1_5::ImageBuf {lvalue} dst, class OpenImageIO::v1_5::ImageBuf src, class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > from, class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > to, bool unpremult=False, struct OpenImageIO::v1_5::ROI roi=<OpenImageIO.OpenImageIO.ROI object at 0x00000257C97A6348>, int nthreads=0) # 

Would really appreciate any help and explanation as to what I'm not getting.

Edit: I'm adding the 1.7 code I tried following Larry's reply:

src = ImageBuf(filename)
dst = ImageBuf()
result_bool = ImageBufAlgo.colorconvert (dst, src, 'sRGB', 'linear')

The error message I got is this:

# Error: Python argument types in
#     ImageBufAlgo.__init__(ImageBufAlgo, ImageBuf, ImageBuf, str, str)
# did not match C++ signature:
#     __init__(struct _object * __ptr64)
# Traceback (most recent call last):
#   File "<maya console>", line 32, in <module>
# ArgumentError: Python argument types in
#     ImageBufAlgo.__init__(ImageBufAlgo, ImageBuf, ImageBuf, str, str)
# did not match C++ signature:
#     __init__(struct _object * __ptr64) #
XJZeng
  • 13
  • 5

2 Answers2

0

Not sure if this will help, but you can use the iconvert cli that is shipped with openimageio, which is used for converting image formats and bit depth.

iconvert -d uint8 in.exr out.tif

https://openimageio.readthedocs.io/en/latest/iconvert.html

user1767754
  • 23,311
  • 18
  • 141
  • 164
  • Hey, thanks for the reply! Is this command line or terminal commands (i.e, unix terminal)? Unfortunately I'm on windows and the requirement is to run it as a python script. Is it possible to run that as a python command? – XJZeng Oct 25 '19 at 19:27
0

You are reading documentation that corresponds to a newer version of OIIO than you are using.

In the first problem, you are calling

buf.write (filename, dtype="", fileformat="")

and that would work with OIIO 2.x, where the second argument is the data type. But for OIIO 1.x, the function signature was

buf.write (filename, fileformat="")

so it thinks you are specifying a file format (that it doesn't know, so it reverts to TIFF because you named your file ending in ".tif").

The second problem you describe is similar: the particular form of

dst_img = ImageBufAlgo.colorconvert (src_img, fromspace, tospace)

is only in OIIO 2.0. In OIIO 1.x, it looked like

result_bool = ImageBufAlgo.colorconvert (dst_img, src_img, from, to)

So the bottom line is, either use OIIO 1.x documentation, or else use OIIO 2.x libraries.

Larry Gritz
  • 13,331
  • 5
  • 42
  • 42
  • Hey Larry, thanks! I really appreciate how you are on top of questions regarding OpenImageIO. I tried using the 1.x example (from version 1.7 documentation) you cited. I'm still getting errors about my parameters though. I'm putting up my code in the top level comment, but I want to ask you if there's a command to find out the version number of the installed library? I don't have a lot of support wrt using oiio (because my studio doesn't use it extensively), so I have to find my own solutions. – XJZeng Oct 25 '19 at 19:20
  • @XJZeng : OpenImageIO.VERSION_STRING – Larry Gritz Nov 23 '19 at 05:13