darktable-org / darktable

darktable is an open source photography workflow application and raw developer
https://www.darktable.org
GNU General Public License v3.0
9.15k stars 1.11k forks source link

Samsung NX mini support + WB presets #12820

Open ge0rg opened 1 year ago

ge0rg commented 1 year ago

Hi,

I wanted to supply WB profiles for the old but still good Samsung NX mini camera: darktable-whitebalance-20221107.tar.gz

From a first analysis of the 105 (7*15) calibration shots, there are two issues with the EXIF data, at least according to exiftool outputs - all of them report the following two lines:

White Balance                   : Manual
WB RGGB Levels Black            : 0 0 0 0

The former makes it impossible to differentiate the different WB profiles (but I've made notes which files belong to which profile, so it can be reconstructed).

The latter causes extract_wb.py to crash:

Traceback (most recent call last):
  File "/usr/src/darktable/tools/extract_wb.py", line 170, in <module>
    r = float(values[0])/g
ZeroDivisionError: float division by zero

Apparently the "todo - this codepath is weird" section of the script is attempting to normalize the values based on green, which is not possible with 0/0/0. Working around this by "fixing" the values to 1/1/1 yields the following ouptut (this is just the "Sunny" profile, but it claims to be "Manual"):

  { "Samsung", "NX mini", Manual, 0, { 2.7421875, 1, 2.06640625, 0 } },
  { "Samsung", "NX mini", Manual, 0, { 2.7890625, 1, 1.99609375, 0 } },
  { "Samsung", "NX mini", Manual, 0, { 2.83984375, 1, 1.92578125, 0 } },
  { "Samsung", "NX mini", Manual, 0, { 2.88671875, 1, 1.85546875, 0 } },
  { "Samsung", "NX mini", Manual, 0, { 2.93359375, 1, 1.78515625, 0 } },
  { "Samsung", "NX mini", Manual, 0, { 2.984375, 1, 1.71484375, 0 } },
  { "Samsung", "NX mini", Manual, 0, { 3.03125, 1, 1.64453125, 0 } },
  { "Samsung", "NX mini", Manual, 0, { 3.08203125, 1, 1.578125, 0 } },
  { "Samsung", "NX mini", Manual, 0, { 3.1328125, 1, 1.5390625, 0 } },
  { "Samsung", "NX mini", Manual, 0, { 3.1875, 1, 1.5, 0 } },
  { "Samsung", "NX mini", Manual, 0, { 3.23828125, 1, 1.4609375, 0 } },
  { "Samsung", "NX mini", Manual, 0, { 3.29296875, 1, 1.421875, 0 } },
  { "Samsung", "NX mini", Manual, 0, { 3.34375, 1, 1.3828125, 0 } },
  { "Samsung", "NX mini", Manual, 0, { 3.3984375, 1, 1.34765625, 0 } },
  { "Samsung", "NX mini", Manual, 0, { 3.44921875, 1, 1.30859375, 0 } },

This also seems to be the "old" format from before the migration to wb_presets.json.

The NX3000 is using the same CPU, but a different (larger) image sensor, and it's apparently fully supported, despite having the same issues in its EXIF data.

What would be the best way to proceed from here?

I don't mind compiling my own Darktable and/or submitting a PR, but I don't know jack about image sensors and how their data is processed.

ge0rg commented 1 year ago

Trial and error on the uploaded raw sample suggests that this is the right CFA, but I'm not sure how to properly generate the other properties:

<Camera make="SAMSUNG" model="NX mini">
        <ID make="Samsung" model="NX mini">Samsung NX mini</ID>
        <CFA width="2" height="2">
                <Color x="0" y="0">RED</Color>
                <Color x="1" y="0">GREEN</Color>
                <Color x="0" y="1">GREEN</Color>
                <Color x="1" y="1">BLUE</Color>
        </CFA>
</Camera>
kmilos commented 1 year ago

I'm not sure how to properly generate the other properties:

Convert to DNG, and then use https://github.com/darktable-org/darktable/blob/master/tools/dngmeta.sh

P.S. Please use the camera support template in the future.

ge0rg commented 1 year ago

Sorry for using the wrong template. I started out after seeing that there is already an NX mini RAW sample, but before realizing that it wasn't yet converted into cameras.xml. I've opened https://github.com/darktable-org/rawspeed/pull/396 with the full XML now.

I'm going to look into noise profiles and lens correction when I ave some more time, but looks like the WB calibration is rather more important, and I can't find anything more up-to-date than https://github.com/darktable-org/darktable/wiki/White-balance-presets which is what made me open this issue.

kmilos commented 1 year ago

I've opened darktable-org/rawspeed#396 with the full XML now.

Err, I had already opened https://github.com/darktable-org/rawspeed/pull/395 and linked it here...

I'll drop it since yours includes black areas.

Usually 3 issues are opened: one using the template for the actual camera model raw format support, one for white balance presets, and one for noise profile (the latter two depend on the first one).

ge0rg commented 1 year ago

@kmilos I'm very sorry, I actually missed your initial PR and only looked at the comment, looks like I developed a blind spot for bot/CI messages in github issues 😲

Can you recommend what to do regarding white balance for the camera? Is there also a different tool I can use to extract the data from the raw images? Should I group the images based on the WB profiles and create respective ~json~ C struct dumps?

kmilos commented 1 year ago

No worries.

As for the white balance preset tool, tools/extract_wb.py should do the grouping for you (given that everything else works out). However, I'm afraid the tools is out of date as it also spews out the deprecated C struct, and dt has moved to JSON on master recently, but it's not a big search/replace job to convert...

ge0rg commented 1 year ago

I've seen the new JSON format, yeah. If the data structure is exactly the same, I can convert the curly braces no problem. However, extract_wb.py fails to do the grouping because all presets are reported as "Manual" in the EXIF (see initial post).

Is dt obtaining the WB mode from the same EXIF field? Do we need to hack up support for the custom fields that Samsung is using internally (the camera displays the right WB preset in the image info, so it must be there)? Does it even play a role or can we just dump all 105 presets (15 values on the B-A range for seven different WB modes) into the "Manual" category?

kmilos commented 1 year ago

Yes, these are coming from Exif, but are mostly found in vendor specific tags in the MakerNotes. If you can figure out the Samsung MakerNotes (exiftool -a -u -s -g1 -w txt foo.SRW), then the script can be updated. If not, I think it'll probably have to be done by hand, preset by preset...

ge0rg commented 1 year ago

It looks like the relevant tag is Samsung Type 2 0x00a0, at least the tag value starts (ironically in all modes) with "AWB".

Here's the C struct dump of the 0x00a0 tag from my 105 picture test set, grouped by the WB mode as displayed in the camera: Samsung_Type_2_0x00a0.txt

If taken as an uint32_t[], it looks like the mode is at offset 3 and the "flash" value is at offset 2. But again, if it's just a one-off effort, I can group the raw data by the respective modes, I'm just not sure about the expected data format.

github-actions[bot] commented 1 year ago

This issue did not get any activity in the past 60 days and will be closed in 365 days if no update occurs. Please check if the master branch has fixed it and report again or close the issue.

ge0rg commented 1 year ago

I'm still unsure how to proceed and what additional data to provide, as per the previous comment.

kmilos commented 1 year ago

You'll probably have more interested and knowledgeable people willing to dig in at metadata specific forums/projects like

https://exiftool.org/forum/index.php https://github.com/exiftool/exiftool https://github.com/Exiv2/exiv2

The darktable part should still be straightforward once the MakerNote metadata is decrypted...

ge0rg commented 1 year ago

Looks like exiftool has the most complete Samsung type2 parser, so I've pinged the developers. I'm still wondering if support for the NX3000 is incorrect or if there is a shortcut that I can also take with the mini.

github-actions[bot] commented 1 year ago

This issue has been marked as stale due to inactivity for the last 60 days. It will be automatically closed in 300 days if no update occurs. Please check if the master branch has fixed it and report again or close the issue.

ge0rg commented 1 year ago

It doesn't look like we'll get exiftool to support the custom WB profile data from the NX mini / NX3000, so is there anything I can do to make the existing data usable for darktable WB profiles? Given that the NX3000 is supported by darktable but lacks proper WB profile parsing, is its data cheated? Incorrect? Can the same mechanism be applied to the mini?

github-actions[bot] commented 1 year ago

This issue has been marked as stale due to inactivity for the last 60 days. It will be automatically closed in 300 days if no update occurs. Please check if the master branch has fixed it and report again or close the issue.

ge0rg commented 1 year ago

Is WB parsing the MakerNotes or is that done by a library? If you can provide a pointer to the right place, I can check how far it's away from supporting the NX mini.

github-actions[bot] commented 10 months ago

This issue has been marked as stale due to inactivity for the last 60 days. It will be automatically closed in 300 days if no update occurs. Please check if the master branch has fixed it and report again or close the issue.

ge0rg commented 10 months ago

When the machines rise, they will auto close all issues and humanity will vanish.

github-actions[bot] commented 8 months ago

This issue has been marked as stale due to inactivity for the last 60 days. It will be automatically closed in 300 days if no update occurs. Please check if the master branch has fixed it and report again or close the issue.

ge0rg commented 8 months ago

.

github-actions[bot] commented 6 months ago

This issue has been marked as stale due to inactivity for the last 60 days. It will be automatically closed in 300 days if no update occurs. Please check if the master branch has fixed it and report again or close the issue.

ge0rg commented 4 months ago

🤔

github-actions[bot] commented 1 month ago

This issue has been marked as stale due to inactivity for the last 60 days. It will be automatically closed in 300 days if no update occurs. Please check if the master branch has fixed it and report again or close the issue.