Jack Hogan
Veteran Member
While I was acting as Jim Kasson's coolie a couple of months ago as he coded up an excellent Photon Transfer matlab application, I came across this interesting tidbit on curve fitting that I would like to submit to the scrutiny of the forum. All data was collected by Jim with his usual professionalism by taking raw capture pairs of a defocused uniform patch from highlights to the deep shadows. Each pair was added to determine mean signal (S) and subtracted to obtain the relative standard deviation (total random noise N). The effect of pattern noise and PRNU is thus effectively minimized, producing data that should depend entirely on the signal, shot noise and read noise only.
SNR** is simply S divided by N and here is Jim's data for the green channel of a D810 at base ISO plotted as a function of Signal on the x-axis (zero stops is clipping/saturation, otherwise known as FWC in some circles):
Jim Kasson's SNR Photon Transfer data from the green channel of a Nikon D810 at base ISO
Note how the data is linear in the highlights because SNR there is virtually all due to the square root of the signal (also equal to shot noise) which plots as a straight line on a log-log scale. The slope is correct (quadrupling the signal doubles the SNR because of the square root) and there is no sign of PRNU, thanks to Jim's excellent technique and pair subtraction. The data deviates from the ideal shot noise SNR straight line in the shadows because Read Noise, always present and adding in quadrature, becomes dominant there. In fact the data appears to fit the incoherent-noise-adds-in-quadrature model so well that if we were able to fit a curve to it built on that model we could extract read noise and other parameters directly from it, more or less like so
Clipping (FWC) can be estimated by checking where the model intersects the y-axis, representing full scale; read noise (RN) by subtracting in quadrature shot noise (obtained from the green line) from total noise (obtained from the red line)
Getting the best curve fit is critical to obtaining accurate estimated parameters, as shifting the curve left or right will clearly result in different read noise and FWC values. Most fitting algorithms choose the best fit based on minimizing the least square error (LSE) between actual data and the model: they simply add up the difference between the actual data point and the relative model prediction squared and find the solution to the quadratic equation that will minimize the sum. Here is the LSE curve fit for our data performed by Excel Solver:
Curve fit resulting from minimizing the least square error (LSE) between the model and actual data
This fit results in a base ISO input-referred read noise for the D810 equal to 5.00e- and FWC equal to 82539e-, which yields an eDR***=14.0 stops. Compare this to DxO/sensorgen.info (RN=5.5e-, FWC=78083e-, eDR=13.8 stops) or Bill Claff's charts (RN=1.076DN or approximately 5.45e-, eDR=13.8 stops). Recall that DxO/Sensorgen averages the four channels while the measured data above refers to the green channel only. I am not sure what channels Bill uses for his estimates.
Pretty good, huh? But if we look closer, while the fit appears good in the highlights and mid-tones it doesn't quite satisfy in the deep shadows:
LSE a good fit? Each dot spans about 0.2 stops.
The reason for this discrepancy is that the absolute error in the shadows is a couple orders of magnitude less than the absolute error in the highlights. Therefore the highlights are (too) heavily weighted in the sum of squared errors overwhelming the errors in the shadows, which end up counting very little in the choice of parameters for the modeled curve. But we know that we do not need all that precision in the highlights: shot noise there is relatively massive, with standard deviation spanning several raw levels; besides, the curve in the highlights is a straight line of known slope. The real test of the accuracy of the fit is in the shadows, exactly the opposite of the weighting resulting from the LSE criterion.
So let's try a different criterion for best fit, one that effectively minimizes the percentage error at every measured point, with equal weighting for data throughout the curve****, from deep shadows to highlights: mathematically, if I've got it right, it is the sum of the absolute log values of the ratio of the measured data to the model = sum(ABS(LOG(measuredSNR/modeledSNR))). Here is the resulting curve fit, also performed by Excel Solver:
Curve fit by minimizing the sum of the absolute log of the ratio of measured to modeled
Zooming in on the deep shadows:
Curve fit by minimizing the sum of the absolute log of the ratio of measured to modeled
Right. With this, imho, better fit the Read Noise is 4.27e- and the FWC 80174e-, for an eDR of 14.2 stops in the green channel*****, down from 5.00e-, 82539e- and 14.2 stops respectively for the original LSE fit.
It appears to me that for this type of analysis LSE curve fitting gives less accurate results than possible with other criteria.
What do you think? And any suggestions for optimal criteria for this application?
Jack
** I prefer to use SNR for Photon Transfer analysis, as opposed to alternatives based on variance for instance, because the parameters we are interested in (read noise and FWC) can be determined directly without having to estimate a third unknown: gain/sensitivity.
*** I am using the simplified definition of engineering Dynamic Range in this post, with the denominator equal to the read noise.
**** Yes, in this case data points are denser in the shadows than in the highlights and ideally we would maintain equal spacing in the measurements. As mentioned, however, the highlight fit is just a straight line: in theory two points would be enough, in practice the more the better to average errors out. Here we have data at every 1/3 stop, plenty.
***** Note that if we wanted to use the formal definition of engineering DR (with the denominator equal to the signal at which SNR =1), we could simply read it off the x-axis intercept in the graph, or approximately 14.0 stops.
SNR** is simply S divided by N and here is Jim's data for the green channel of a D810 at base ISO plotted as a function of Signal on the x-axis (zero stops is clipping/saturation, otherwise known as FWC in some circles):
Jim Kasson's SNR Photon Transfer data from the green channel of a Nikon D810 at base ISO
Note how the data is linear in the highlights because SNR there is virtually all due to the square root of the signal (also equal to shot noise) which plots as a straight line on a log-log scale. The slope is correct (quadrupling the signal doubles the SNR because of the square root) and there is no sign of PRNU, thanks to Jim's excellent technique and pair subtraction. The data deviates from the ideal shot noise SNR straight line in the shadows because Read Noise, always present and adding in quadrature, becomes dominant there. In fact the data appears to fit the incoherent-noise-adds-in-quadrature model so well that if we were able to fit a curve to it built on that model we could extract read noise and other parameters directly from it, more or less like so
Clipping (FWC) can be estimated by checking where the model intersects the y-axis, representing full scale; read noise (RN) by subtracting in quadrature shot noise (obtained from the green line) from total noise (obtained from the red line)
Getting the best curve fit is critical to obtaining accurate estimated parameters, as shifting the curve left or right will clearly result in different read noise and FWC values. Most fitting algorithms choose the best fit based on minimizing the least square error (LSE) between actual data and the model: they simply add up the difference between the actual data point and the relative model prediction squared and find the solution to the quadratic equation that will minimize the sum. Here is the LSE curve fit for our data performed by Excel Solver:
Curve fit resulting from minimizing the least square error (LSE) between the model and actual data
This fit results in a base ISO input-referred read noise for the D810 equal to 5.00e- and FWC equal to 82539e-, which yields an eDR***=14.0 stops. Compare this to DxO/sensorgen.info (RN=5.5e-, FWC=78083e-, eDR=13.8 stops) or Bill Claff's charts (RN=1.076DN or approximately 5.45e-, eDR=13.8 stops). Recall that DxO/Sensorgen averages the four channels while the measured data above refers to the green channel only. I am not sure what channels Bill uses for his estimates.
Pretty good, huh? But if we look closer, while the fit appears good in the highlights and mid-tones it doesn't quite satisfy in the deep shadows:
LSE a good fit? Each dot spans about 0.2 stops.
The reason for this discrepancy is that the absolute error in the shadows is a couple orders of magnitude less than the absolute error in the highlights. Therefore the highlights are (too) heavily weighted in the sum of squared errors overwhelming the errors in the shadows, which end up counting very little in the choice of parameters for the modeled curve. But we know that we do not need all that precision in the highlights: shot noise there is relatively massive, with standard deviation spanning several raw levels; besides, the curve in the highlights is a straight line of known slope. The real test of the accuracy of the fit is in the shadows, exactly the opposite of the weighting resulting from the LSE criterion.
So let's try a different criterion for best fit, one that effectively minimizes the percentage error at every measured point, with equal weighting for data throughout the curve****, from deep shadows to highlights: mathematically, if I've got it right, it is the sum of the absolute log values of the ratio of the measured data to the model = sum(ABS(LOG(measuredSNR/modeledSNR))). Here is the resulting curve fit, also performed by Excel Solver:
Curve fit by minimizing the sum of the absolute log of the ratio of measured to modeled
Zooming in on the deep shadows:
Curve fit by minimizing the sum of the absolute log of the ratio of measured to modeled
Right. With this, imho, better fit the Read Noise is 4.27e- and the FWC 80174e-, for an eDR of 14.2 stops in the green channel*****, down from 5.00e-, 82539e- and 14.2 stops respectively for the original LSE fit.
It appears to me that for this type of analysis LSE curve fitting gives less accurate results than possible with other criteria.
What do you think? And any suggestions for optimal criteria for this application?
Jack
** I prefer to use SNR for Photon Transfer analysis, as opposed to alternatives based on variance for instance, because the parameters we are interested in (read noise and FWC) can be determined directly without having to estimate a third unknown: gain/sensitivity.
*** I am using the simplified definition of engineering Dynamic Range in this post, with the denominator equal to the read noise.
**** Yes, in this case data points are denser in the shadows than in the highlights and ideally we would maintain equal spacing in the measurements. As mentioned, however, the highlight fit is just a straight line: in theory two points would be enough, in practice the more the better to average errors out. Here we have data at every 1/3 stop, plenty.
***** Note that if we wanted to use the formal definition of engineering DR (with the denominator equal to the signal at which SNR =1), we could simply read it off the x-axis intercept in the graph, or approximately 14.0 stops.
Last edited:








