Hi Larry,
Thanks for fixing the issue, I’ll recompile v2.0 dev branch to get the update.
I’m still using v1.8 since I was able to compile 2.0 shortly after release but
didn’t have time to test it yet.
Please note that using the line below on the tiff file I sent you is
problematic since OIIO can’t retreive the colorspace from the tiff file (which
I believe is sRGB) and therefore defaults to “linear” which results in a
lifted/desaturated output image since it is doing an unessesary linear to sRGB
conversion.
However the same code works well on EXRs since the source image colorspace is
properly retrieved.
I also removed the hard coded channel count and used sourceBuf.spec().nchannels
instead, which seems safer.
>> srcColSpace = spec.get_string_attribute('oiio:ColorSpace', 'linear')
Simplifying the read code also works great.
Thanks again for your help.
FULL CODE:
import sys
sys.path.append(r'S:\outfit\shared\FFXPipeline\FFX')
from OpenImageIO import OpenImageIO as oiio
from OpenImageIO.OpenImageIO import ImageBufAlgo, ImageBuf, ImageSpec
sourcePath = "C:/temp/ataafm_diff_v001.1005.tif"
# sourcePath = "C:/temp/ataafm_diff_v001_tiled.1005.exr"
destImgPath = "C:/temp/test_oiio.jpg"
sourceBuf = ImageBuf(sourcePath)
spec = sourceBuf.spec()
resizedImgSpec = ImageSpec(int(120), int(120), spec.nchannels, oiio.UINT8)
resizedBuf = ImageBuf(resizedImgSpec)
ImageBufAlgo.resample(resizedBuf, sourceBuf)
# Set input colorspace to linear if converting EXR file
if sourcePath.split('.')[-1] == 'exr':
srcColSpace = spec.get_string_attribute('oiio:ColorSpace', 'linear')
ImageBufAlgo.colorconvert(resizedBuf, resizedBuf, srcColSpace, 'sRGB')
resizedBuf.write(destImgPath)
From: Renaud Talon
Sent: Monday, December 31, 2018 1:06 PM
To: 'Larry Gritz' <[email protected]>; 'OpenImageIO developers'
<[email protected]>; '[email protected]'
<[email protected]>
Subject: RE: [Oiio-dev] Tiff image conversion to jpg color shift issue
Hi Larry, thanks a bunch for your help.
I tried the code you sent me which attempts to read the colorspace of the input
image and the result is a now a brighter and desaturated image.
I uploaded the tiff image I’m using as a source so hopefully you can see the
same result on your end.
[cid:[email protected]]
Test Tiff image:
http://s000.tinyupload.com/?file_id=10327734964867955756<http://s000.tinyupload.com/index.php?file_id=10327734964867955756>
Updated Code Sample:
import sys
from OpenImageIO import OpenImageIO as oiio
from OpenImageIO import ImageBufAlgo, ImageBuf, ImageSpec, ImageInput
sourcePath = "C:/temp/ataafm_diff_v001.1005.tif"
destImgPath = "C:/temp/test_oiio.jpg"
sourceImg = ImageInput.open(sourcePath)
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 sourcePath.split('.')[-1] == 'exr':
ImageBufAlgo.colorconvert(resizedBuf, resizedBuf, 'linear', '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)
From: Renaud Talon
Sent: Friday, December 28, 2018 1:10 PM
To: 'Larry Gritz' <[email protected]<mailto:[email protected]>>;
OpenImageIO developers
<[email protected]<mailto:[email protected]>>;
[email protected]<mailto:[email protected]>
Subject: RE: [Oiio-dev] Tiff image conversion to jpg color shift issue
oiiotool.exe C:\temp\ataafm_diff_v001.1005.tif -resize 120x120 -o
c:/temp/test_oiio_tool.jpg
From: Larry Gritz <[email protected]<mailto:[email protected]>>
Sent: Friday, December 28, 2018 1:05 PM
To: OpenImageIO developers
<[email protected]<mailto:[email protected]>>; Renaud
Talon <[email protected]<mailto:[email protected]>>;
[email protected]<mailto:[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')
[cid:[email protected]]
Renaud
--
Larry Gritz
[email protected]<mailto:[email protected]>
_______________________________________________
Oiio-dev mailing list
[email protected]
http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org