Scripting Resources for DigitalMicrograph™ |
Function: Fit an n Order 2D Polynomial |
|
Function |
This function will compute the linear least squares fit of a 2D polynomial to a surface described by the intensity values in an image. |
Version |
version:20200519, v1.0 |
Author |
D. R. G. Mitchell |
Acknowledgements |
- |
Comments |
This function uses the pseudoiverse matrix technqiue to compute the parameters of an n order 2D polynomial (where n can be 2, 3, or 4) which is the linear least squares fit of the function to a 2D surface. This method is very computationally efficient, even for very large data sets. The data passed in to the function are a 2D image where the x and y values of the pixels are the point coordinates and the intensity value represents the surface value to be fitted. A polynomial order term, which can take values of 2, 3, or 4, is also supplied. When run, the script will select the front-most image (ensure it has an intensity variation which is amenable to a polynomial fit) and then call the fitting function. The function returns a single column array which contains the polynomial coefficients. The number of coefficients depends on the polynomial order being fitted. The script uses these coefficients to compute the fitted data. The script displays the original input data, the fitted output data and the difference between these two images - to highlight how good (or bad) the fit is. This difference image is coloured using a temperature colour lookup table - as minor differences are more easily seen in colour than in greyscale. |
System Requirements |
Should be compatible with all recent versions of DigitalMicrograph. |
Known Issues |
Use lower order fits for slowly varying surfaces and higher order fits for more convoluted surfaces. Increasing the number of data points will produce better fits - especially near edges. Lower order fits will smooth rapidly varying data to a greater degree than higher order fits. This function can readily be expanded to 5th order fits and beyond - the additional computational effort is minimal, although the number of additional terms in the fit equation will grow significantly. |
Supported |
Yes |
Included Files |
Main script file. |
Source Code |
See attached script file. |