After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 125305 - Curves Dialog
Curves Dialog
Status: RESOLVED OBSOLETE
Product: GIMP
Classification: Other
Component: Tools
git master
Other All
: Normal enhancement
: ---
Assigned To: GIMP Bugs
GIMP Bugs
Depends on:
Blocks:
 
 
Reported: 2003-10-23 14:17 UTC by Jack Zagaja
Modified: 2005-06-20 14:43 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Jack Zagaja 2003-10-23 14:17:56 UTC
Now - because some images have different than Gamma unbalanced grays
 we would choose different gray balance formula for Curves. GIMP has
 no option for that now. Consider a gray balance curve that has only
 one parameter and very good property that means you will get linear
 shadows and highlights - this is well known Shlick mapping method:

 p parameter can be greater or smaller than 1.0:

 http://tme.szczecin.pl/~jacek/temp/Graphs/shlick.gif

 p = ( Grey*({R'G'B'}-2^bits) )/ ( {R'G'B'}*(1-2^bits) )

 and RGB channels can be remapped using Shlick formula as follows:

 {R'G'B'} = p*{R'G'B'} / ( p*{R'G'B'}-{R'G'B'}+2^bits )

 This is very simple and robust method since can be written as Look Up
 Table. Now if you implement that tools then GIMP will be useful as others
 like Photoshop and Picture Window or PSpro. 

 Consider a histogram into the Curves Dialog - linear off course. 

Regards --Jack,
Comment 1 Daniel Rogers 2003-10-23 18:44:10 UTC
I am having trouble understanding this report.

For one thing, I don't think you have defined your formula very well.  Is { } a vector 
notation?  Are you impling element by element operations on the elements in { }?  
Also what is the domain of definition of R', B', G'?  Is each color element meant to go 
from 0<=X'<=1?  What is the normalized form of this equation?  Can you explain in 
words what this equation is supposed to be doing, or a technical reference describing 
it?

So, are you suggesting that the curves dialog be implements as this single parameter 
adjustment?  It is fast, but I am not sure I see why this is good.  Please help enlighten 
me.  Our current dialog lets you create fairly arbitrary remappings of the intensities, 
which is often useful.

Also, when you say you want to add a "linear" histogram do you mean perceptually 
linear or linear in power?
Comment 2 Jack Zagaja 2003-10-23 19:18:33 UTC
Hello Daniel,

{} means for each element from set. You don't need to go deep to 
understand this. I've just used one line, short form of equation. For 
every pixel with nonlinear luminance denoted as R' G' B' you have to 
set p parameter of Shlick intensity mapping. This parameter is 
derived from Luminosity value of NTSC weights at each R'G'B' pixel.

So add "Grey" button and picker size - user clicks on image and GIMP 
computes Grey value and correlated p parameter for each R'G'B' 
channel. There are much more images with unbalanced grays that follow 
this law than Gamma.

Linear histogram means always the same - counts pixel value. We don't 
use log scaling because it pushes low values. Add luminosity weights 
instead of odd "Value".

BTW: there are no technical paper for that - this is our (very 
simple) idea.

Cheers --Jack,
Comment 3 Sven Neumann 2003-10-24 10:52:40 UTC
The histogram in Curves tool dialog is handled in bug #71633.
Comment 4 Jack Zagaja 2003-11-05 13:22:43 UTC
Hello,

You forgot about white/black/grey points discussed in this report !!!

BR --Jack,
Comment 5 Sven Neumann 2003-12-04 15:56:16 UTC
The curves dialog is about being able to freely choose a correction
curve. I have not the slightest idea how the formula you've given fits
into this picture.
Comment 6 Jack Zagaja 2003-12-09 22:57:40 UTC
 Sven  -  your  arguments  seems to be more obscure than our idea. You
 forgot  about  one  truth  -  there  are  no  white  and gray balance
 algorithms available in public. That's only your know-how and we name
 our  curves  "Shlick"  but  the  effect  can  be  obtained using many
 mathematical tools.
 
 "Most people seem to be happy with the current state" sounds like you
 just  don't  want to listen to users who are unhappy with the current
 state.  Serious photographers use professional editors or specialized
 application  for  color corrections (e.g. Color Washer from my friend
 Harrald  Heim).  It  looks  like those people you have mentioned have
 small  amount  of knowledge about DTP at all. They use GIMP for image
 cutting and to make some tasteful borders and text on it.


 There  are  plenty of cheap application (Paint Shop Pro, Picture Man,
 Picture  Window)  for  Windows  that  offers 16 bits editing and gray
 balance algorithms based on Shlick and Gamma as a standard. This is a
 standard in those days!

 Now  take a look at my screenshots. You will see a slide shot and you
 should  provide  at  least  two  types  of  non-linear  gray  balance
 algorithms.  Gamma  model makes wrong shadows (too much red) and even
 so the mid-grays are too warm. Shlick method is a right choice here !
Comment 7 Jack Zagaja 2003-12-09 23:01:48 UTC
And the missing screenshot ;)

http://tme.szczecin.pl/~jacek/temp/gimp.jpg
Comment 8 Simon Budig 2003-12-09 23:49:53 UTC
Jack:

Instead of assuming that we just conservatively try to avoid work you
should consider the idea that *maybe* you failed to explain your idea
to us up to now. Insulting us by implying that we just don't want to
listen certainly does not help your credibility for us.

You proposed a formula that supposedly makes it easy to do color
correction. According to you you invented it yourself and it gets used
in a tool from your friend.

That doesn't sound very convincing. Why should we implement a formula
with very much unknown quality?

Also Sven mentioned, that the Curves Dialog is not only about
correcting color casts, but also about giving the user the power to do
everything he wants: sine-like curves to create solarizing effects,
inverting the red channel of an image, correcting color casts.

Where do you see your formula embedded in this concept?

Maybe it is more useful to implement this approach in a plugin for a
specific purpose? Maybe your friend Harrald (or Harald?) is interested
to port his tool to the GIMP?
Comment 9 Jack Zagaja 2003-12-10 14:20:27 UTC
Simon,

Bloody hell You are really difficult guys :)

I presented all information that are required for implementation 
which is trivial for experienced programmers You are I think. If 
something is unclear then write precisely which part. List of 
applications with 2 non-linear formulas (Shlick and Gamma): 
Photoshop, Paint Shop Pro, Picture Man, Picture Windows - enough?

Please read carefully what was written here and 
then “quality”, “usefulness”, “fears” just will disappear.

Regards – Jack Zagaja,
Comment 10 Simon Budig 2003-12-10 14:27:01 UTC
It is unclear where you suggest to implement this in the UI. Where
should the user adjust the p-parameter? And since your proposed
formula is a subset of the curves dialog possibilities it is unclear
where you want to see it. It certainly is not an option to make a the
curves dialog a "Shlick correction dialog", since this would restrict
the user in his possibilities.

Sorry, just proposing a formula and claiming that it is the solution
to all color correction problems will not work.
Comment 11 Dave Neary 2003-12-10 14:56:06 UTC
Hi Jack,

I can understand your frustration since English is obviously not your
native language. Nor is it the native language of Sven or nomis
(although they get by OK ;-) ). I think that when you were intending
to come across as playful, your humour was mistaken for someone being
a little over-exigent.

So - just to step back a bit - there are a couple of confusing things
in the bug report. First, I am having some trouble seeing what the
change accomplishes, and second, I, like Simon, am not sure how it
would fit into the UI.

Are you suggesting that we have a grey picker (similar to the levels
tool) to pick RGB 50.5, 0.5, 0.5), and that based on this choice we do
a transform of the curve in the curves tool to reflect this choice?

If that's the case, how would you transform each channel? If we take
the case of, say, just the Green channel, say the mid-grey point
selected by the user is 0.55 - from that, how would we calculate the p
for the green channel? And then what is the form of the curvethat
results? 

I'm afraid I didn't follow your equations in the first comment. 

Thanks for your input,
Dave.

Comment 12 Jack Zagaja 2003-12-10 15:05:04 UTC
>It is unclear where you suggest to implement this in the UI

Do I talk with human being ? My second answer at the top:

“So add "Grey" button and picker size - user clicks on image and GIMP 
computes Grey value and correlated p parameter for each R'G'B' 
channel [...]”

I think that this not require a lot of imagination since I posted 
Photoshop screenshots :)
Just make Dialog similar to the Photoshop’s if it is a trouble.

> should the user adjust the p-parameter?

No it’s computed using averaged color reading from the point where 
user clicked. The p parameter control a curve shape.

>Sorry, just proposing a formula and claiming that it is the solution
>to all color correction problems will not work.

This is no a *magic solution* for all situations I repeating: this is 
a standard in those days. Other color correction routines can be 
always founded in plug-ins (http://www.thepluginsite.com/).

Regards -- Jack Zagaja
Comment 13 Dave Neary 2003-12-10 15:27:25 UTC
Hi Jack,

I really was trying to understand your request. I did read the entire
thread before adding my comment... it seems I understood you correctly
with what I said afterwards.

So you map the selected point to 0.5, 0.5, 0.5 (as we do in the levels
tool). And then for each channel, you have 
f(x) = x + 4 * x * (1 - x) * (g' - 0.5) 
where 0 <= x <= 1 and g' is the selected greypoint for the channel? Or
something like that?

Like I said, I had some trouble following your equations at the top.
Does this look like what you were intending?

Cheers,
Dave.
Comment 14 Simon Budig 2003-12-10 15:49:14 UTC
I fail to see from the screenshot how the dialog in Photoshop works.
I don't have Windows, I don't know how this works.

Also please note that there is a certain inconsistency in your
arguing. On one hand you call this a "standard method", on the other
hand you claim, that this is something simple that you and your friend
invented.
Searching Google for "Shlick color correction" does not yield any
useful resources.

The formula as described above apparently did not work when I tried to
plot a sample curve. It had a nasty spike where the denominator got
close to 0. It is perfectly possible that I did read it wrong. Also I
am not sure what "bits" it is referring to.

You write "p parameter can be greater or smaller than 1.0", in the
first screenshot you posted there is p>0 and p<0. Even though asked
for it you did not yet provide the value range for R, G, B.

I tried to understand the formula. I guess, that the basic idea is, to
calculate a p, so that - by calculating the corrected red value for
the red serving as a base for p - the grey value should be the result.

Now, I tried to insert the definition for p into the formula for the
correction and expected to be able to solve the equation quickly.

I failed. Not sure where the problem is, but there are lots of nasty
sums in the fractions. It simply does not resolve for me.

I tried it with

p = grey * (R - 2^bits) / (R * (1 - 2^bits))

R' = p * R / (p * R - R + 2^bits)

where R is the original red value, and R' is the computed new value.
grey is the grey level of the color where the R value originates from.

The 2^bits part is very dubious to me. I don't see why the number of
bits necessary to represent my colors should be relevant at all. I
guess that 2^bits is kind of "maximum possible value" (one too big
though).

Please reformulate the formulas so that R,G,B is a float in the range
from 0 to 1. I certainly hope that they get easier then.

Also you did not yet discuss what should happen when the user already
defined a curve in the dialog: Do all the control points get thrown
away when you select a grey point?

How should the "click in the image to determine gray point" interact
with the current behaviour when clicking in the image?

As I said above: Just throwing a formula at us and say "please
implement it, it must be easy!" does not work. There are a lot of
things to consider, we have to care about existing behaviour etc. pp.

Also my failure to get useful results from your formula does not
really make me trust it.
Comment 15 Jack Zagaja 2003-12-10 16:00:55 UTC
Dave,

You  are  absolutely right about English. My style is only a calque of
other  peoples  style  of  writing  because I learned a little of your
language  using  newsgroups  only.  Some abbreviations occurred out of
habit  to  peoples  from  sci.image.processing or sci.engr.color. This
topic  is  well  understandable  for  color  hobbyist  not  for strict
programmers.

>Are  you suggesting that we have a grey picker (similar to the levels
>tool)  to  pick RGB 50.5, 0.5, 0.5), and that based on this choice we
>do  a  transform  of  the  curve  in  the curves tool to reflect this
>choice?

Yes  the same buttons - white point, gray point and black point. White
and  black  points  appear  on  all  channels of course - gray only on
luminosity.  Suppose  user  clicked  at  the  gray object with R:G:B =
45:70:50. The first step is to compute luminosity and p parameters for
every channel:

Luminosity  =  0.299*R'  + 0.587*G' + 0.114*B' = 0.299*45 + 0.587*70 +
0.114*50 = 60.


P(red)  =  Grey*(R-2^bits)/(R*(1-2^bits)) = 60*(45-255)/(45*(1-255)) =
1.10

P(green) = 60*(70-255)/(70*(1-255)) = 0.62

P(blue) = 60*(50-255)/(50*(1-255)) = 0.96


Influence  of  green channel is strong which comes from all luminosity
weights  (humans color sensitivity). Now the last step is to apply LUT
using very simple and robust Shlick formula:

R' = 1.10*R /(1.10*R - R + 255) r channel
G' = 0.62*G /(0.62*G - G + 255) g channel
B' = 0.96*B /(0.96*B - B + 255) b channel

This  3  curves  that  should be applied on every channel are shown in
Photoshop screenshot. It would be nice to show user a calculated curve
on  Curves Dialog at each channel separately (luminosity channel stays
unchanged of course).

With kind regards -Jack,
Comment 16 Simon Budig 2003-12-11 00:47:53 UTC
Ok, I sat down and did some math to understand whats going on here.

1) The p<0 and p>0 annotation in your very first graph is simply
wrong, that should read p<1 and p>1.

2) The 2^bits part is simply wrong. Your examples show that you refer
to the maximum value of the channel, which is 2^bits-1.

3) Your oh so simple and robust example does not work, because
       R' = 1.10*R /(1.10*R - R + 255)
gives R'=0.19 for R = 45. Wasn't the idea to get 60?

For the rest of this comment I operate on floats in the range from 0
(minimal intensity) to 1 (maximal intensity). Assuming that your
correction formula is correct it would translate to

   f(x) = p*x / ((p-1)*x + 1)

Some sample plots for different p indeed shows that it behaves nicely
and even is symmetrical to the y=1-x line. And Symmetry is always good
(this definitely is an advantage over the Gamma approach). Also f(0)=0
and f(1)=1. Very nice.

Solving this equation for p gives:

   p = (1-x)*y / ((1-y)*x)

where x is the source value and y=f(x) is the target value.
This obviously differs from your given equation, but has the advantage
of giving correct results (values are from the red channel):

x = 45/255 = 0.176
y = 60/255 = 0.235

p = (1-x)*y / ((1-y)*x) = 1.436

f(x) = p*x / ((p-1)*x + 1) = 0.235 = 60/255.

Now it apparently works.

Could you please doublecheck your math and compare it to my math?
Please confirm or decline my comments above.
Comment 17 Dave Neary 2003-12-11 08:57:20 UTC
Hi,

Perhaps I misunderstood Jack, but I thought that f(0.176) = 0.5 = that
is, since 45 is the grey point intensity, we'd map that way...

So I would do this.
x = 45/255 = 0.176
y = 127/255 ~= 0.5

p = (1-x)*y / ((1-y)*x) = 4.68 (a big p, but then the grey point is a
long way from 0.5)

f(x) = p*x / ((p-1)*x + 1) = 0.5 = 127.5/255.

So simon, what do you think? Is this something that we could include
at some stage?

Cheers,
Dave.
Comment 18 Simon Budig 2003-12-11 10:48:34 UTC
As far as I understood it, the idea is to map a color to its gray
value. I don't really understand why there are three color pickers in
the Photoshop Screenshots.

I think it is feasible to integrate this functionality, however I am
not  sure if the curves dialog is the correct place. It might me
feasible to have an own tool for correcting color casts and besides
this kind of correction also have the stuff pippin was working on.

I don't see this functionality in 2.0 right now, given the yet
unresolved math problems and unclear GUI proposal.

The way you understood it sounds wrong to me, because it might be hard
for the user to spot a point in the image that is about 50% gray.
Otherwise the image will change its brightness quite a lot.
Comment 19 Piotr Legiecki 2003-12-11 10:59:21 UTC
Hello

To Dave and Simon.

It seems to me that you consider the ideas from Jacek as something
nice but exotic. I wonder why? All this thread is only about gray
point picker for curves dialog. Thats all.

If there is (finally) gray point in Levels dialog (although not
working the way it should but it is in another bug report, please look
at http://bugzilla.gnome.org/show_bug.cgi?id=125303) so IMHO it is
only  a natural consequence to implement it in Curves dialog, just
like photoshop does it.

I hope that finally those mathematical formulas will be resolved and
everyone will benefit from better color manipulation tools in gimp.

Regards
Piotr Legiecki
Comment 20 Sven Neumann 2003-12-11 11:30:04 UTC
The Curves tool is about manipulating the colors using a curve. I
don't see how a color picker fits into the purpose of this tool.
There's a color picker in the Levels tool already (and it fits there).
What benefit would another color picker in the Curves tool give?
Comment 21 Jack Zagaja 2003-12-11 14:23:19 UTC
Thank  you  All  for contributing this post. Sorry for my "p" equation
mistake.  It  seems I was made quick solving without remembering about
RGB triplets normalization. Even so my first "p" equation was also odd
and  I  can't  figure  why  I  mess  it  up :) Simon - your normalized
equation is correct of course.

This was a cosmetics now Sven must be convinced. Any suggestions ? ;)

White/Black  color  pickers  should  be doubled in Curves because this
dialog has much better potential than Levels that are used for quicker
editing  or  pure  Gamma  changes (for example cinema gamma output). I
have no idea why Sven is so conservative here :(

WIth kind regards --Jack,
Comment 22 Sven Neumann 2003-12-11 14:36:07 UTC
I am not at all conservative. I simply refuse to work on a suggested
feature unless it is clearly explained. And that is not the case here.

Albeit being asked multiple times you have still not described what
exactly the color pickers should do. Of course I have an idea how this
could be implemented but I want you to write down a detailed
description of what should happen when one of the color pickers is
used. I assume that picking a color is supposed to modify the curve
somehow. Please tell us exactly what effect each of the pickers should
have on an existing curve. If you aren't able to give detailed
descriptions, you can't seriously expect us to start coding.
Comment 23 Dave Neary 2003-12-11 14:44:12 UTC
Hi Jack,

How would the white & black point colour pickers affect the
calculation of p and f(x) for the channels?

Can I summarise what I understand here? 

Each channel, and the Value channel, should have a white & black
colour picker.

The Value channel should also have a mid-grey picker.

Clicking on the White point or the black point with a channel selected
will change the white point (or the black point) for just that channel
(or all the channels if the Value channel is selected) to reflect the
appropriate value of the channel at the selected point. The curve will
keep the same grey point and black point, and recalculate p based on
the new white point (NB: what is this calculation?)

Is this right?

The behaviour of the grey point seems OK with the equation above, but
the part which is confusing me is if, say, I change the global grey
point, and then change (say) the white point for the red channel, what
do the curves look like?

Cheers,
Dave.
Comment 24 Jack Zagaja 2003-12-11 15:20:35 UTC
"you have still not described what exactly the color pickers should 
do"

Well  :) I assumed that some kind of free choice is good since You are
experienced  programmer  (generic idea would be sufficient). Photoshop
uses  IMO  the  same color picker are as chosen in color picker tool -
1x1,  3x3,  5x5.  You  would use the same tool setting here. Now after
average  color calculus one need to build a look up table. White/Black
points make first entry on that. When user clicked on gray button then
the  LUT  is changed as in equation. Using LUTs settings you can build
curve  shape  in  your curve dialog so if you do that in the past then
very small modification is needed.

Summary:

-  color  pickers  at  Value channel changes a curve shape only at RGB
channels separately

- color pickers on RGB channels overwrites Value pickers settings

-  color  pickers settings (9 variables) should be stored in array and
LUT can be calculated very fast.

With kind regards --Jack
Comment 25 Sven Neumann 2003-12-11 16:38:22 UTC
I am an experienced developer and I don't need any instructions on
implementation details. What I need is a detailed instruction of what
should happen to the curve when a color picker is used. From a users
point of view, please.
Comment 26 Jack Zagaja 2003-12-11 18:21:56 UTC
Everything is in my previous post Sven :) Thanks --Jack
Comment 27 Jack Zagaja 2003-12-12 21:51:33 UTC
Which interpolation method is used in GIMP Curves Dialog? It behaves 
differently than Photoshop's. Thank You --Jack,
Comment 28 Albert Cahalan 2004-11-14 03:18:19 UTC
This might be more usable if the current foreground color
were involved. Then the user does:

1. select color, in the normal way
2. use it to set the curves (via drag+drop or a button)

The grey point being used can be from there too, avoiding the need
to find a spot on the image that will become exactly 50% grey.
Comment 29 Sven Neumann 2004-11-14 11:16:48 UTC
Sorry, but I fail to understand that last comment (#28).
Comment 30 Sven Neumann 2005-01-03 18:19:17 UTC
IMO this bug report should be closed. It grew way too large, it's full of
unrelated and rather confusing descriptions and doesn't help anyone. If someone
wants to extract some good points from these comments, please open new bug
reports for them as this bug report is about to be closed soonish.
Comment 31 Michael Schumacher 2005-06-19 11:02:32 UTC
http://tme.szczecin.pl/~jacek/ ia gone, so I guess the bug reporter doesn't care
anymore.
Comment 32 Sven Neumann 2005-06-20 13:56:23 UTC
Closing as OBSOLETE then.
Comment 33 Jack Zagaja 2005-06-20 14:43:04 UTC
Gentelman,

My www address is now http://ucz.tme.szczecin.pl/~jacek/ and email is:
jzagaja-at-poczta.onet.pl.

Jack Zagaja, Szczecin University of Technology