Hi there,
I created a small fix for the normalization of the histogram height for
bright/dark pictures. When a picture contains a lot of white/black
pixels that one peak totally overshadows everything else in the histogram:
I therefore ignored the last and the first 4 bins from the height
detection. This leads to a more usable histogram in these corner cases:
As you can see, the center of the histogram is not longer just a flat
line. I recommend playing around with the exposure correction to see the
before and after for yourselves.
Please have a look at the code, I just added an offset of 16 (=4bins)
and -1 to all for-loops but I do not understand, why some of them
originally started with k=0 while others started with k=4,5,6,7 so I
just kept it that way. The reason why I skip 4 bins on the left side but
only a single one on the right is because a picture needs to be
reeeeaaaally dark for the pixels to have a brightness of exactly 0.
Usually they accumulate in the first few bins and screw the
normalization from there. This is not the case for white pixels so a
single bin is sufficiant there.
Hope you accept this submission.
___________________________________________________________________________
darktable developer mailing list
to unsubscribe send a mail to darktable-dev+unsubscr...@lists.darktable.org
>From e98b337cee39770303cab23a7019777d8ea2b53c Mon Sep 17 00:00:00 2001
From: solarer <sola...@hotmail.de>
Date: Mon, 5 Apr 2021 19:48:39 +0200
Subject: [PATCH] =?UTF-8?q?Changed=20the=20calculation=20of=20the=20normal?=
=?UTF-8?q?ization=20factor=20for=20the=20histogram=20so=20that=20the=20fi?=
=?UTF-8?q?rst=20and=20last=20bins=20are=20ignored.=20Otherwise=20these=20?=
=?UTF-8?q?bins=20will=20overshadow=20all=20other=20values=20in=20very=20b?=
=?UTF-8?q?right=20or=20very=20dark=20pictures.=20=09ge=C3=A4ndert:=20=20?=
=?UTF-8?q?=20=20=20=20=20src/common/histogram.c?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/common/histogram.c | 27 +++++++++++++++------------
1 file changed, 15 insertions(+), 12 deletions(-)
diff --git a/src/common/histogram.c b/src/common/histogram.c
index 380627b64..7534f82ea 100644
--- a/src/common/histogram.c
+++ b/src/common/histogram.c
@@ -393,6 +393,9 @@ void dt_histogram_helper(dt_dev_histogram_collection_params_t *histogram_params,
}
}
+
+// calculate max bin value for normalization of histogram height
+// ignore couple of first and last bin because the height of these bins explodes for bright/dark pictures which flattens the whole histogram
void dt_histogram_max_helper(const dt_dev_histogram_stats_t *const histogram_stats,
const dt_iop_colorspace_type_t cst, const dt_iop_colorspace_type_t cst_to,
uint32_t **histogram, uint32_t *histogram_max)
@@ -403,19 +406,19 @@ void dt_histogram_max_helper(const dt_dev_histogram_stats_t *const histogram_sta
switch(cst)
{
case iop_cs_RAW:
- for(int k = 0; k < 4 * histogram_stats->bins_count; k += 4)
+ for(int k = 0+16; k < 4 * (histogram_stats->bins_count - 1); k += 4)
histogram_max[0] = histogram_max[0] > hist[k] ? histogram_max[0] : hist[k];
break;
case iop_cs_rgb:
// don't count <= 0 pixels
- for(int k = 4; k < 4 * histogram_stats->bins_count; k += 4)
+ for(int k = 4+16; k < 4 * (histogram_stats->bins_count - 1); k += 4)
histogram_max[0] = histogram_max[0] > hist[k] ? histogram_max[0] : hist[k];
- for(int k = 5; k < 4 * histogram_stats->bins_count; k += 4)
+ for(int k = 5+16; k < 4 * (histogram_stats->bins_count - 1); k += 4)
histogram_max[1] = histogram_max[1] > hist[k] ? histogram_max[1] : hist[k];
- for(int k = 6; k < 4 * histogram_stats->bins_count; k += 4)
+ for(int k = 6+16; k < 4 * (histogram_stats->bins_count - 1); k += 4)
histogram_max[2] = histogram_max[2] > hist[k] ? histogram_max[2] : hist[k];
- for(int k = 7; k < 4 * histogram_stats->bins_count; k += 4)
+ for(int k = 7+16; k < 4 * (histogram_stats->bins_count - 1); k += 4)
histogram_max[3] = histogram_max[3] > hist[k] ? histogram_max[3] : hist[k];
break;
@@ -424,25 +427,25 @@ void dt_histogram_max_helper(const dt_dev_histogram_stats_t *const histogram_sta
if(cst_to == iop_cs_LCh)
{
// don't count <= 0 pixels
- for(int k = 4; k < 4 * histogram_stats->bins_count; k += 4)
+ for(int k = 4+16; k < 4 * (histogram_stats->bins_count - 1); k += 4)
histogram_max[0] = histogram_max[0] > hist[k] ? histogram_max[0] : hist[k];
- for(int k = 5; k < 4 * histogram_stats->bins_count; k += 4)
+ for(int k = 5+16; k < 4 * (histogram_stats->bins_count - 1); k += 4)
histogram_max[1] = histogram_max[1] > hist[k] ? histogram_max[1] : hist[k];
- for(int k = 6; k < 4 * histogram_stats->bins_count; k += 4)
+ for(int k = 6+16; k < 4 * (histogram_stats->bins_count - 1); k += 4)
histogram_max[2] = histogram_max[2] > hist[k] ? histogram_max[2] : hist[k];
- for(int k = 7; k < 4 * histogram_stats->bins_count; k += 4)
+ for(int k = 7+16; k < 4 * (histogram_stats->bins_count - 1); k += 4)
histogram_max[3] = histogram_max[3] > hist[k] ? histogram_max[3] : hist[k];
}
else
{
// don't count <= 0 pixels in L
- for(int k = 4; k < 4 * histogram_stats->bins_count; k += 4)
+ for(int k = 4+16; k < 4 * (histogram_stats->bins_count - 1); k += 4)
histogram_max[0] = histogram_max[0] > hist[k] ? histogram_max[0] : hist[k];
// don't count <= -128 and >= +128 pixels in a and b
- for(int k = 5; k < 4 * (histogram_stats->bins_count - 1); k += 4)
+ for(int k = 5+16; k < 4 * (histogram_stats->bins_count - 1); k += 4)
histogram_max[1] = histogram_max[1] > hist[k] ? histogram_max[1] : hist[k];
- for(int k = 6; k < 4 * (histogram_stats->bins_count - 1); k += 4)
+ for(int k = 6+16; k < 4 * (histogram_stats->bins_count - 1); k += 4)
histogram_max[2] = histogram_max[2] > hist[k] ? histogram_max[2] : hist[k];
}
break;
--
2.31.0