# Algorithm to find characteristic curve

Discussion in 'B&W: Film, Paper, Chemistry' started by L Gebhardt, Feb 27, 2009.

1. ### L GebhardtSubscriber

Messages:
1,769
Joined:
Jun 27, 2003
Location:
NH
Shooter:
Large Format
This is a long shot, I'm sure. I'm thinking of writing a simple web utility site to work with film and paper curves. Sort of a shared BTZS database. I'm running into a major issue in that I'm not sure how to convert a series of data points into an accurate equation so I can describe the curve. This is needed to draw the curve, and more importantly pull off accurate intermediate values especially in the toe and shoulder areas.

I know I could just interpolate between points, but that isn't very accurate except in the straight line portion.

So, any math majors out there who can point me to the right curve fitting algorithm?

2. ### Chan TranMember

Messages:
2,386
Joined:
May 10, 2006
Location:
Aurora, IL
Shooter:
35mm
Curve fitting would work for the straight portion but would not work for the toe and shoulder areas. To do a curve fitting you would first find a mathematical function that describe the behavior of the curve and then fit the data point on it.

3. ### Ray RogersMember

Messages:
1,555
Joined:
Aug 27, 2005
Location:
Earth
Shooter:
Multi Format
I have had a similar need...

I have the least math skills here, so try not laugh too loudly.

I think that is exactly what is being asked...
How does one find a mathematical function that describes the behavior of a curve?

That is,
How can a mathematical function be derrived (produced/created) from a curve, once the curve exists?

Is there some software that allows you to plot data points for x & y, draw the curve (for visual conformation) and then describe it in terms of an equation?

and that is simple to use....

Last edited by a moderator: Feb 27, 2009
4. ### ntennyMember

Messages:
2,283
Joined:
Mar 5, 2008
Location:
San Diego, C
Shooter:
Multi Format
I'm a math Ph.D., but not in numerical analysis, so I'm a little outside my area of real expertise here.

Curve fitting and interpolation are a huge area of applied mathematics with a lot of well-known algorithmic tools. In this case, we've got N data points and want a curve that hits all of them exactly; this can always be done with a polynomial of degree N (the Wikipedia article at <http://en.wikipedia.org/wiki/Polynomial_interpolation> has the details, but basically it involves solving N linear equations in N unknowns, which is simple enough in principle but algorithmically brutal if N is really large).

That curve is always guaranteed to hit the N points you chose to fit it to, but outside that range it could do absolutely anything. This means that for a characteristic curve, you'd better include some points through the shoulder and toe regions, and the further out you can get data from those regions, the better.

There are more complicated methods for fitting a polynomial curve approximately to more than N points, or for fitting other types of curves.

Any general-purpose mathematical software like Matlab will include basic curve-fitting functions; I googled "curve fitting windows download" and found a bunch of freeware for Windows, but I have no idea how well any of it works. It sounds, though, like that's the family of software that the original poster wants to be playing around with.

The problem Ray Rogers asks about, drawing a curve and finding an equation to fit it, is in practice the same problem as described above, writ large---this is because a "curve" on a computer screen is just a finite set of pixels, so you're really trying to find an equation that hits a very large number of points. The mathematically pure version of this problem isn't really solvable---there are lots of functions for which no formula can be written down in any reasonable way.

Um, does this post make it better or worse?

-NT

Last edited by a moderator: Feb 27, 2009
5. ### Chan TranMember

Messages:
2,386
Joined:
May 10, 2006
Location:
Aurora, IL
Shooter:
35mm
There are comercial software that would simply take your data points and find a mathematical function that best fitted to your data points. Most of these programs would try to fit the data point into some known function (i.e. linear, logarithmic, exponential, power...). I don't think the shoulder and toe portion would fit into any of these functions.
To derive a mathematical function for a curve, one must study and find out why the curve behaves that way. In the straight line portion we pretty much know (we may not know exactly why) or at least assume that the density is proportional to exposure. For the toe and shoulder I can tell that the rate of change for density is less than the change in exposure but I don't know in which manner.

6. ### Photo EngineerSubscriber

Messages:
25,894
Joined:
Apr 19, 2005
Location:
Rochester, NY
Shooter:
Multi Format
The best method of fitting the characteristic curve comes from use of a cubic spline. Here is a reference:

http://en.wikipedia.org/wiki/Spline_(mathematics)

We use this in most all of our software, or at least did when I worked in the area.

PE

7. ### John WMember

Messages:
122
Joined:
Jul 24, 2008
Location:
Seattle, WA
Shooter:
4x5 Format
Ah, PE beat me to it. In short, you don't want a single function to describe these curves. Splines provide that because they are piecewise defined over the available data points.

8. ### Anon YmousMember

Messages:
1,480
Joined:
Feb 7, 2008
Location:
Greece
Shooter:
35mm
Ok, I was thinking about plotting characteristic curves too and splines seemed to be the best solution. Now that PE confirmed it, I'd like to ask a question too. Would it be possible to make a reasonably good densitometer? I was thinking about making a circuit with a photosensitive component like a CdS cell (photoresistor) or a photodiode. The circuit would have an amplifier (op amp?) and I'd take a voltage reading with a multimeter. So, has anyone tried this?

9. ### Photo EngineerSubscriber

Messages:
25,894
Joined:
Apr 19, 2005
Location:
Rochester, NY
Shooter:
Multi Format
The problem is building the integrating light "sphere".

Light must go in at one angle and be reflected and collected properly for prints and it must go in at 90 degrees for film and then be integrated in a collection sphere with a photo detector inside. The light source must be of a given or given but variable wavelength and the whole thing must somehow be calibrated.

Yes, it can be done, but it is not just exactly what you have in mind.

This is not a simple task.

PE

10. ### Anon YmousMember

Messages:
1,480
Joined:
Feb 7, 2008
Location:
Greece
Shooter:
35mm
The "plan" (of which some parts I found somewhere, don't remember where) was this:

1) Shoot a grey card at different exposures, simulating different zones.
2) Process it.
3) Turn off the lights and turn on the enlarger.
4) Take a reading with the densitometer without a negative. That should be zero density.
5) Take a reading of a blank shot. That should be film base + fog.
6) Take the rest of the readings with progressively denser frames.
7) Calculate the logs of the readings and plot the curve.

I'm not interested in prints. I only want to experiment with films. I also have a feeling that there's no need for calibration. Since I'd take a reading without a negative in the carrier, this reading would be 0 density. The difference between frames must be all I need to get a plot. The wavelength of the light source is something that I didn't think of though.

Last edited by a moderator: Feb 27, 2009
11. ### L GebhardtSubscriber

Messages:
1,769
Joined:
Jun 27, 2003
Location:
NH
Shooter:
Large Format
I've never built a densitometer, but my RH Designs Alalyser has the capability to work as one. I've checked it against an X-Rite one I have and it is right on (relative values only).

12. ### L GebhardtSubscriber

Messages:
1,769
Joined:
Jun 27, 2003
Location:
NH
Shooter:
Large Format
Thanks, that should be enough to get me started. Now I just need to figure out how to program it.

13. ### Anon YmousMember

Messages:
1,480
Joined:
Feb 7, 2008
Location:
Greece
Shooter:
35mm
I've no reason to believe that the aforementioned analyser is bad, but...

1) I'm, ahem, cheap!
2) I have a tight budget.
3) I have an itch.

15. ### L GebhardtSubscriber

Messages:
1,769
Joined:
Jun 27, 2003
Location:
NH
Shooter:
Large Format
I should have expanded on this to say that the probe is a fairly simple looking thing and probably uses a cell like you mention. So, I'm sure it's possible. Just use the enlarger as a light source. You would need a calibrated step wedge to correlate the voltages to density.

16. ### Anon YmousMember

Messages:
1,480
Joined:
Feb 7, 2008
Location:
Greece
Shooter:
35mm
Maybe not. See post #10 in this thread.

17. ### Photo EngineerSubscriber

Messages:
25,894
Joined:
Apr 19, 2005
Location:
Rochester, NY
Shooter:
Multi Format
You will find that Excel or most any spreadsheet program can make a quite good graph of sensitometric data. I have posted some of mine here.

PE

18. ### L GebhardtSubscriber

Messages:
1,769
Joined:
Jun 27, 2003
Location:
NH
Shooter:
Large Format
That's what I've found too. I also have the BZTS plotter program. But if I want to automate the process of reading a point off of a curve, say the exposure for 90% of DMAX I can't do that with Excel.

I figure if all these program can nicely plot the line it shouldn't be too hard to get a nice function for each data set.

19. ### df cardwellSubscriber

Messages:
3,341
Joined:
Jul 16, 2005
Location:
Dearborn,Mic
Shooter:
Multi Format
Tough one. First, you have to choose whether you are setting out to predict, or describe, what the film is doing.

If you master the 'predictive' testing, you've made a lovely graph and cut off your creative future at your knees. Choose wisely. BTZS considered, it is just a beginning. Add imagination to the business of reproducing a perfect tone curve, and you will get photography, not numerology.

20. ### Photo EngineerSubscriber

Messages:
25,894
Joined:
Apr 19, 2005
Location:
Rochester, NY
Shooter:
Multi Format
Well, you have to consider that many densitometers made nowdays have parallel and serial ports including USB. These can be connected to the computer to read the data, and a simple program can convert the data to row-column format for Excel. I've done this and it is fairly easy. I no longer have a copy of it, as it was written years ago (80s) and was used at Kodak for a number of chores including inverting row with column and sorting. This was before Excel or Lotus had those features.

PE

21. ### ic-racerMember

Messages:
7,484
Joined:
Feb 25, 2007
Location:
Midwest USA
Shooter:
Multi Format
For me getting the curve is not the problem. Solving a polynomial or cubic spline to get some useful data from it would be helpful. For example solving (X) for, say (Y=0.1) is the difficulty I have encountered.

For example, I got a good 4th order polynomial fit with this Delta400 in T-max developer curve:
f(x) = 5.480380E-2*x^4 + -2.520940E-1*x^3 + 3.262913E-1*x^2 + -6.918132E-1*x + 1.568020E+0

But solving it for Y=0.1 is time consuming, even with a computer. I found it easier to just graph it and pick up any needed value off the graph.

But if you were to write some software to easily solve a polynomial like this or a spline, that would be great. It would also be nice to have it solve for the X-intercept of a least-squares fit through the straight-line portion (another way to estimate speed as PE has pointed out in a related thread).

22. ### Photo EngineerSubscriber

Messages:
25,894
Joined:
Apr 19, 2005
Location:
Rochester, NY
Shooter:
Multi Format
IC;

That equation can be used directly in Visual Basic with little modification and the plot routine will draw the requisite curve. VB can be used to input serial data, solve the equation and plot it. That is how we did our pre-run predictions and then the post process run-time data. We also integrated flow rate vs time to derive volumes of solution needed.

Everything is there in VB or C++. We used both. The VB formed the front end screen and the C++ did the number crunching from a DLL.

PE

23. ### L GebhardtSubscriber

Messages:
1,769
Joined:
Jun 27, 2003
Location:
NH
Shooter:
Large Format
I've found that film curves are fairly easy to get a polynomial to fit with, but paper curves don't work so well. I hope the cubic spline is going to work well for this.

The solving for Y=.1 is exactly what I am hoping to accomplish programatically. I may need to go to an iterative estimate (just now looking at some CubicSpline code), but it should be more than good enough for what I want. It's not like I will need to efficiently solve millions of them a second.

24. ### Lee LMember

Messages:
3,247
Joined:
Nov 17, 2004
Shooter:
Multi Format
You probably want to take a look at Curvexpert 1.34 at http://userpages.xfoneusa.net/~dhyams/cmain.htm

It's MS Windows freeware, but I run it under linux. It does many kinds of curves. If you look at the screenshot on the home page, it looks very much like an H&D curve.

More often I use an openoffice calc spreadsheet and have it smooth the curve through data, but it only does regression for straight lines, logs, power, and exponential curves. When I do have a known polynomial equation, I plug in X data and let it calculate Y, then do an XY plot chart to show the curve. I believe that Excel will do polynomial regressions to a relatively high order, but it's been years since I used it.

Another cool tool that I use to derive equations for manufacturers data is g3data that comes with my OS. You can find screen shots and how to install in MS Windows from http://www.frantz.fi/software/g3data.php

To use g3data, I scan or save a graph from a .pdf. It generates data by scaling the x and y axes, then "tracing" the curve, as shown on the home page, which I then pull into openoffice calc or curvexpert for analysis. This graph (a .pdf) http://www.apug.org/forums/attachment.php?attachmentid=13231&d=1232553771 is one from data put into openoffice calc then a regression curve was plotted and the formula for that curve displayed. Openoffice will save graphs to many formats, including .pdf.

Lee

25. ### Kirk KeyesMember

Messages:
3,267
Joined:
Jun 17, 2004
Location:
Portland, OR
Shooter:
4x5 Format
I wrote and excel macro and it uses simple linear interpolation between two adjacent points. You enter your base+fog, and then add 0.1 to it and then find the points that bracket the density value of base+fog+0.1. When you know the points on either side, then use linear interpolation to determine the exposure. Then add 1.05 to base+fog+0.1 (or whatever value you want to use for your paper range), and then find the exposures that bracket that density, and then linear interpolate to exposure that equals base+fog+0.1+1.05.

I put in values from the BZTS book into this spreadsheet and I get very similar answers to BZTS.

Once you can do that, then you can figure out splining curves and all...

26. ### Kirk KeyesMember

Messages:
3,267
Joined:
Jun 17, 2004
Location:
Portland, OR
Shooter:
4x5 Format
You don't really need to bother with fitting all the stuff on the straight line portion, so why bother with it!