1
$\begingroup$

I'm using dcraw program to import raw image data to Mathematica. When I use Run["dcraw -4 -D -T "image.nef"] (which converts it to an unprocessed linear TIFF file) and then Import["image.tiff","Data"], I basically import the raw data to Mathematica.

Afterwards I use Image[Import["image.tiff","Data"]] command to see the image using the extracted data, but it is DIFFERENT than the Import["image.tiff"] image, WHY?

$\endgroup$
  • $\begingroup$ You should probably not use Image[Import[...]]; Import already returns an Image object. Instead you should save the image returned by Import into a variable, e.g. img = Import["path/to/yourimage"]. Evaluating img will already show that image. I suppose that the difference you see may come from the fact that running Image on an object that is already a bitmap image might cause it to be rasterized a second time, leading to loss of quality, etc. $\endgroup$ – MarcoB Mar 31 '16 at 18:16
1
$\begingroup$

It would have been best if you post the TIFF file (upload it somewhere). Without it, my best guess is this:

data = Import["file.tiff", "Data"] will import the integers stored in the TIFF. These may have various ranges depending of the type of TIFF file. For an 8-bit one, you'll get values between 0..255, for a 16-bit one between 0..65535, etc.

data only has the raw data from the image file without any meta information such as what range of values should be assumed. Image[data] thus assumed a default range of 0..1 and creates a Real type image (ImageType). Thus in your case you should manually specify the type of image you want to create, e.g. Image[data, "Bit16"] as dcraw outputs 16-bit files with the -4 option.


If you want to import the data as an image, just use Import["file.tiff"]. Also note that since version 10.1 Mathematica can import NEF files directly, without any help from dcraw.

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.