Hi. Just wondered if there was a way of saving exr formats with one of the compression options available with exrs. Any ideas?
Hi,
exr output is provided by a plugin. The compression is currently hardcoded, but you should be able to modify the python code directly to set the desired strategy.
HTH
Thanks. I thought that might be the case. I’ll see if I can work it out.
Here’s a quick patch for (lossy) DWA compression:
diff --git a/exr/exr_io.py b/exr/exr_io.py
--- a/exr/exr_io.py
+++ b/exr/exr_io.py
@@ -138,6 +138,7 @@
header['channels'] = {'R': Imath.Channel(tp),
'G': Imath.Channel(tp),
'B': Imath.Channel(tp)}
+ header['compression'] = Imath.Compression(Imath.Compression.DWAB_COMPRESSION)
exr = OpenEXR.OutputFile(opts.output, header)
exr.writePixels({'R' : r.tobytes(), 'G' : g.tobytes(), 'B' : b.tobytes()})
exr.close()
HTH
Hi
Thanks for that.
header[‘compression’] = Imath.Compression(Imath.Compression.DWAB_COMPRESSION) produces a very small file (6
3mb compared to 117Mb) whereas:
header[‘compression’] = Imath.Compression(Imath.Compression.ZIP_COMPRESSION) produces a file of the exact same size as without. (I am using ART-cli) I read the imageio docs and that seems to be the correct string. Not sure if I have mis-understood
I think zip is the default compression, if you want uncompressed you should use NO_COMPRESSION. DWAB is very effective but not fully lossless, though from all I’ve read online the degradation is minimal to non-existent, especially for captured images (as opposed to CGI)
Hi. I have tried to see if I can output half float exr by forcing it like this:
#tp = e_tp(r.dtype)
tp = Imath.PixelType(Imath.PixelType.HALF)
I failed. Is it possible? Have I got it wrong. Python/programming isn’t my strength.
Thanks
Hi,
you can have a look at the latest version of the script in the repository. Basically, if you want 16-bit, just add:
data = data.astype(numpy.half)
right after
data = tifffile.imread(opts.input)
at the beginning of write
. However, if you are already using DWA compression, I think that already automatically enables 16-bit output