Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Read and write Nikon raw files (*.NEF)

442 views
Skip to first unread message

Michael Wess

unread,
Aug 28, 2012, 5:31:09 AM8/28/12
to
Hello!

As one column of the sensor in my nikon camera is not working, I'm thinking about writing a matlab code where I can interpolate the value using the neighbor values to correct the images taken with this camera.

The images are stored in the Nikon raw format NEF, so to do this, I need to open, read and write NEF files in matlab.

What I have found so far is the C routine "dcraw" which allowed me to import NEF images into Matlab. But I'm not quite shure how to write the corrected files?

I don't need to change, or even identify any metadata, I just want the new files to be exactly the same as the old ones except for the corrected column.

Does anybody know how to achieve that?

Thank you and best regards
mischa

Michael W

unread,
Aug 28, 2012, 10:23:11 AM8/28/12
to
I think I will not use the proprietary Nikon format (NEF), but I will convert all the raw images to DNG files.

I now converted all files using the free adobe DNG converter, and it was now possible to import the image into matlab using this tips: http://blogs.mathworks.com/steve/2011/03/08/tips-for-reading-a-camera-raw-file-into-matlab/

However, if I write DNG files with matlab using the tiff class, I cannot open the resulting images in lets say photoshop.

Here is what I did:

copyfile('DSC_0799_ISO1600.dng','output_test.dng');

t = Tiff('DSC_0799_ISO1600.dng','r');
offsets = getTag(t,'SubIFD');
setSubDirectory(t,offsets(1));
cfa = read(t);
close(t);


t2 = Tiff('output_test.dng','r+');
offsets = getTag(t2,'SubIFD');
setSubDirectory(t2,offsets(1));
w=flipdim(cfa,1);
t2.write(w)
close(t2);

I just copy the original file, read the content I want, open the copied file, mirror the original content and write it to the new file.
The new file is a few KBs bigger and isn't recognized by Photoshop anymore.

Is there another option to write standard DNG files?

Thank you!

John

unread,
Aug 28, 2012, 4:02:08 PM8/28/12
to
I would think this would only work if that first sub IFD were uncompressed. Any chance I can get my hands on your DSC_0799_ISO1600.dng file to look at this?


"Michael W" wrote in message <k1ik8f$aae$1...@newscl01ah.mathworks.com>...

Michael W

unread,
Aug 28, 2012, 4:28:08 PM8/28/12
to
"John " <com.wor...@evans.john> wrote in message <k1j840$t61$1...@newscl01ah.mathworks.com>...
> I would think this would only work if that first sub IFD were uncompressed. Any chance I can get my hands on your DSC_0799_ISO1600.dng file to look at this?
>

Hi John,

I took the sample file from here: http://media.dpnotes.com.s3.amazonaws.com/DSC_0799_ISO1600.NEF

and converted it to DNG using the converter found here: http://www.adobe.com/go/dng_converter_win

and selected the option "uncompressed" as recommended here: http://blogs.mathworks.com/steve/2011/03/08/tips-for-reading-a-camera-raw-file-into-matlab/

Thanks for your help!

Mischa

John

unread,
Aug 29, 2012, 12:07:08 PM8/29/12
to
Mischa, when I follow your steps as outlined, the file size doesn't change, which is what one would expect with an uncompressed image, so something somewhere must be different. I would have to see your DSC_0799_ISO1600.dng file to go further.


"Michael W" wrote in message <k1j9ko$5go$1...@newscl01ah.mathworks.com>...

Michael W

unread,
Aug 29, 2012, 3:04:08 PM8/29/12
to
John, thanks for trying this!

I uploaded the DNG to http://www.easy-dump.com/38180, hope this works....

the file seems to have a size of 24,042 KB, but my output image is 24,050 KB and not readable.

Thank you and best regards
Mischa


"John " <com.wor...@evans.john> wrote in message <k1lenc$1kg$1...@newscl01ah.mathworks.com>...

Michael W

unread,
Aug 29, 2012, 3:11:06 PM8/29/12
to
Sorry, need to remove the comma at the end:

http://www.easy-dump.com/38180

there is my file

"Michael W" wrote in message <k1lp38$cba$1...@newscl01ah.mathworks.com>...

John

unread,
Aug 30, 2012, 1:18:08 PM8/30/12
to
Mischa, it still seems to work ok on my end, i.e. the file size does not change for me. I'll contact you off-line, we can think of how to proceed further.



"Michael W" wrote in message <k1lpga$e50$1...@newscl01ah.mathworks.com>...
0 new messages