Developing a FOSS solution for inverting negatives



If anyone is still watching this, I am still moving this along :slight_smile:

I could use some maths assistance, I been researching various techniques, the filmic one posted here etc.

What I think I need is function, where values greater than say .8 are progressively scaled such that 1.2 becomes 1, any tips?

(Shreedhar Inamdar) #62

I am a professional mathematician. What you need is to shrink the length 0.4 to 0.2 so why not multiply by the factor 1/2? So the function is

f(x) =x for x upto to. 8 and then x+(x-0.8)/2 up to 1.2

Is this what you want?

(Alan Gibson) #63

I show two methods – linear and power – in Putting OOG back in the box


Thanks shreedhar.

I think so, that’s very helpful !, so easy to get yourself tied in knots, that you can’t see the wood for the trees. BTW I am trying to fit this part of a curve before a power function is applied to the normalised values.


Thanks alan, that’s very detailed I have been researching lift,gamma,gain.

Actually I now realise I want to apply a curve to the value from .8 to 1.2. and leave the values below .8 alone. (.8 and 1.2 are just illustrative, I would like to parametrise them)

(Alan Gibson) #65

Yes, my “power method” applies a curve just to the highlights, leaving values below 0.8 (or whatever you want) untouched. It can also apply a different curve to shadows, leaving values above 0.1 (or whatever) untouched. Values between the limits are unchanged.

In Power curve for shadow, mid and highlights, I show how to get a single power curve that changes all values, giving required values at the top, bottom and somewhere between. This is pretty much the same as lift-gamma-gain.

My pages at use ImageMagick and Windows BAT scripts (yeah, I know, hawk spit), but I try to explain enough so the concepts can be applied to any platform.


Thanks Alan,

I have been going through you scripts I converted the graph1d and graphline scripts to bash, that is very helpful to visualise things.

I am busy studying stepwise polynomial’s :slight_smile:

I have two math questions that may save me a lot of time…

  1. In the filmic tutorial the author says “Given those points, how can we form a continuous curve between them? One option would be polynomials, but that does not work well. These changes can be pretty sharp in linear space and fitting to polynomials will sometimes have undesirable concavity changes. Instead, we are going to use power curves.”

Should I just ignore that comment, as it doesn’t make all that much sense, I thought with polynomials could you can match any curve?

  1. Am I correct in understanding that for polynomials all exponents must be positive?

(Alan Gibson) #67

In standard polynomials, yes, all exponents are positive integers. If x is the input and y is the output, a polynomial of degree 2 is:

y = ax^2 + bx + c

So three parameters (a, b, c) specify the polynomial. Beware that some people write this as:

y = a + bx + cx^2

If we have (n) known correspondences between x and y, it is true that a polynomial of degree (n-1) can be found that passes exactly through those given points. But what does the curve do between those points? Sadly, it often does stupid things, going madly beyond what a human would consider sensible or desirable.

For that reason, we often prefer a series of joined paramaterised cubic curves (or Bezier curves or B-splines, they are all variations of the same thing). Each curve starts and ends at two of the desired points but its shape is influenced by two other points. Each curve joins to the next curve at one point, and has the same slope and curvature.

Bezier curves passing through given points more closely follow what a human would draw. Gimp and other editors use them in the “curve editor”. (Though I don’t like the Gimp curve editor because it can cause clipping.)

A power curve, in the form …

y = a*x^p + b

… has parameters a, p and b, and these have fairly intuitive meanings (“gain”, “gamma” and “lift” in some editors). They are easer to calculate than Beziers, and are better-behaved than polynomials.

EDIT: corrected the counting of degrees.

(Shreedhar Inamdar) #68

This is a quadratic polynomial, not cubic. In general, due to the constant term, one needs n+1 constants to describe a polynomial of degree n.

(Alan Gibson) #69

Oops, yes, thanks for the correction. I’ve fixed the post (I hope). Degree (n) means there are (n+1) terms, and thus (n+1) coefficients.

(Colin Paul Adams) #70

No it doesn’t. Degree n just means the highest power present is n. Lower powers might have zero coefficients.

(Shreedhar Inamdar) #71

Zero is also a coefficient!

(Alan Gibson) #72

Yes, okay, my statement should have said: Degree (n) means there are up to (n+1) terms, and thus (n+1) coefficients, but coefficients other than the top one can be zero.

I try not to get hung up on terminology (I don’t actually care what “degree” means), but I used the term so I should get it right.


I got a working simulation of negative/positive colour film camera working that is reasonably accurate/authententic. i.e. its not just negate. Using Kodak Porta 400 as a model.

You can make a colour negative of any jpeg picture.

becomes this

which becomes

The simulation is to help understand the negative/positive process a little better, and to try ideas out.