NEF, Color Space Settings, and Embedded JPGs

This post is not likely of interest to regular readers of my blog (“Hi Mom”); I'm putting it here mostly for the search engines.


A Nikon D200 dSLR has two color-space settings: sRGB and Adobe RGB. People often ask which should be selected when shooting in raw mode, with the oft-provided answer that “it doesn't matter” because raw data has its own camera-specific raw-sensor-data color space, and sRGB vs. AdobeRGB comes in to play only when converting the raw sensor data to a different image format (e.g. JPEG).

Indeed, the color-space setting doesn't matter for the main picture, which is what people are generally asking about, so “it doesn't matter” is a good first approximation of the answer.

However, even when shooting raw, there are effects to the resulting NEF file from the on-camera color-space setting, so I thought I'd document them here for completeness:

  • The MakerNotes:ColorSpace metadata reflects the setting (“sRGB” vs. “Adobe RGB”).

  • The setting determines the color space for two JPEG images embedded within the NEF. The embedded JPEG images have no metadata of their own, so the only indication of their color space is the NEF's MakerNotes:ColorSpace metadata.

  • The setting determines the name of the NEF file: with sRGB, it's of the pattern “DSC_0001.NEF”, and with Adobe RGB, it's of the pattern “_DSC0001.NEF” (see D200 manual, English version, page 29).

Perhaps surprisingly, a NEF (at least a D200-produced NEF) contains two embedded JPEG images:

  • A small (570 × 375) “preview image”

  • A full-frame (3,872 × 2,592) “JPEG from raw” image, which is identical to the image inside a Large-size Basic-quality JPEG produced with the camera's JPEG Compression set to “Size Priority” (manual page 30).

Together, the two embedded JPGs add about 9-10% to the size of a compressed NEF.

It's interesting to note that if you shoot both raw and JPEG at the same time, you end up with six versions of the same picture, in two files:

  1. Raw full-frame sensor data in .NEF file
  2. Small (570 × 375) “preview image” JPEG embedded in the .NEF file
  3. Full-frame basic-quality size-priority-compression “JPEG from raw” embedded in the .NEF file
  4. Main JPEG image in the .JPG file whose size depends on the Image Size setting (manual page 32)
  5. Tiny (120 × 160) JPEG thumbnail embedded in the .JPG file
  6. Small (570 × 375) “preview image” embedded in the .JPG file

Images 3 and 4 are identical if the camera is set to produce Large Basic-quality size-priority JPEGs. The resulting .JPG file has a lot of metadata that the embedded “JPEG from raw” doesn't have, of course.

If you have Phil Harvey's most excellent ExifTool (now available in a Windows stand-alone executable), you can easily extract these embedded images:

  exiftool -b -PreviewImage   file.NEF > file-Preview.jpg
  exiftool -b -JpgFromRaw     file.NEF > file-FromRaw.jpg
  exiftool -b -PreviewImage   file.JPG > file-Preview.jpg
  exiftool -b -ThumbnailImage file.JPG > file-Thumb.jpg

Again, be warned that none of these extracted images have any metadata, including an indication of their color space.


All 8 comments so far, oldest first...

Hey! I’m regular (Hello Jeffrey’s Mom) around here now and I thought this was interesting.

I wonder if this is the same on a D70? I’m still saving for a D200. And may be saving for ever as every time I get some traction with savings, I end up needing to use them for something else! I had to purchase a flash this week to help with some event photography for a friend. Grrrr. I want to shoot landscapes, what on earth do I need a flash for? I’ve gotta start practicing my psychotic look so that people don’t ask for so many favours. 🙂

— comment by Simon P. Chappell on December 8th, 2006 at 11:16pm JST (17 years, 4 months ago) comment permalink

I know my D80 includes a small image in the NEF because I see it in thumbnail views on programs that don’t understand NEF files. The D80 is also compressed-NEF, which I didn’t like at first but have decided that is worth the smaller file size. I usually shoot RAW+JPEG and only use the NEF file if the image is something special and needs some touch-up. (Here’s my article on RAW vs JPEG.)

— comment by Brian White on December 9th, 2006 at 12:03am JST (17 years, 4 months ago) comment permalink

This is news to me. I just cannot believe how much space is wasted on my memory card! I suppose the embedded files help to speed up previewing the shot on the computer, but I really think I could do without them. Makes me think that I’ll need a lot more memory cards – feels like the camera vendors cooperate with the memory card makers!? At least we’re past the megapixel hype race for now. Thanks for your research Jeff!

— comment by Stefan on December 20th, 2006 at 7:43pm JST (17 years, 4 months ago) comment permalink

(I’m reading this thread because of a reference (without link) in the Adobe Lightroom 1.1 forum regarding exported jpegs having major color/exposure differences from the image displayed in LR.)

Yes, it should have no effect whatsoever.

It would seem to me that the color space selection you discuss here should *not* have any effect on the jpegs produced from a LR export (from RAW). Is that true? If not, then where might I find some guidance on why I am experiencing this problem? (I have a D200 and LR 1.1).

Thanks,
dds

When you re-import a JPG you’ve just exported (perhaps after changing the name so that it doesn’t conflict with the NEF you just exported from), does it look okay once in LR again? How about when viewing with Photoshop or Elements? How about with Safari (mac or win)?

The first thing I think of is that you’ve got your system monitor profile somehow set wildly wrong, and so anything that uses it (LR, Photoshop) will distort things, but things that don’t use it (Firefox, IE, most Windows image viewers) won’t be as wrong….

—Jeffrey

— comment by Dennis Steinauer on July 16th, 2007 at 6:30am JST (16 years, 9 months ago) comment permalink

Hy,

I’ve read your post, it’s great !

But, I’m wondering wheter all of this also applies to Nikon D70 (that I own).

I’ll try to be more clear.

I shoot in RAW + Basic Jpg and set COlor Space to Adobe.

Well.

The embedded large size, basic quality, no metadata jpg file in the .NEF seems to be coded as sRGB and NOT as Adobe98, even though Color II was set.

That is, no matter what Color Space is specified, the embedded jpg in .NEF will always be standard sRGB, the jpg file created togheter with the .NEF is instead coded with the requested color space.

Do you also agree on this ?

Is D70 embedded jpg coding policy different from D200 ?

Lemme Know.

PS : I’m from Rome Italy, don’t bother my bad English !

Thanks,

Enzo

I have not tested with a D70, but I’m surprised to hear that it’s different. With the D200, the embedded JPGs definitely differ depending on the color space chosen. —Jeffrey

— comment by Enzo on February 20th, 2008 at 7:38pm JST (16 years, 2 months ago) comment permalink

So, going back to the original question… Now that we know that there are differences, which color space would be better? I’m guessing sRGB.

It’s like asking “which measuring system is best?” — and the answer is the same: “It depends.” A lot of the relevant issues are discussed in my Introduction to Digital-Image Color Spaces writeup.

— comment by Larry Truesdale on May 1st, 2008 at 4:26pm JST (16 years ago) comment permalink

Hi jeffrey
Thanks for NEF, Color Space Settings, and Embedded JPGs.
I have bought Nikon D3100 but cant find a detailed explanation of the image files structures or tools to examine them.
So it seems odd ,to say the least, that Nikon D3100 has the option to shoot RAW + Jpeg fine when the option Raw only= NEF file already has a full size embedded jpeg. Why is it there? Can the user access it? Get rid of it to reduce the file size? Add the metadata to it?
My objective is to make a long lasting master image archive/database from which to make copies and other images for different uses.
Regards JohnB

These days, the only reason to shoot raw+jpeg that I can think of is when you want the long-term quality of the raw files, but need immediate, quick access to the images (such as to pick a few from the sidelines, to send to the home office during a timeout). The smaller file size of the JPGs makes that kind of very quick access possible, when every second counts. For most people, it makes little sense to do both. There’s no way to inhibit the inclusion of the embedded jpegs that I know of; they’re used by the camera itself when displaying the image on the LCD, and by most image-viewer programs (e.g. Finder and Explorer). Once you’ve got them into Lightroom or Aperture, all they do is waste space. I don’t remove them, though, because I don’t want to modify my master images. —Jeffrey

— comment by John Bestevaar on February 19th, 2011 at 12:16pm JST (13 years, 2 months ago) comment permalink

Question about the NEF Codec – I performed a web search for “customizing NEF codec to use the embedded color space” and on top of the list is your blog on SRGB and Adobe RGB. I previously was using SRGB color space in my Nikon cameras. Lately, I switched my camera color space settings to Adobe RGB. My Lenovo P32U monitor is set to Adobe RGB color space. When I converted the Adobe RGB NEF files to JPEG and TIFF formats using Nikon NX-View with the software converting my final JPEG and TIFF output in SRGB, I can see the correct colors of the converted/exported JPEG and TIFF images in Windows Picture viewer exactly matching the same color of the NEF files rendered in Nikon NX-View. The problem is that when I launch the NEF files using Windows picture viewer which use the installed NEF Codec, the NEF images with Adobe RGB embedded color space would be displayed by Windows Picture viewer a bit less in color vibrancy since the NEF codec is defaulting to SRGB color space. Is there a way to customize the Nikon NEF Codec which is called by Windows Picture Viewer to use the color space embedded in the NEF files? I could not find any answer from my web search. Thanks. If this is a bug in the Nikon Codec, I will report it to Nikon USA.

Your use of the word “codec” here isn’t quite right. I suppose in the wide scope of things, one could consider a color profile to be a “codec”, but this is not common usage. Anyway, as the blog post explains, the in-camera setting has no impact on the raw data in the NEF file; the in-camera setting impacts the color space used to create the embedded JPEG previews. From what you describe, it sounds like the Windows Picture Viewer software is smart enough to understand how to extract JPEG data fro a NEF file, but not smart enough to know about the color-space setting within the NEF. It sounds like it’s just blindly assuming that any embedded JPEG data is to be interpreted as sRGB. This would be a bug in Windows Picture Viewer. —Jeffrey

— comment by Edwin on December 22nd, 2018 at 5:21pm JST (5 years, 4 months ago) comment permalink
Leave a comment...


All comments are invisible to others until Jeffrey approves them.

Please mention what part of the world you're writing from, if you don't mind. It's always interesting to see where people are visiting from.

IMPORTANT:I'm mostly retired, so I don't check comments often anymore, sorry.


You can use basic HTML; be sure to close tags properly.

Subscribe without commenting