Scripting Resources for DigitalMicrograph™

banner

Dave Mitchell's DigitalMicrograph™ Scripting Website

Home | Scripts | Examples | Functions | Recent Updates | Tutorials | Resources | Publications | Consulting | Projects | Contact & Bio | Private | Search

 

Monte Carlo 2D Gaussian Fitting
Function
Fits a 2D Gaussian to a blob feature - such as diffraction spot or atomic column - to locate its centroid with sub-pixel accuracy.
Version
version:20150720, v1.0
Author
D. R. G. Mitchell
Acknowledgements
-
Comments

This is more of an example script than anything. It contains a number of functions which may be of general use in fitting algorithms. As its input, the script takes an image of a blob. This could be an excised region containing a diffraction spot or an atomic column. The script will locate the centroid without knowing where the approximate centre is. However, as the Monte Carlo approach can be quite time consuming, it may be computationally quicker to use something like a centre of gravity measurement as a rapid way to approximate the centre, then to ask this script method to start looking for the centroid using the centre of gravity location as its starting point. This script starts from the centre provided - but if none is supplied then it will use the geometric centre. The script first approximates a Gaussian fit using the supplied/guessed centre and by assuming a sigma value for the Gaussian of 1/4 of the image width. Thereafter it varies the sigma with a random number generator, retaining sigma values which improve the fit. Once that iteration is complete, it varies the centre with a random number generator. It then repeats the sigma refinement and the centre refinement a number of times, until the chi squared value of the fit no longer improves. The method is quite robust, although median filtering is included to reduce any sensitivity to noise. Once complete, the script reports the centroid with sub-pixel precision.

System Requirements
Should be compatible with all recent versions of DigitalMicrograph.
Known Issues
The script uses multiple iterations for fitting and so is computationally intensive. Analysing small images will be faster than large images. The script has been designed to terminate iteration when three successive refinement loops fail to improve the chi squared value of the fit. This could be reduced to two to speed things up. Similarly, specifying fewer interations will reduce the processing time, but may also reduce the accuracy. The ideal blob image for this script is one in which the blob is rotationally symmetric and fully contained within the image, but which does not contain an excessive area of black background. Extraneous information should be excluded. So, if for example atomic columns are being analysed, intensity from adjacent atomic columns should not be present within the blob image. This is sometimes unavoidable. To reduce the sensitivity of the method to such edge information, 2D Gaussian fitting is only done on a central sub-area - which can be 25 - 75% of the original image area.
Supported
Yes
Included Files
Main script file.
Source Code

see attached script