0

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:

  1. The output JPG is distorted. My guess is that there's lens distortion that is not rectified during the conversion process.
  2. 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.

Jeff
  • 101
  • 8
  • First, [this](https://photo.stackexchange.com/questions/41327/why-do-raw-images-look-worse-than-jpegs-in-editing-programs). Of course, Apple software can recognize pictures taken with Apple hardware. IM can probably [correct the lens distortion if you have lens calibration data for your iPhone](https://legacy.imagemagick.org/Usage/lens/) (either you find it in the wild, or you create it). Now, what is the point of using DNG and automating DNG conversion if all you want is the same JPG as produced by the camera? – xenoid May 01 '23 at 09:47
  • Thanks for that first link. Yes Apple can display it nicely... that means I should be able to, too. Also, Windows thumbnails and Photos app displays it nicely. As for why I want to do this... I have a use case. – Jeff May 02 '23 at 13:10
  • @xenoid If the answer to this question is "every DNG viewer makes its own attempt at post-processing, which may or may not use metadata embedded in the image", feel free to post an answer and maybe link out to that first link you included. – Jeff May 02 '23 at 13:20

0 Answers0