Miscellaneous Algorithms

Here we discuss algorithms whose discussion doesn't seem to belong in any specific part of the overview.

Using Bresenham algorithm's to interpolate

When doing linear interpolation, it is possible to use a variant of Bresenham's algorithm (usually used in driving bit-mapped displays). Doing so is fast, and photo makes use of this trick. Apart from speed, and rounding errors, this is equivalent to a naive linear interpolator.

Interpolation

Given a set of pixel values, I[i], with one value (say I[0]) missing, how should we go about replacing it? Due to laziness on the part of RHL, we restrict ourselves to 1-dimensional interpolation; the adopted algorithm would trivially extend to working in 2-d, but the book-keeping is a little intimidating.

The simplest solution would be to interpolate linearily,

    I'[0] = (I[-1] + I[1])/2,
but this doesn't perform well for marginally sampled data.

We know something about the auto-correlation present in our data, as it has been convolved with the PSF; we should look for interpolation schemes that minimise errors when interpolating over missing data in a signal consisting solely of the PSF.

Interpolation: Theoretical Considerations

As usual, there are a variety of ways of considering this problem, all of which are closely related. We give three approaches below.

Software Bias

As we are using unsigned 16-bit integers, bias and sky subtraction could lead to negative pixels, which would be a problem; photo gets around this by adding an arbitrary constant to the data just after removing the bias (it's currently 1000 and is a #define in the C code); when sky is subtracted the soft_bias is added back in (and removed from the sky estimate!). As there was a hardware bias of this order in the raw frames, doing so doesn't reduce the dynamic range of the data.

Removing the Bias due to Choosing the Minimum of Two Pixel Values

It is easy enough to calculate that the expectation value of the minimum of two Gaussian variates (with zero mean and unit variance; N(0,1)) is -0.5641895835. If we ever replace a pixel value by the minimum of two estimates of its true value, we will systematically underestimate its value; we should (and do) add a correction of approximately 0.56sigma.

Determining a Frame's Statistics using regStatsFromQuartiles

The routine regStatsFromQuartiles constructs a histogram of pixel intensities for an image, and derives any of a wide range of parameters. See the source code for details.

Fitting Taut Splines to Data

A Taut Spline is a regular (cubic) spline with the extra constraint that there be no superfluous turning points; it's rather as if you took the piece of flexible wood that provides the term spline and pulled on each end to remove unwanted wiggles.

This is achieved by inserting extra knots at cleverly chosen places, and seems to work well in practice.

Using asinh to Control the Dynamic Range of Data that can be Negative

It is a common practive to take logarithm of numbers that span many orders of magnitude, e.g. to display an object's radial profile. This has two main disadvantages: Both of these problems can be circumvented by using asinh(x/Delta) instead of lg(x), where Delta is some constant with magnitude comparable to the expected error in x. This has the nice property of being (within a scale) a simple logarithm for x >> Delta, and approximately linear for x <~ Delta.

For more details, see the paper by Szalay, Lupton, and Gunn.

How to Estimate the Mode

The result that mode = 3*median - 2*mean is readily proved from a Gram-Charlier series up to the third Hermite polynomial; to the same order it's easily shown that
      mode = median - (Q25 + Q75 - 2*median)/eta^2
where eta ~ 0.673 is the 75th percentile of an N(0,1) Gaussian. We can then estimate the mode as
      5.4*median - 2.2*(Q25 + Q75)
The variance of this estimate is approximately
      (4.78)^2 sigma^2/N;
much worse then the mean (with variance sigma^2/N), and 3.8 times worse than the median (whose variance is (pi/2)sigma^2/N).