Search code examples
pythonimageimage-processingtype-conversiontiff

Convert a RAW image to TIFF in python but keep the metadata


I tried converting a raw image to tiff, but I want it to keep the metadata. This is the code I was using earlier:

import rawpy, imageio, os
with rawpy.imread(path) as raw:
   rgb = raw.postprocess()
imageio.imsave('default.tiff', rgb)

Solution

  • If you are interested in, and actively using EXIF data, you will almost certainly need exiftool installed on your machine - a Perl script by Phil Harvey. That being the case, it is probably easiest to do your image processing with rawpy as you are already to produce a TIFF file, then use exiftool to copy forward the EXIF data from your raw file.

    So, in concrete terms, if your raw file is Nikon.nef you would open that and do your rawpy image processing to make Nikon.tif, then shell out (or use the Python binding) and run:

    exiftool -TagsFromFile Nikon.nef Nikon.tif
    

    which will transfer the EXIF data from your raw file to your TIFF file.