Differentiation in Time and Space: Savitzky-Golay Filters

Physiological information is often encoded in rates. Differentiation in time tells that how fast is the change of the signal in each time point of the measurement, i.e. what is the slope of the intensity vs. time trace, performing the slope fitting at each time point. Differentiation in space tells that how steep are the edges of objects in the image.

Temporal differentiation of pixel values, which are discrete in time or in space is performed in the simplest case by subtracting the value occurred earlier from the value occurred later, and dividing it by the difference of the time point. Analogously, for differentiation along the x axis just replace time for space: considering that the x-axis increases from left to right the spatial derivative is calculated by subtracting the value on the left from the value on the right, and dividing it by the distance between them, which is 2.

In practice images are noisy, and differentiation amplifies
noise. Therefore derivatives are calculated from more data points
(pixel values) than strictly before and after the point of
calculation. The fundamental idea is to fit a different
polynomial to the data surrounding each data point^{1}. The
smoothed points are computed by replacing each data point with the
value of its fitted polynomial. Numerical derivatives come from
computing the derivative of each fitted polynomial at each data
point. In practice the polynomial coefficients can be computed with
kernel
filtering.
Savitzky-Golay^{2,3,4} filters are kernels calculated to
be mathematically identical to performing actual polynomial fitting
within the window of the kernel. Image Analyst MKII calculates one
or two-dimensional Savitzky-Golay filters for any given window size
or polynomial order (obviously the size has to be greater then the
order) and differentiation order. Savitzky-Golay filters with zero
differentiation order perform polynomial smoothing.

When differentiating with Savitzky-Golay filtering, temporal
derivatives are calculated by kernel filtering the intensity values
observed over a given pixel during the time lapse and dividing these
filtered values by the kernel filtered time axis. When spatial
derivatives are calculated in pixels, the spatial coordinate
increments by 1 by each pixel, so its differential is essentially
one. Therefore spatial filtering of images with Savitzky-Golay
filtering results true spatial gradients as *intensity change /
pixel*.

Spatial differentiation using 2D Savitzky-Golay filtering calculates partial derivatives. The actual partial derivative calculated is described by the order as follows:0: smoothing; 1:dx, 2:dy, 3:dx2, 4:dxy, 5:dy2

**One-dimensional Savitzky-Golay kernel examples:**

With=3, 1^{st} derivative, 1^{nd} polynomial
order

-0.5 | 0. | 0.5 |

With=5, 1^{st} derivative, 2^{nd} polynomial
order

-0.2 | -0.1 | 0. | 0.1 | 0.2 |

With=7, 1^{st} derivative, 2^{nd} polynomial
order

-0.107 | -0.071 | -0.036 | 0. | 0.036 | 0.071 | 0.107 |

With=15, 1^{st} derivative, 2^{nd} polynomial
order

-0.025 | -0.021 | -0.018 | -0.014 | -0.011 | -0.007 | -0.004 | 0. | 0.004 | 0.007 | 0.011 | 0.014 | 0.018 | 0.021 | 0.025 |

**Two-dimensional Savitzky-Golay kernel examples (use 3 ^{rd}
order):**

With=5, 0^{th} derivative (smooth, "order"=0), 3^{nd}
polynomial order

-0.074 | 0.011 | 0.04 | 0.011 | -0.074 |

0.011 | 0.097 | 0.126 | 0.097 | 0.011 |

0.04 | 0.126 | 0.154 | 0.126 | 0.04 |

0.011 | 0.097 | 0.126 | 0.097 | 0.011 |

-0.074 | 0.011 | 0.04 | 0.011 | -0.074 |

With=5, 1^{th} derivative along x axis ("order"=1), 3^{nd}
polynomial order

0.074 | -0.105 | 0. | 0.105 | -0.074 |

-0.012 | -0.148 | 0. | 0.148 | 0.012 |

-0.04 | -0.162 | 0. | 0.162 | 0.04 |

-0.012 | -0.148 | 0. | 0.148 | 0.012 |

0.074 | -0.105 | 0. | 0.105 | -0.074 |

With=5, 1^{th} derivative along y axis ("order"=2), 3^{nd}
polynomial order

0.074 | -0.012 | -0.04 | -0.012 | 0.074 |

-0.105 | -0.148 | -0.162 | -0.148 | -0.105 |

0. | 0. | 0. | 0. | 0. |

0.105 | 0.148 | 0.162 | 0.148 | 0.105 |

-0.074 | 0.012 | 0.04 | 0.012 | -0.074 |

**Differentiation in Image Analyst MKII:**

*Filters*/*Temporal Savitzky-Golay filter**Filters*/2D Savitzky-Golay filter

**References:**

- Savitzky-Golay Filters for 2D Images, John Krumm Microsoft Research Microsoft Corporation
- Wikipedia: Savitzky–Golay smoothing filter
- Savitzky, A. Golay, M.J.E. (1964). "Smoothing and Differentiation of Data by Simplified Least Squares Procedures". Analytical Chemistry 36 (8): 1627–1639
- Press, WH., and S. Teukolsky. 1990. Savitzky-Golay Smoothing Filters. Computers in Physics 4:669