{"action":"created","issue":{"url":"https://api.github.com/repos/jcelaya/hdrmerge/issues/126","repository_url":"https://api.github.com/repos/jcelaya/hdrmerge","labels_url":"https://api.github.com/repos/jcelaya/hdrmerge/issues/126/labels{/name}","comments_url":"https://api.github.com/repos/jcelaya/hdrmerge/issues/126/comments","events_url":"https://api.github.com/repos/jcelaya/hdrmerge/issues/126/events","html_url":"https://github.com/jcelaya/hdrmerge/issues/126","id":307407033,"number":126,"title":"Wrong computed `satThreshold`","user":{"login":"Floessie","id":10133457,"avatar_url":"https://avatars3.githubusercontent.com/u/10133457?v=4","gravatar_id":"","url":"https://api.github.com/users/Floessie","html_url":"https://github.com/Floessie","followers_url":"https://api.github.com/users/Floessie/followers","following_url":"https://api.github.com/users/Floessie/following{/other_user}","gists_url":"https://api.github.com/users/Floessie/gists{/gist_id}","starred_url":"https://api.github.com/users/Floessie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Floessie/subscriptions","organizations_url":"https://api.github.com/users/Floessie/orgs","repos_url":"https://api.github.com/users/Floessie/repos","events_url":"https://api.github.com/users/Floessie/events{/privacy}","received_events_url":"https://api.github.com/users/Floessie/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":9,"created_at":"2018-03-21T20:31:45Z","updated_at":"2018-03-23T19:48:41Z","closed_at":null,"author_association":"NONE","body":"Hi,\r\n\r\nwith my new camera (Canon 6D) I sometimes have an issue with HDRMerge: The mask is solid green (brightest image). This seems to be due to the value fed to `Image::isSaturated()` via `Image::isSaturatedAround()` either being too low or the computed `satThreshold` too high. The max value fed to `Image::isSaturated()` was 13314, the computed `satThreshold` 13556.\r\n\r\nIf I set the custom WB to 13314, everything is fine, but I can only get this value by adding `printf()` code to `Image::isSaturated()`, which is impractical at least. Why do those values differ?\r\n\r\nHere's the output of `-vv` with the additional patch below:\r\n\r\n```\r\nUsing LibRaw 0.17.2-Release\r\nNumber of frames : Number of frames : 11\r\n\r\nNumber of frames : 1\r\n20180320-183828-1.cr2: 5496x3670 (5568x3708+72+38, by Canon EOS 6D, 400ISO 1/50sec f3.2 EV:-7\r\nb4b4b4b4 RGBG, sat 15490, black 2047, flip 5, wb: 2305 1024 1458 1024, cblack: 2047 2047 2048 2047\r\n20180320-183828.cr2: 5496x3670 (5568x3708+72+38, by Canon EOS 6D, 400ISO 1/3200sec f3.2 EV:-13\r\nb4b4b4b4 RGBG, sat 15490, black 2047, flip 5, wb: 2305 1024 1458 1024, cblack: 2047 2047 2048 2048\r\n20180320-183826.cr2: 5496x3670 (5568x3708+72+38, by Canon EOS 6D, 400ISO 1/400sec f3.2 EV:-10\r\nb4b4b4b4 RGBG, sat 15490, black 2047, flip 5, wb: 2305 1024 1458 1024, cblack: 2047 2047 2048 2047\r\nLoad files: 0.710646 seconds\r\n13693 14336 13859 14335 \r\nparams.max = 15490, satThreshold = 15490\r\nA: satThreshold = 13693\r\nB: satThreshold = 13556\r\nCompute response functions: 0.187964 seconds\r\nGenerate mask: 0.0791689 seconds\r\n```\r\n\r\n```patch\r\ndiff --git a/src/ImageStack.cpp b/src/ImageStack.cpp\r\nindex 9097bb4..ab918e5 100644\r\n--- a/src/ImageStack.cpp\r\n+++ b/src/ImageStack.cpp\r\n@@ -87,17 +87,26 @@ void ImageStack::calculateSaturationLevel(const RawParameters & params, bool use\r\n         }\r\n     }\r\n \r\n+    for (auto m : maxPerColor) {\r\n+        printf(\"%u \", m);\r\n+    }\r\n+    printf(\"\\n\");\r\n+\r\n     satThreshold = params.max == 0 ? maxPerColor[0] : params.max;\r\n+    printf(\"params.max = %u, satThreshold = %u\\n\", params.max, satThreshold);\r\n     for (int c = 0; c < 4; ++c) {\r\n         if (maxPerColor[c] > 0 && maxPerColor[c] < satThreshold) {\r\n             satThreshold = maxPerColor[c];\r\n         }\r\n     }\r\n+    printf(\"A: satThreshold = %u\\n\", satThreshold);\r\n     if(!useCustomWl) // only scale when no custom white level was specified\r\n         satThreshold *= 0.99;\r\n     else\r\n         Log::debug( \"Using custom white level \", params.max );\r\n \r\n+    printf(\"B: satThreshold = %u\\n\", satThreshold);\r\n+\r\n     for (auto & i : images) {\r\n         i.setSaturationThreshold(satThreshold);\r\n     }\r\n```\r\n\r\nBest,\r\nFlössie"},"comment":{"url":"https://api.github.com/repos/jcelaya/hdrmerge/issues/comments/375779268","html_url":"https://github.com/jcelaya/hdrmerge/issues/126#issuecomment-375779268","issue_url":"https://api.github.com/repos/jcelaya/hdrmerge/issues/126","id":375779268,"user":{"login":"Beep6581","id":5844619,"avatar_url":"https://avatars1.githubusercontent.com/u/5844619?v=4","gravatar_id":"","url":"https://api.github.com/users/Beep6581","html_url":"https://github.com/Beep6581","followers_url":"https://api.github.com/users/Beep6581/followers","following_url":"https://api.github.com/users/Beep6581/following{/other_user}","gists_url":"https://api.github.com/users/Beep6581/gists{/gist_id}","starred_url":"https://api.github.com/users/Beep6581/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Beep6581/subscriptions","organizations_url":"https://api.github.com/users/Beep6581/orgs","repos_url":"https://api.github.com/users/Beep6581/repos","events_url":"https://api.github.com/users/Beep6581/events{/privacy}","received_events_url":"https://api.github.com/users/Beep6581/received_events","type":"User","site_admin":false},"created_at":"2018-03-23T19:48:41Z","updated_at":"2018-03-23T19:48:41Z","author_association":"COLLABORATOR","body":"@iliasg you wrote,\r\n> It's common that these WhiteLevel values are violated by some outlier pixels\r\n\r\nWhile @LibRaw wrote,\r\n> So to avoid magenta cast you need to set data cut limit based on histogram or on real data maximum\r\n\r\nSince the brightest pixel value cannot be trusted to be a safe data maximum, if we were to use LibRaw I suppose this means the white level detection should somehow know how to find the \"real, safe\" white, to ignore the outliers. Is that correct? If so, how? Do you just discard the top 1% or is there a better or standard way? Short of having humans do the measurement and come up with a `camconst.json` file, that is."}}
{"actor":{"display_login":"Beep6581"}}