My goal is simple: use python on Windows to convert from DNG to JPG, maximizing quality and carrying through metadata (e.g. EXIF). I've tried a few things, but this is the best I've found:
from PIL import Image
import rawpy
def convert_dng_to_jpg_b(input_dng_file, output_jpg_file):
with rawpy.imread(input_dng_file) as raw:
rgb = raw.postprocess(
use_camera_wb=True,
output_color=rawpy.ColorSpace.sRGB,
)
image = Image.fromarray(rgb)
image.save(output_jpg_file, format='JPEG', quality=100)
I've tried this on a few files and found that the output JPG has two problems (that I know of) relative to the input DNG:
- The output JPG is distorted. My guess is that there's lens distortion that is not rectified during the conversion process.
- The output JPG is too dark. Again, my guess is that there's some brightness/exposure adjustment that is not being applied/respected during the conversion process.
I've tried to get imageio's FreeImage plugin working, but had all sorts of trouble getting it to read the DNG file.
I'd be very willing to use some non-python external tool (and call it from python), as long as it was easy to get running on Windows via command line and fit my requirements. I'd also be fine copying over EXIF/metadata as a separate step, if the main work of image data conversion doesn't happen to do so (as in my example code above).
If it helps/matters, the input DNG is from an iPhone, and apps like Photos, Mac OS Preview, Mac OS Quick View, Windows Thumbnails, and Windows Photos are all able to show the DNG image the way I'd expect (not distorted, "correct" brightness).
Update:
I've also tried command line tools like imagemagick and dcraw:
> magick dng:1.dng 1.jpg
> dcraw -v -w -q 3 -T 1.dng
Using imagemagick, the output had both of the above 2 mentioned problems, plus a lack of white balance adjustment.
Using dcraw, the output had both of the above 2 mentioned problems.