Bug 304811

Summary: Offer a "stretch histogram" functionality to automatically adjust brightness & gamma
Product: [Applications] digikam Reporter: Alain Knaff <kde>
Component: Plugin-Editor-BCGAssignee: Digikam Developers <digikam-bugs-null>
Status: RESOLVED FIXED    
Severity: wishlist CC: caulier.gilles, sven.burmeister
Priority: NOR    
Version: 1.4.0   
Target Milestone: ---   
Platform: Ubuntu   
OS: Linux   
Latest Commit: Version Fixed In: 6.1.0

Description Alain Knaff 2012-08-08 17:56:14 UTC
I've found that for lightening up a dark image, increasing the gamma value works best.

However, that introduces a haze over the image (it looks as if it was slightly foggy), and I've noticed that I can make the haze go away by decreasing brightness and increasing contrast in such a way that the histogram curve occupies the entire range. 

This also works to get the haze out of images that have it from the beginning.

However, this method takes some fiddling with the BC numbers/sliders to get right.

Would it be possible to have a button or checkbox to make this happen automatically?

Bonus points if the tool is batchable (with gamma adjustment as a parameter)

Or is there already a tool that does this naturally? (None of the color->AutoCorrection seem to do much (except Equalize), and Equalize usually spoils the colors completely).
Comment 1 caulier.gilles 2012-08-08 19:16:07 UTC
We need an algorithm to adjust BCG settings automatically... Any proposal, link, url ?

Gilles Caulier
Comment 2 Alain Knaff 2012-08-08 20:17:29 UTC
I dunno... the histogram is displayed, so at some point it's probably stored somewhere.
Assuming the histogram x axis goes from 0 to 99, maybe we could do something as follows:

int min=-1;
int max=-1;
int i;
for(i=0; i<=99; i++) {
  if(histogram[i] != 0) {
    min=i;
    break;
 }
}

for(i=99; i>=0; i++) {
  if(histogram[i] != 0) {
    max=i;
    break;
 }
}

brightnessCorrection = 100-(min+max);
contrastCorrection = 100-(max-min);

I don't really know the digikam code that much, so maybe the numbers (bounds) probably need adjustment and/or scaling to make everything fit. The goal here is to tweak contrast/brightness such that the black part of the histogram stretches enough to fill the available space, without any black part being "cut" off, and without any part where y is 0 (or very small) left over near the bounds.
Comment 3 Marcel Wiesweg 2012-08-21 20:14:05 UTC
Reminds me of levels adjust, with some automatic determination of input range?
Comment 4 Alain Knaff 2012-08-22 15:29:27 UTC
Possibly... but it'd need a simpler UI
Comment 5 S. Burmeister 2012-08-22 16:18:33 UTC
Doesn't the auto-correction in the colours menu do that already?
Comment 6 Alain Knaff 2012-08-22 16:19:49 UTC
Unfortunately not (see my first comment)
Comment 7 S. Burmeister 2012-08-22 16:50:26 UTC
auto correction (I think the last option in it) does what levels adjust can be used for and hence imho what is needed to lighten up images that do not use the full spectrum/range.
Comment 8 caulier.gilles 2012-08-22 17:05:03 UTC
Just for info, AutoLevels code is in this dir, if you want to take a look to improve it :

https://projects.kde.org/projects/extragear/graphics/digikam/repository/revisions/master/show/libs/dimg/filters/levels

Gilles Caulier
Comment 9 caulier.gilles 2019-02-24 10:21:30 UTC
As S. Burmeister said in comment #5, stretch histogram feature is already implemented in Colors/Auto-color correction tool (available in BQM and Image Editor).

I close this file now.

Gilles Caulier