


Algorithm/Numerical Approach for Computing CI (Contrast Index)
Recently I've been plotting my film test curves using R (sorry Bill), which I also use for smoothing them. I can calculate a myriad of gradients by getting a linear regression of any section of the fitted smooth curves, but I would like to code a procedure for calculating CI. I have used the handheld technique, using the CI "ruler" with points marked off at 0.2 and 2.2 log E, and I think I understand the concept of the two concentric arcs described here. I have also seen discussions about automating curverelated plotting in several threads:
While there is a lot of discussion about curve fitting, that is not one of my issues—I find that R fits a good enough curve for me. It usually does it using LOESS, and the fitted curve is a little odd just to the left of the point where the toe takes off, but this is not my concern, as the search for CI takes place further to the right of that point anyway, in the section where the curve seems to look good. Besides, I am sure it wouldn't be too hard to fix the wonky section if needed, after all the smooth fit uses splines.
What I would like to ask for, please, is a pointer towards a suitable algorithm to use the just found curve to calculate the CI. I assume no weird curve shapes, and generally good inputs. If nothing can be found, then I will be resigned to writing a short loop, that "walks" the curve looking for the intersection of the 3 points on a straight line, first at x=FB+F, the other distant 0.2 and lying on the curve and the third, distant from the first 2.2, and also on the curve. But I am sure someone must have already coded that in a more elegant way than just doing a brute search along the curve.
FYI, example of plots, I'd be happy to share the few lines of R code if anyone cares:
Many thanks.

If I were programming this, I'd mimic what I already do. I'd treat curves as triangles and solve for intersections. I'd do the same when it came to curves (I would solve them as triangles). Since I already physically slide back and forth to find where the curve crosses the two arcs at the same angle, I'd do the same thing by recursively trying different points, until I get within 0.01 of the answer.

What on earth are you talking about?
“The contemplation of things as they are, without error or confusion, without substitution or imposture, is in itself a nobler thing than a whole harvest of invention”
Francis Bacon

Last edited by icracer; 08302013 at 10:22 PM. Click to view previous post history.

Originally Posted by cliveh
What on earth are you talking about?
One measure of a film's characteristic curve is how steep it is. Gamma is one name for the slope of the curve. Think of 45degrees as 1.0 because for every unit of exposure difference on the film you get one unit of density difference on the negative. 0.0 would be if you forgot to develop the film. Infinity would be where it goes instantly from clear to black. (Actually that is unlikely to ever happen, and a special meaning is given to the term: "Gamma Infinity"  which is the "most contrast you will ever get" in that developer, no matter how long you develop it, even if it's only 1.5 or 2.0.)
Contrast Index is another term used to describe the slope of the curve. Contrast Index and Gamma just take two points on the curve and calculate the slope of them, they don't use curve fitting to describe the curve, it's just a straightline between two points. The two differ from each other by the choice of endpoints you measure.
Contrast Index uses a couple points spread out about as far apart as the part of the film you would normally use to print from. So it has the advantage of relating development to meet printing needs. Think of a protractor with an inner arc and an outer arc that you slide left and right until both arcs touch the line at the same angle (marked as slope to the center of the arcs). That's all Rafal wants to do, but he wants to do it with a computer program instead of on paper.
Contrast Index Meter
Here is a graph of Rafal's film tests, with "C" marks on each curve showing the two endpoints used to determine Contrast Index.
The ASA triangle is also shown, it is very specific, and Rafal luckily hit it at 11 minutes. Note that even though the ASA triangle literally measures 0.62 slope by the points that define it, the Contrast Index of that same curve is 0.75  significantly different...
If I had a Normal scene, I would develop it 7 minutes because I aim for specific CI and for Normal I would aim for 0.62 CI. If I used Gamma instead, I might arrive at a different recommend developing time for Normal, and if I were to develop to ASA standard, I'd possibly develop 11 minutes.
Last edited by Bill Burk; 08302013 at 11:35 PM. Click to view previous post history.
Reason: crossplatform link

Sponsored Ad. (Subscribers to APUG have the option to remove this ad.)

Thank you, Bill, for the suggestion of solving triangles. Dale, I'd love to have a look at those spreadsheets, I suppose I know enough Excel. I'd still plan to lift the logic into R, as I find it easier and faster to manage the data+code+plotting (ggplot2) in it for my film tests. I'd be happy to share the resulting code. Having said that, it seems like you're "walking" along the axis, similar what I thought of doing. I wonder if there is some more holistic approach (solving geometric inequalities?) that doesn't involve checking all the points, until a certain precision of the solution has been reached. Many thanks, everyone.

Contrast Index is something that Kodak came up with to replace the traditional Gamma for their films. It never really caught on with other manufacturers.
A rock pile ceases to be a rock pile the moment a single man contemplates it, bearing within him the image of a cathedral.
~Antoine de SaintExupery

Rafal,
I am the fool who started the first of the APUG threads you listed, in which I suggested a simple mathematical function for fitting densitometric data. Suffice it to say that my methods were not instantly adopted by thousands of photographers, leading to the fame and fortune that I had imagined for myself. But, I have used that function to calculate the Kodak contrast index, and I think that I can suggest a general way to formulate the problem.
The key thing that is needed is a relationship between the exposure and density, which is presumably based on your measured data. I used the function I described, with fit values for the 3 parameters that define that function. Having an analytical function makes things a bit easier, but one could also use a table of closely spaced points.
Let's call the exposure values "x" and the density at a given value of x "D(x)". To use the Kodak definition, the exposure values should be given in log base 2 units (i.e. doublings or "stops"). The CI definition specifies 3 points that lie on a common line:
1. A point on the baseline, where density  (base + fog) = 0.
2. A point to the right of point 1 that lies on the curve and is 0.2 units away from point 1.
3. A point to the right of point 2 that lies on the curve and is 2 units away from point 2.
Call these points:
x1,D(x1)
x2,D(x2)
x3,D(X3)
From Pythagoras, the relationships among the points can be written as:
(x2  x1)^2 + (D(x2)D(x1))^2 = 0.2^2
(x3  x2)^2 + (D(x3)D(x2))^2 = 2.0^2
(x3  x1)^2 + (D(x3)D(x1))^2 = 2.2^2
This gives three equations in three unknowns. Once the values for the three x values are known, then the contrast index can be calculated from the slope of the line, using any pair of points:
CI = (D(x3)D(x2))/(x3x2)
Solving the equations has to be done numerically, i.e. iteratively, at least for my analytical function or a table of data points. This requires a starting guess for the three x values, but that isn't too difficult.
I have done this in Python, using the optimize.fsolve function in the scipy package, but I'm sure that similar functionality can found in R.
I hope that this is a bit of help. I'm happy to send you the Python code if that would be useful.
David

Hi David,
The clinker in the formula is the point is not 0.2 units to the right...
You have a baseline zero at B+F and two arcs, one with a radius of 0.2 units and the next with a radius of 2.2 units
You look for a condition where the curve, zeroed at B+F, crosses the two arcs at the same angle.

Bill,
My words may not have been as clear as I intended, but I think that the equations are correct. The equations define the distances between the points in two dimensions, not just the distance along the horizontal axis. (That's where Pythagoras comes in.) The first two equations define the distances between the first and second points (0.2) and the second and third points (2). The third equation ensures that all three lie on the same line. Also, D(x1) should be specified to be b+f.
David
Last edited by dpgoldenberg; 08312013 at 12:15 AM. Click to view previous post history.

