Bug 304811 - Offer a "stretch histogram" functionality to automatically adjust brightness & gamma
Summary: Offer a "stretch histogram" functionality to automatically adjust brightness ...
Status: RESOLVED FIXED
Alias: None
Product: digikam
Classification: Applications
Component: Plugin-Editor-BCG (show other bugs)
Version: 1.4.0
Platform: Ubuntu Linux
: NOR wishlist
Target Milestone: ---
Assignee: Digikam Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-08-08 17:56 UTC by Alain Knaff
Modified: 2019-02-24 10:21 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In: 6.1.0


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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