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

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
blair
Posts: 7
Joined: 2016-08-07T17:46:35-07:00
Authentication code: 1151

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

Post 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!
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post 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.
snibgo's IM pages: im.snibgo.com
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

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

Post 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
blair
Posts: 7
Joined: 2016-08-07T17:46:35-07:00
Authentication code: 1151

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

Post 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.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post 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.
snibgo's IM pages: im.snibgo.com
Post Reply