Nikon Z6 NEF - Extract: Lens Distortion / Vignetting / Chromatic Aberration

Started by Gunar, February 07, 2022, 03:44:08 AM

Previous topic - Next topic

Gunar

Hi, first I would like to acknowledge this great piece of software - I'm fascinated how many hours of reverse engineering must have went into that!

I'm using darktable to edit my raw images and stumbled upon a new module (https://github.com/darktable-org/darktable/pull/7092/) which reads the lens correction parameters (distortion, vignetting, chromatic aberration) embedded in the raw file instead of relying on the lensfun database. I would to contribute corresponding information of the Nikon Z6 to this project and searched for hints where to find these information in the Nikon Z6 NEF. During the search I stumbled upon a comment in the exiftool code (https://github.com/exiftool/exiftool/blob/master/lib/Image/ExifTool/Nikon.pm#L10157) and happily started inspecting the corresponding tag.

ExifTool Comment:

# extra info found in IFD0 of NEF files (ref PH, Z6/Z7)
%Image::ExifTool::Nikon::NEFInfo = (
    GROUPS => { 0 => 'MakerNotes', 2 => 'Camera' },
    NOTES => q{
        As-yet unknown information found in SubIFD1 tag 0xc7d5 of NEF images from
        cameras such as the Z6 and Z7, and NRW images from some Coolpix cameras.
    },
    # 0x01 - undef[12]
    # 0x02 - undef[148]
    # 0x03 - undef[284]
    # 0x04 - undef[148,212]
    # 0x05 - undef[84] (barrel distortion params at offsets 0x14,0x1c,0x24, ref 28)
    # 0x06 - undef[116] (vignette correction params at offsets 0x24,0x34,0x44, ref 28)
    # 0x07 - undef[104]
    # 0x08 - undef[24]
    # 0x09 - undef[36]
);


I've extracted the data of tag 0xc7d5 of my files and converted them to decimal number and signed integers to see if I can find the needle in the haystack. However, I've problems to align the offsets mentioned in the comment above with my data:

0xc7d5 SubImage2 0xc7d5 Undefined 448 448
0000 4e 69 6b 6f 6e 00 01 01 00 00 49 49 2a 00 08 00 Nikon.....II*...
0010 00 00 05 00 05 00 07 00 54 00 00 00 4a 00 00 00 ........T...J...
0020 06 00 07 00 74 00 00 00 9e 00 00 00 07 00 07 00 ....t...........
0030 68 00 00 00 12 01 00 00 08 00 07 00 18 00 00 00 h...............
0040 7a 01 00 00 09 00 07 00 24 00 00 00 92 01 00 00 z.......$.......
0050 00 00 00 00 30 31 30 30 03 01 00 00 9a 59 01 00 ....0100.....Y..
0060 00 10 00 00 04 00 00 00 3e 4f 00 00 00 00 10 00 ........>O......
0070 8f ac ff ff 00 00 10 00 0c ef 00 00 00 00 10 00 ................
0080 00 00 00 00 01 00 00 00 00 00 00 00 01 00 00 00 ................
0090 00 00 00 00 e1 4b 01 00 00 00 10 00 00 00 00 00 .....K..........
00a0 00 00 00 00 00 00 d9 8a 30 31 30 30 01 01 00 00 ........0100....
00b0 9a 59 01 00 00 10 00 00 08 00 00 00 66 d2 fc ff .Y..........f...
00c0 00 00 10 00 00 00 00 00 01 00 00 00 11 f3 06 00 ................
00d0 00 00 10 00 00 00 00 00 01 00 00 00 62 9f fb ff ............b...
00e0 00 00 10 00 00 00 00 00 01 00 00 00 66 3a 06 00 ............f:..
00f0 00 00 10 00 00 00 00 00 01 00 00 00 01 00 00 00 ................
0100 01 00 00 00 00 00 00 00 1d 02 00 00 00 04 00 00 ................
0110 00 00 00 00 00 00 00 00 00 00 f7 da 30 31 30 30 ............0100
0120 01 02 00 00 9a 59 01 00 00 10 00 00 03 00 00 00 .....Y..........
0130 46 00 00 00 00 00 10 00 b9 ff ff ff 00 00 10 00 F...............
0140 00 00 00 00 01 00 00 00 6a ff ff ff 00 00 10 00 ........j.......
0150 03 00 00 00 9e ff ff ff 00 00 10 00 ff ff ff ff ................
0160 00 00 10 00 00 00 00 00 01 00 00 00 78 ff ff ff ............x...
0170 00 00 10 00 00 00 01 00 00 00 00 00 00 00 00 00 ................
0180 00 00 63 97 30 31 30 30 13 4f 00 00 00 01 00 00 ..c.0100.O......
0190 f0 3b 00 00 00 01 00 00 00 00 c4 a8 93 03 00 00 .;..............
01a0 00 02 00 00 b3 02 00 00 00 02 00 00 00 02 00 00 ................
01b0 00 02 00 00 00 02 00 00 00 02 00 00 00 00 31 dc ..............1.


I'm a noob when it comes to interpretation of hex values and addresses.
Can you please point me to how to interpret the comment above and apply it on my example?!
Thanks!

Phil Harvey

Those hex numbers aren't offsets, they are tag ID's.  You can see all of this with the ExifTool -v3 or -v4 option, or in the -htmlDump output.

- Phil

...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Gunar

Phil, thanks for the feedback! Seems I was searching in the wrong haystack ;-)
The htmlDump option is very good to get a better overview. Will investigate further...