Aha, I think I know what's happening.
JPEG, the format, is always sRGB. The low-level ImageOutput for the most part
just writes whatever raw values you pass it in the pixels. So if you do a
straight read from any format where it presumes the values are linear, then a
straight write to a format where it presumes the values are sRGB (JPEG), you'll
end up with a result image file where the pixel values don't *mean* the same
things those values did in the source file.
oiiotool is smarter for some special cases. In particular, it knows that JPEG
files are required to be sRGB, so upon output to a JPEG file, if the
intermediate results seem like they're not already in sRGB, it will transform
the values before writing to JPEG, which is probably the right guess if you
think that the oiiotool results are correct.
Now, in your python script, you have the following curious code:
# Set input colorspace to linear if converting EXR file
if sourceImgPath.split('.')[-1] == 'exr':
ImageBufAlgo.colorconvert(resizedBuf, resizedBuf, 'linear', 'sRGB')
You *almost* have it. But you are testing to see if the source was exr, but
it's tif, so the color conversion won't happen. I think a more robust solution
might be (assuming you have the output filename in 'destImgPath'):
# If writing to jpeg, convert to sRGB
if destImgPath.split('.')[-1] == 'jpg':
# query input color space, presume linear if there is no such metadata
srcColSpace = sourceImg.spec().get_string_attribute ('oiio:ColorSpace',
'linear')
ImageBufAlgo.colorconvert(resizedBuf, resizedBuf, srcColSpace, 'sRGB')
resizedBuf.write(destImgPath')
This is roughly the logic that oiiotool uses.
Make sense?
> On Dec 28, 2018, at 1:10 PM, Renaud Talon <[email protected]> wrote:
>
> oiiotool.exe C:\temp\ataafm_diff_v001.1005.tif -resize 120x120 -o
> c:/temp/test_oiio_tool.jpg
>
> From: Larry Gritz <[email protected]>
> Sent: Friday, December 28, 2018 1:05 PM
> To: OpenImageIO developers <[email protected]>; Renaud Talon
> <[email protected]>; [email protected]
> Subject: Re: [Oiio-dev] Tiff image conversion to jpg color shift issue
>
> What oiiotool command line did you use when it worked as expected?
>
>
>
> On December 28, 2018 12:36:04 PM PST, Renaud Talon <[email protected]
> <mailto:[email protected]>> wrote:
> Hi Larry,
>
> I’m having a problem when making thumbnails from tiff images where the
> results image is coming out darker and less saturated than the source.
> When using oiiotool.exe it results in a proper output but the issue happens
> when I do the conversion myself from the python API.
> Any idea why this is happening ?
> Thanks !
>
> Trimmed down code:
>
> from OpenImageIO import OpenImageIO as oiio
> from OpenImageIO.OpenImageIO import ImageBufAlgo, ImageBuf, ImageSpec,
> ImageInput
>
>
> sourceImgPath = "C:/temp/ataafm_diff_v001.1005.tif"
>
> sourceImg = ImageInput.open(sourceImgPath)
> spec = sourceImg.spec()
>
> pixels = sourceImg.read_image(0, 3, oiio.UINT8)
>
> sourceBufSpec = ImageSpec(spec.width, spec.height, 3, oiio.UINT8)
> sourceBuf = ImageBuf(sourceBufSpec)
> sourceBuf.set_pixels(oiio.ROI.All, pixels)
>
> resizedImgSpec = ImageSpec(int(120), int(120), 3, oiio.UINT8)
> resizedBuf = ImageBuf(resizedImgSpec)
>
> ImageBufAlgo.resample(resizedBuf, sourceBuf)
>
> # Set input colorspace to linear if converting EXR file
> if sourceImgPath.split('.')[-1] == 'exr':
> ImageBufAlgo.colorconvert(resizedBuf, resizedBuf, 'linear', 'sRGB')
>
> resizedBuf.write('C:/temp/test_oiio.jpg')
>
>
>
>
> Renaud
>
> --
> Larry Gritz
> [email protected] <mailto:[email protected]>
--
Larry Gritz
[email protected]
_______________________________________________
Oiio-dev mailing list
[email protected]
http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org