Message Boards Message Boards

Recover highlight and shadow detail from RAW images?


I am processing RAW images (.nef) from a Nikon camera. If I process these images in Adobe Lightroom I can adjust the highlights and shadows to avoid clipping any data. Histogram looks like this. Histogram Lightroom

In Mathematica, doing an Import with default values the ImageHistogram looks like this: Histrogram Mathematica

Values appear to be clipped at both ends of the histogram. Applying ImageAdjust does not recover the data at the ends. It appears that importing a RAW file clips the data during the import process. The result is much like the defaults in Lightroom before adjusting the highlight and shadow sliders.

How can I import RAW images and get all the data without clipping?

POSTED BY: Jeff Burns
4 months ago

Whenever you post here, post your code! it's part of the rules... thanks you :)

Did you use







POSTED BY: Sander Huisman
4 months ago

If you provide your ".nef" file,you will receive more better solution maybe.And I have a related answer here,hope to help.

POSTED BY: Yode Japhe
4 months ago

Test NEF files are a available at this link.

Using this code it is apparent that the image data is not clipped by Mathematica.

img = Import[“a.NEF”];

ImageHistogram[img, 1000, All, Appearance -> "Transparent", 
   Method -> #, ImageSize -> Large, 
   FrameTicks -> True] & /@ {"IncludeOutOfRange", "ExcludeOutOfRange"}
POSTED BY: Jeff Burns
4 months ago

So, what was the source of the problem? Was is too rough default binning by ImageHistogram (default is 128 bins)?

Apparently imported image contains no out-of range values:

ImageData[img] // MinMax
(* =>  {0., 1.} *)

But a naive attempt to obtain it directly from the "Data" element by applying Rescale to each color channel separately produces a slightly different image:

data = Import["DSC_2106.NEF", "Data"];
img = Import["DSC_2106.NEF"];

subimage = ImageTake[img, {-4500, -3000}, {1300, 2700}];
subimageFromData = 
 Image[Rescale /@ Transpose[N@data[[-4500 ;; -3000, 1300 ;; 2700]], {2, 3, 1}], 
  Interleaving -> False];

ImageData[subimageFromData] - ImageData[subimage] // MinMax

(* => {0., 0.0346075} *)
POSTED BY: Updating Name
4 months ago

Group Abstract Group Abstract