Page 1 of 1

Extract largest thumbnail / preview image from RAW (NEF/CR2) image file, automatically

Posted: 2016-09-11T12:52:08-07:00
by blair
How does one automatically extract the largest thumbnail/preview JPEG file from a RAW image file?

I could have sworn I figured out how to do this with convert, but I can't remember for the life of me how I did it.

The best I've found today is exiv2, using the '-e' operator with the 'p' option. This extracts all three preview image files:

Code: Select all

Preview 1: image/tiff, 160x120 pixels, 57600 bytes
Preview 2: image/jpeg, 570x375 pixels, 95510 bytes
Preview 3: image/jpeg, 4288x2848 pixels, 780844 bytes
I remember pretty clearly using an option with some command-line tool (perhaps it was not Imagemagick's convert?) which automatically extracted that third preview image, at 4288x2848 pixels. I want that third image because it's closest to the original NEF.

Can anybody correct or refresh my memory? Thanks!

Re: Extract largest thumbnail / preview image from RAW (NEF/CR2) image file, automatically

Posted: 2016-09-11T13:13:01-07:00
by snibgo
For a file from a Nikon D800 camera, exiftool shows:

Code: Select all

 Composite:JpgFromRaw='(Binary data 2307391 bytes, use -b option to extract)'
 Composite:OtherImage='(Binary data 918709 bytes, use -b option to extract)'
 Composite:PreviewImage='(Binary data 101723 bytes, use -b option to extract)'
ImageMagick can't see these images. They can be extracted by exiftool:

Code: Select all

exiftool -JpgFromRaw -b AGA_2983.NEF >fromraw.jpg
exiftool -OtherImage -b AGA_2983.NEF >other.jpg
exiftool -PreviewImage -b AGA_2983.NEF >preview.jpg
Note this this reads binary data and dumps it into a file with a JPG extension, but i've seen no guarantees that these are actually JPEG images. However, they always are.

Re: Extract largest thumbnail / preview image from RAW (NEF/CR2) image file, automatically

Posted: 2016-09-11T13:39:11-07:00
by Bonzo
I have extracted the thumbnail image from a jpg in the past but it could have been nearly 10 years ago and I can not remember how I did it. I have had a look through the forum and I can not find the thread but I found this one: viewtopic.php?f=1&t=8141&hilit=extract+thumbnail

Re: Extract largest thumbnail / preview image from RAW (NEF/CR2) image file, automatically

Posted: 2016-09-11T14:35:28-07:00
by blair
Thanks for the replies! I started playing with exiftool. The JpgFromRaw option does basically what I want.

Somewhat unrelated, I have noticed the NEF displays much more "nicely" in photoshop than the exiftool-outputted preview does. The preview is darker. I guess making a preview which most closely resembles the photoshop presentation would require some kind of conversion. Is that even worth trying? Seems like it could be an "eye of the beholder" kind of thing - no precise answer.

Re: Extract largest thumbnail / preview image from RAW (NEF/CR2) image file, automatically

Posted: 2016-09-11T15:10:40-07:00
by snibgo
blair wrote:Seems like it could be an "eye of the beholder" kind of thing - no precise answer.
Correct.

The NEF file is a linear mosaic with weird colour balance between the 3 channels. The JPG is demosaiced sRGB with "corrected" balance. There is probably a wealth of other corrections including tone, contrast, saturation, and sharpness.

Part of the art of (digital) photography is making the "best" image from the raw data (or negative). Camera and computer software generally does a decent job.

But if you don't like the result, it's better to start from the raw data, not a JPEG version.