Hi Marcelo,
I do a lot of photography with a Nikon camera. The raw NEF images are exactly what is read from the imager. That means they lack even the color correction needed to compensate for the spectral response of the imager. I am doing photography – not data analysis – but I convert images by reading them into Adobe LightRoom, often to jpeg for printing, but sometimes to tiff. Adobe Camera Raw and Photoshop will also read raw images and convert them as needed. I think your best solution (as someone on StackExchage also recommended) is to read your images with such a tool and covert to tiff. This avoids the artifacts of jpeg compression, but can correct for color as needed. If you have in fact calibrated for the spectral response of the camera imager you could probably also create a tiff with no color correction, only the pixel values in tiff format so Mathematica can read them. If that is what you need, let me know and I’ll look into it.
In fact, I use raw images to do the following corrections: Dark frames and bias, mainly, so I can correct the termal noise from ccd,and other distorsions as vigneting etc…I do not ever try using tiff format. I ll try the Szlabocs suggestions.
Before using photoshop , or ligthroom I would like to clean the image using mathematica codes applied for these darks and bias reductions.
So we need the crude informations from sensors to do that. My intend is explore the Mathematica programming in the same path that sherlock´s Fixing Bad Astrophotography II: Imaging Mars with Mathematica—Wolfram Blog did (with. fits extension), but using dark and bias reductions first and then aplying other filtering codes..
I really don’t know much about astrophotography, but don’t modern Nikon cameras do in-camera dark-frame subtraction already? The camera calls it “long exposure noise reduction”.
If you’d want to turn this off in camera and do it manually, then the dcraw based method I suggested does really give you data which is suitable for this.
dcraw -o 0 -D -T -6 infile.nef
will create a TIFF that has un-demosaiced, unprocessed data. The pixel values will be proportional to the charge accumulated at each photosite. The TIFF you get will look like this (no. 2) due to lack of demosaicing.
You can then process it in Mathematica.
But I imagine that eventually you would want to export this data from Mathematica and do proper demosaicing on it. I don’t know what tool will be able to do this well. I don’t know of any easy way to put the processed data back into a NEF file so you can use Lightroom, ViewNX or other RAW converters that know the camera’s characteristics and can do a correct conversion.
This is why I stopped playing with RAW data in Mathematica. I could do some useful processing on it (I wanted to do de-banding), but I had no way to convert this data to a usable photograph afterwards.
So if we want use the raw image, first it is more useful do the reductions (darks, bias, flats, etc..) in a suitable program and then converting the results to a suited format for being manipulate inside mathematica.
You need to download the source code of LibRaw library: Download | LibRaw and build it.
Then, you need to compile image_external.c, load the LibRaw library and load the read_raw_image function. Here is an example for Windows:
CreateLibrary::cmperr: Compile error: C:\Program Files\Wolfram
Research\Mathematica\10.0\SystemFiles\Links\LibraryLink\LibraryResources\Source\image_external.c(4)
: fatal error C1083: Cannot open include file: ‘cv.h’: No such file or
directory >>
Although the file image_external is present in the source directory:
Well I did , but now the following error happened:
During evaluation of In[162]:= CreateLibrary::cmperr: Compile error:
C:\Program Files\Wolfram
Research\Mathematica\10.0\SystemFiles\Links\LibraryLink\LibraryResources\Source\image_external.c(5)
: fatal error C1083: Cannot open include file: ‘libraw.h’: No such
file or directory >>
Out[169]= $Failed
During evaluation of In[162]:= LibraryFunction::notfound: Symbol
C:\cygwin64\home\decicco\LibRaw-0.16.0\libraw\build\libraw not found.
But ´libraw.h´ is there:
C:\cygwin64\home\decicco\LibRaw-0.16.0\libraw\libraw.h