Skip to main content

mpfit: a robust method for fitting atomic resolution images with multiple Gaussian peaks


The standard technique for sub-pixel estimation of atom positions from atomic resolution scanning transmission electron microscopy images relies on fitting intensity maxima or minima with a two-dimensional Gaussian function. While this is a widespread method of measurement, it can be error prone in images with non-zero aberrations, strong intensity differences between adjacent atoms or in situations where the neighboring atom positions approach the resolution limit of the microscope. Here we demonstrate mpfit, an atom finding algorithm that iteratively calculates a series of overlapping two-dimensional Gaussian functions to fit the experimental dataset and then subsequently uses a subset of the calculated Gaussian functions to perform sub-pixel refinement of atom positions. Based on both simulated and experimental datasets presented in this work, this approach gives lower errors when compared to the commonly used single Gaussian peak fitting approach and demonstrates increased robustness over a wider range of experimental conditions.


The development of spherical aberration-correction for scanning transmission electron microscopy (STEM) imaging has been one of the biggest triumphs of electron microscopy over the past several decades, allowing the sub-ångström resolution imaging of crystal structures [1,2,3]. Several pioneering STEM experiments have demonstrated the feasibility of this technique for the direct visualization of atom positions from aberration-corrected STEM images and has proved itself an invaluable tool for sub-ångström resolution structural measurements [4,5,6,7,8]. While the typical aberration-corrected STEM electron beam has a probe diameter approximately between 0.5 and 1 Å, supersampling scanning positions below the Nyquist–Shannon sampling limit and the subsequent fitting of the probe image with a two-dimensional Gaussian function allows the sub-pixel precision assignment of atom column positions from aberration-corrected STEM datasets [5, 9,10,11,12,13,14]. This technique has been used for quantitative atomic displacement measurements across thin films, 2D crystals, domain boundaries and has allowed the experimental observation of novel structural phenomena such as polar vortices [15,16,17,18,19,20].

While the Gaussian function fitting approach is an extraordinarily powerful technique, one noted shortcoming is that it assumes well-separated atoms with no overlap, or negligible aberrations in the beam itself—conditions that are only available under a certain limited set of imaging conditions [16, 17]. Typically, such an imaging setup uses a ring shaped annular detector with the outer and inner detector collection circles centered along the microscope optic axis. Such a configuration will have an inner collection angle of approximately 85–90 mrad to capture only the incoherently scattered electrons, and is conventionally referred to as high angle annular dark field STEM (HAADF-STEM) imaging [5, 21]. This mode of imaging is referred to as dark field imaging since atom columns themselves are bright due to electrons preferentially scattering from atomic nuclei as a consequence of Rutherford scattering from proton–electron Coulombic forces [22, 23]. Since this Coulombic force experienced by the electron probe is directly proportional to the number of protons in the nucleus (Z), atom column images in HAADF-STEM datasets generate peaks with an almost linear relationship of intensity \(\mathrm {\left( \propto Z^2 \right) }\) with the atomic number and is also referred to as Z-contrast imaging [24,25,26].

Z-contrast imaging, however, is generally considered unsuitable for imaging lighter elements such as oxygen, boron or carbon [19,20,21]. However, structural metrology for many scientifically important material systems such as ferroelectrics needs the imaging and quantification of lighter atoms as well as heavier elements [27, 28]. This problem can be significantly mitigated in bright field STEM (BF-STEM) imaging, where rather than annular detectors a circular detector is used with the detector center coinciding with the optic axis of the microscope [19, 29]. The conventional collection angle ranges in BF-STEM imaging extend up to 15 mrad, significantly lower than even the inner collection angle for HAADF-STEM [29]. Because unscattered electron beams are imaged by this technique, in contrast to HAADF-STEM vacuum is bright, while the atom positions have comparatively lower intensity. The ideal BF-STEM image would thus have an intensity profile complementary to the images obtained from HAADF-STEM imaging. However, in reality owing to the lower collection angles, atom positions are more blurred from aberrations that are more prominent in BF-STEM images [30]. Additionally, since BF-STEM images capture both light and heavy atom positions the inter-atomic distances are substantially smaller. These effects result in atom positions that are non-Gaussian in shape, and often have intensity overlaps and tails coming from their neighbors making position metrology challenging in BF-STEM images.


Fig. 1
figure 1

Error with single peak fitting on experimental data. a BF-STEM image of \({\text {LiNbO}}_{3}\) with the red dots referring to the intensity minima. b BF-STEM image shown in a with the intensity minima and single peak fitting results overlaid in red and green, respectively. c Intensity profile along the arrow shown in a and b with the red arrows referring to the intensity minima and the green arrows referring to the single peak fits

Fitting atom positions with Gaussians

The best modern aberration-corrected microscopes can generate electron probes that are free of aberrations up to 30 mrad, which corresponds to beam diameters that are of the order of 0.5 Å, or 50 pm at 200 kV [8, 10]. Super-sampling the beam by a factor of five results in scan positions that are spaced approximately 10 pm apart from each other. For HAADF-STEM images where oxygen atoms are not observed, inter-atomic distances from the low index zones are mostly of the order of 1.5 Å, allowing enough distance between atoms so that they are well separated and thus an atom position can be reasonably approximated with a two-dimensional Gaussian intensity profile. Since the FWHM of this Gaussian is around 50–75 pm, this allows the determination of the peak of the Gaussian intensity distribution with accuracies approaching 0.5 pm [14, 17]. It is this combination of aberration-corrected imaging and Gaussian peak fitting that has enabled modern electron microscopy to reliably measure domain walls, grain boundaries, defects, and strain with single picometer precision, making STEM imaging so powerful.

However, this approach runs into problems when applied to BF-STEM imaging. In Fig. 1a, we show a typical BF-STEM image of \({\text {LiNbO}}_{3}\) with 4.9 pm scanning pixel sizes. The darker regions in the image are the niobium and oxygen atom columns with the red dots corresponding to the intensity minima. While the intensity minima can be used as an initial estimate of atom positions, the error in such a measurement is at least of the order of the pixel size, which is 5 pm in our case. This makes the error of measurement in BF-STEM an order of magnitude worse than the best HAADF-STEM results. Figure 1b demonstrates the same section of the BF-STEM image with the refined atom positions obtained from fitting the intensity distribution with a single Gaussian peak with green dots next to the intensity minima (red dots). A visual estimation shows that the fitted Gaussians do not reliably converge on the atom positions, and are often tens of picometers away when the intensity minima is weak, and the neighboring atom is close. In some cases, the refined atom position is in the middle of the two neighboring atom columns with no definite atomic intensity.

This can be quantitatively demonstrated by profiling the summed intensity distribution (Fig. 1c) from the region shown along the white arrows in Fig. 1a, b. The red arrows in Fig. 1c correspond to the intensity minima, while the green arrows correspond to the Gaussian refined atom positions. The presence of an intense neighboring atom’s intensity tail gives rise to a dip in the intensity away from the original minima, right in the middle of two atom columns and the Gaussian peak fitting technique converges to that local minima rather than the original position. Previous BF-STEM imaging has attempted in circumventing such issues by using a multi-parameter Gaussian peak, or performing image metrology through multivariate statistics rather than fitting each individual atoms [19, 20]. Both approaches require an initial knowledge of the crystal structure being imaged. Multi-parameter Gaussian fits need an estimation of the number and location of the nearest neighbors, and thus cannot be applied as a robust technique as it necessitates custom fitting equations for individual crystal structures. In particular, this restriction limits the application of this method where more than one crystal orientation may be present. Here, we propose a novel multi-Gaussian refinement routine—mpfit—that does not require prior knowledge of the crystal structures being imaged and can robustly refine a wider variety of images by deconvolution of a subsection of the image into multiple overlapping two-dimensional Gaussians. Since HAADF-STEM image refinement requires less stringent conditions, our algorithm extends equally well to such systems too.

Fig. 2
figure 2

Schematic of the procedure. Red circles correspond to intensity minima or maxima for BF-STEM and ADF-STEM images, respectively. The smaller squares surrounding the red dot refer to the nearest neighbor cutoff region while the yellow crosses refer to the refined atom positions

The mpfit algorithm

The Gaussian curve is a centrosymmetric curve with wide uses in single processing for approximating symmetric impulse functions [31, 32]. Moreover, it has been demonstrated that given a sufficiently large number of Gaussians, any non-infinite signal can be approximated as a sum of overlapping Gaussians [31, 32]. We use this insight and extend it into two dimensions by first modeling our observed atom intensity as a sum of overlapping Gaussians. The second key idea is to recognize that not all Gaussian functions that are approximating the region of interest are in fact originating from the atom whose position we are trying to refine. Thus the Gaussian functions are subsequently sorted and only a subset of them that approximate the atom position are used to refine the atom. The flowchart of our algorithm is illustrated in Fig. 2. The steps of the mpfit algorithm can be described as:

  1. 1.

    Get intensity minima/maxima The initial starting point of this algorithm is the calculation of intensity maxima for inverted contrast BF-STEM images or ADF-STEM images. This can be implemented through standard MATLAB or Python peak finding routines. However, in noisy images, sometimes a single atom may generate multiple maxima. To prevent this, if there are more than one maxima with the distance between the maxima smaller than the resolution of the microscope, the center of mass of this cluster of points is chosen as the starting reference point.

  2. 2.

    Calculate median inter-neighbor distance Following the identification of intensity minima, the median inter-peak distance is calculated, which is rounded to the nearest integer, which we call \(\mathbf {\eta }\).

  3. 3.

    Get region of interest The region of interest is a square with the intensity minima as the central pixel, with the sides of the square given by \(\mathbf {s = 2\eta + 1}\), where s is the side of the square. Thus the \(\mathbf {\left( \eta + 1, \eta + 1 \right) }\) pixel in the square is the intensity minima that was the original starting point. Other regions of interest schemes, such as a Voronoi tessellation around the intensity minima actually demonstrate comparatively worse results (see Fig. 8 in Appendix).

  4. 4.

    Fit iteratively with Gaussians The region of interest is then fit by a single 2D Gaussian function with a user determined tolerance factor. The tolerance factor refers to the mean absolute difference in intensity between the fitted Gaussian and the original data. The fitted Gaussian function is then subtracted from the original region of interest, and the residual is subsequently fitted again. This process continues for a pre-determined number of iterations, with the sum of all the Gaussians then subsequently representing the original region of interest. In the authors’ experience, the tolerance factor is less important than the number of iterative Gaussians used, with reasonable accuracy and speed being obtained with a tolerance of \(\mathrm {10^{-12}}\) and 12 to 16 iterations for the mpfit examples presented in this text. We deal with the background intensity by normalizing each ROI cell from 0 to 1 before starting the estimation of the individual Gaussians.

  5. 5

    Sort peaks and get the refined position The Gaussian peaks are then subsequently sorted based on their distance from the original minima (step 1) with only those peak positions whose distances are less than \(\mathbf {\frac{\eta }{2}}\) from the minima/maxima (step 1) used for refinement. The refined atom position is then the weighted average peak position of all the Gaussians that lie within this selected region, with the peak amplitudes being the weights used.

Results and discussion

Fig. 3
figure 3

Evolution of Gaussian peaks for simulated data. a Simulated BF-STEM image of \({\text {LiNbO}}_{3}\) with the intensity minima overlaid as blue dots. b Calculation region of interest, demonstrated as the red box in a of the simulated BF-STEM image with the intensity reversed, with the blue spot corresponding to the intensity minima. c Evolution of the sum of the Gaussian peaks over multiple iterations. d Contributions of the Gaussian peaks scaled to their amplitudes with larger spheres corresponding to peaks with higher amplitudes. The red circle refers to the region from which the Gaussian peaks were selected from. e Equivalent summation of multiple Gaussian peaks with the blue point corresponding to the intensity minima, the green point corresponding to the atom position calculated by the mpfit algorithm and the red point corresponding to the atom position. f Contribution from the atom whose positions are being measured. g Contribution from the nearest neighbors

Results on simulated BF-STEM images

The efficiency and accuracy of the mpfit algorithm was tested on simulated BF-STEM images of \({\text {LiNbO}}_{3}\). The advantage of simulated data is that the accurate atom positions are already known and can be compared with mpfit results. This allows the estimation of the relative errors of the single Gaussian and the multiple Gaussian mpfit approaches, with the simulation parameters outlined in Table 1. Following the steps of the algorithm outlined in Fig. 2, the intensity minima were first calculated for the simulated image, with Fig. 3a demonstrating the simulated BF-STEM image of \({\text {LiNbO}}_{3}\) with the intensity minima overlaid as blue dots. These intensity minima are subsequently used to calculate the median nearest neighboring distance \(\mathbf {\left( \eta \right) }\) between the minima. Based on the calculated \(\mathbf {\eta }\) value, the region of interest for this image is demonstrated for one of the atoms as a red square in Fig. 3a. The region of interest for that atom is shown in Fig. 3b with the contrast inverted and the intensity minima for the atom in question overlaid as a blue dot. As could be ascertained from Fig. 3b, the intensity distribution from the bottom left atom partially overlaps with the atom position we are aiming to refine, precisely indicating the scenario where single peak Gaussian fitting approaches often give erroneous results.

Sixteen iteration steps were chosen to represent this section of the image, as per step four of the algorithm. The first 12 of these iteration steps and the evolution of the Gaussian summation are shown in Fig. 3c. The calculation of the Gaussian is performed by taking in the entire image, and calculating a two-dimensional Gaussian peak with the smallest absolute difference with the initial region of interest. Multiple different Gaussian fitting approaches can be used, with the fitting equation used in this approach expanded in Eq. 1. As could be observed from Fig. 3c, the summation of the Gaussian peaks starts to approximate the region of interest within only a few iterations. This demonstrates that the iteration number chosen was sufficient enough to capture the complexities of the data being fitted. It is even more interesting to look at the result of the first iteration, which is mathematically equivalent to the single Gaussian peak fitting approach. As the first iteration in Fig. 3c shows, the single Gaussian peak fitting approach is a special case of the mpfit algorithm, where the number of iterations is one. According to this image, the first Gaussian peak does not exist near the center of the image, and is extracted towards the bottom left corner. The central peak related to the atomic column of interest is captured in the second iteration rather than the first, thus visually demonstrating why the single Gaussian approach fails in some cases.

While it may be possible to adjust the calculation of the region of interest to capture the atom position accurately, this approach necessitates tinkering with multiple different collection areas and a non-uniform solution for all the atoms in the image. mpfit on the other hand, removes the necessity for such complicated user modifications, allowing the estimation of all the Gaussian peaks that contribute to the final image. The individual peak positions are visually represented as a function of the iteration number in Fig. 3d where the radius of the spheres are scaled to the amplitude of the Gaussian calculated—with the X and Y position of the sphere referring to the location of the Gaussian peak. Only Gaussian peaks lying below a certain distance from the intensity minima (shown as the red circle in Fig. 3d) are used for the estimation of the refined position. As could be observed, the peak obtained from the the most intense Gaussian in green is actually assigned to the neighboring atom, and two other peaks are also assigned to two neighboring atoms, and only the subset of Gaussian peaks lying within the red circle are used for refinement. Summing all the Gaussian functions together we obtain Fig. 3e, which shows close fidelity to the input data (Fig. 3b).

Based on the final step of the algorithm, the Gaussian peaks are assigned either to neighboring atoms or the central atom depending upon the distance of the peak center from the initial intensity minima. As can be seen in Fig. 3e, the intensity minima is not always a reliable estimator of the actual atom position, but the mpfit algorithm converges extraordinarily close to the actual atom position (green and red dots overlapping), demonstrating its superiority. The representative summation of the Gaussian summation can thus be broken down into two components—the Gaussian peaks that were used for atom position refinement, the sum of which is visualized in Fig. 3f and the Gaussian peaks that were further off, and assigned as contributions of neighboring atom intensity—represented in Fig. 3g. Thus, the combination of the main atom and the neighboring contributions gives rise to the total intensity profile that was observed.

Fig. 4
figure 4

Calculated positions. a Simulated \({\text {LiNbO}}_{3}\) BF-STEM data with the original atom positions and the intensity minima overlaid in yellow and teal, respectively. b Simulated \({\text {LiNbO}}_{3}\) BF-STEM data with the original atom positions and the atom positions obtained by fitting a single Gaussian peak overlaid in yellow and red, respectively. c Simulated \({\text {LiNbO}}_{3}\) BF-STEM data with the original atom positions and the atom positions calculated via the mpfit algorithm overlaid in yellow and green, respectively

We further evaluated the accuracy of the mpfit algorithm for an entire image rather than a single atom. Figure 4 shows and compares the three different atom position metrology techniques—intensity minima/maxima, single Gaussian peak fitting and the mpfit algorithm with each other, respectively. Figure 4a demonstrates the intensity minima itself may not be coincident with the ideal atom positions due to minute intensity variations that are not accurately captured given a limited detector dynamic range, with the errors of the order of a single pixel. As a result, the intensity minima atom positions are clustered at several different clustering values, which can be understood based on the fact that results from the intensity minima are always on the order of a pixel. Thus compared to position refinement algorithms, just the minima itself is incapable of sub-pixel precision metrology. Figure 4b demonstrates the difference of the single peak approach from the ideal atom positions, with the results being clustered into three distinct clusters. This can be understood based on the fact that there are three separate types of intensity distributions in the simulated data. For well-separated atoms, the single peak and the atom positions show close agreement, which generates the central cluster. However, there are also atom columns, where the neighboring atoms are either on the top left or the top right, giving rise to the two extra clusters—demonstrating the shortcomings of this approach when the intensity distributions of neighboring atoms approach the resolution limit of the electron microscope. The results from the mpfit algorithm, demonstrated in Fig. 4c, are on the other hand clustered in a region less than 0.5 pm across from the known atom positions—demonstrating it’s accuracy. However, in the authors’ experience, the mpfit technique fails to converge for the edge atoms, which shows up as atom positions that are not clustered and have a higher error. For the rest of the atoms in the image, however, mpfit is significantly superior to the other approaches.

Fig. 5
figure 5

Evolution of Gaussian peaks for experimental data. a Experimental inverted contrast BF-STEM image of \({\text {LiNbO}}_{3}\). b Calculation region of interest of an experimental BF-STEM image with the intensity reversed from the region marked by the red box in a, with the blue point corresponding to the intensity minima, and the green point corresponding to the position calculated by fitting a single Gaussian peak. c Evolution of the sum of the Gaussian peaks over multiple iterations. d Contributions of the Gaussian peaks scaled as a function of their amplitude. Peaks lying outside the red circle are assigned to neighboring atoms. e Equivalent summation of multiple Gaussian peaks with the blue point representing the location of the intensity minima, the green point the position calculated by fitting a single Gaussian peak and the yellow point representing the atom position calculated by the mpfit algorithm. f Contribution from the atom whose positions is being measured. g Contribution from nearest neighbors

Results on experimental BF-STEM images

Along with simulated datasets, we additionally performed position metrology on experimental BF-STEM images of \({\text {LiNbO}}_{3}\) viewed from the \({\left[ 1{\bar{1}}00 \right] }\) zone axis [15]. The results were obtained through STEM imaging in a spherical aberration-corrected FEI \(\mathrm {Titan^3}\) transmission electron microscope, corrected for upto third order spherical aberrations. Imaging was performed at a camera length of 145 mm and the BF-STEM images were collected using Gatan detectors with an outer collection semi-angle of 15 mrad, using scanning pixel step sizes of 9.8 pm.

In contrast to simulated datasets, the exact ideal atom positions are not known owing to specimen drift, thermal vibrations, signal-to-noise ratio, and localized imperfections in the crystal lattice. Figure 5a demonstrates a region of interest in an experimental dataset, with the intensity reversed, with Fig. 5b showing a section of the image marked by the red box in Fig. 5a. The blue dot in Fig. 5b corresponds to the intensity minima, while the green dot represents the position calculated by the single Gaussian peak fitting approach. As can be visually ascertained, the calculated atom position does not correspond to the atom position, and thus is an inaccurate representation. Following step 4 of the algorithm, and similar to the procedure outlined in Fig. 3c, the region of interest is represented by a succession of closely spaced two-dimensional Gaussian peaks over 16 iteration steps,with the contribution from the first 12 steps shown in Fig. 5c. The individual Gaussian peaks that contribute to the final representation of the region of interest are pictorially represented in Fig. 5d, with the radius of the circle corresponding to the amplitude of the Gaussian. Peaks that are further from the original intensity minima by more than twice the median inter-peak distance (which is indicated by the red circle) are assigned to the neighboring atoms, and only peaks lying inside the red circle are used to calculate the refined atom position.

Figure 5b demonstrates the initial experimental data, while Fig. 5e demonstrates the final summation from the 16 Gaussian peaks with visual inspection revealing close correspondence between the experimental and represented data. Extending the number of iterations would allow progressively smaller Gaussian peaks resulting in better correspondence, but would also increase the demand for computational resources without a correspondingly significant increase in precision. The intensity minima are overlaid on the images in blue, with the results from the single peak fit approach in green and the mpfit results in yellow, respectively. Thus the mpfit algorithm accurately determines the atom location rather than converging to saddle points created from intensity tails from neighboring atoms. Figure 5f represents the sum of the Gaussians that represents the atom being refined and Fig. 5g represents the contribution from the intensity tails from the neighboring atoms, and is calculated from the Gaussian peaks represented with red borders in Fig. 5d.

Fig. 6
figure 6

Comparing mpfit with single peak fitting on experimental data. a Experimental \({\text {LiNbO}}_{3}\) BF-STEM data with the red points referring to the intensity minima, green points referring to the fitted positions as calculated by the single peak approach, and yellow points being the points as calculated by the mpfit approach. b Intensity profile of the image along the white arrow, with the red arrows corresponding to intensity minima, green arrows to single peak refinement results, and yellow arrows referring to the mpfit refinement results

Returning back to the original experimental BF-STEM image in Fig. 1a, we revisit that experimental data in Fig. 6a, comparing the results obtained with the mpfit approach. As could be visually ascertained, while the single peak fit approach fails in some of the cases, the mpfit approach reliably refines to the atom position, which can also be ascertained by the intensity profile demonstrated in Fig. 6b.

Fig. 7
figure 7

Comparison of mpfit and StatSTEM on simulated images. a Overlaid results from StatSTEM and mpfit on a simulated \({\text {LiNbO}}_{3}\) dataset. b Distance from known atom positions and the calculated positions from StatSTEM (in blue) and mpfit (in orange). c Distance between StatSTEM and mpfit results in picometers

Comparisons with other algorithms

Several other specialized algorithms have been designed to quantify atom positions in electron microscope datasets, such as Atomap [33], StatSTEM [34] and oxygen octahedra picker [35]. The Atomap algorithm uses principal component analysis to obtain denoised STEM images and finds the center of mass based on the initial guess of local intensity maxima or minima. Using the center of mass as the starting estimate, it then subsequently approximates a two-dimensional Gaussian to locate the estimated position of atoms. Atomap can additionally sort the different species of atom columns in the image and analyze them individually. StatSTEM on the other hand is a model-based fitting algorithm for extraction of the atom position information from STEM images. StatSTEM models the atoms in the images as the superposition of two-dimensional Gaussian peaks, and since this is a model-based technique it requires prior knowledge of the crystal structure of the sample being imaged to give a better estimation of the initial guess. After obtaining the initial guess, the algorithm will go through iterations to reach the least-squares estimation of fitting parameters, and then determines the position. oxygen octahedra picker is a software specialized in identifying the octahedra rotations in the \({\text {ABO}}_{3}\) perovskite oxides. It sorts out the oxygen and B atom positions and provides users the option of selecting a fast center of mass estimation or a slower peak fitting with two-dimensional gaussians. It exhibits an impressive accuracy of as small as 3 pm in simulated HAADF images. However, the existing methods still possess limitations in practical cases—with neither the oxygen octahedra picker and the Atomap software being able to process STEM images where atomic columns being measured will have intensity contributions from their neighbors. Thus both these approaches work well for well-separated atom columns in HAADF images, but face accuracy penalties with BF-STEM images. While StatSTEM’s model-based algorithm is able to solve the overlapping issue by assuming atom columns as overlapping 2D Gaussian peaks, its iterative model fitting process is computationally intensive, and requires prior knowledge of the crystal structure being imaged. As demonstrated in Fig. 7a, visually there is almost no difference between the fitting results of StatSTEM versus mpfit, with StatSTEM’s results being slightly off-centered from mpfit’s estimation. Comparison of the results in Fig. 7b demonstrates that both technique give results that are less than a pixel apart from each other, with mpfit outperforming StatSTEM. The standard deviation \(\mathrm {\left( \sigma \right) }\) of mpfit’s estimation from known atom positions is 1.49 pm compared to a \(\mathrm {\sigma }\) of 3.31 pm from StatSTEM.


While it may be possible to assume from the results presented here that the single Gaussian peak fitting approach fails to converge to atom solutions and gives erroneous results, it actually performs perfectly adequately for the majority of STEM experiments. However, for certain non-ideal imaging conditions, the single Gaussian peak fitting approach fails, while mpfit accurately obtains precise atom positions. For well-separated atoms, the results from mpfit and a single Gaussian refinement are in fact identical. Additionally, it has to be kept in mind, that even with parallelization implemented, the mpfit algorithm solves for over ten Gaussian peaks in a batch process. On the other hand, the single Gaussian approach solves for just one peak, thus making the single Gaussian approach faster by at around an order of magnitude.

Future planned improvements include solving for neighboring peaks simultaneously using the tail functions to deconvolve the full obtained image as an independent set of impulse functions originating from individual atoms. Additionally, atom columns whose separation distances are below the resolution limit of the microscope may be particularly suited for this approach, by the deconvolution of the observed impulse function into two closely separated Gaussians and enabling the super-resolution metrology of atom positions from STEM datasets.

Thus, our results demonstrate that the mpfit algorithm can reliably and robustly refine the sub-pixel precision of atoms even without a priori knowledge of the underlying crystal structure. Additionally, since the single Gaussian approach is a special case of the mpfit approach with the total number of iterations as one, this approach will also work for ADF-STEM images, enabling a single approach to the metrology of a wide variety of STEM data. The results are superior to existing algorithms, and exceeds the state of the art—StatSTEM in accuracy, with the added advantage of being agnostic to the crystal structure being imaged.

Availability of data and materials

mpfit code in MATLAB is freely available from the mpfit Github repository ( The Python codes are available in the afit module of stemtools ( The datasets used and/or analyzed during the current study are available from the corresponding author (N.A.) on reasonable request.



scanning transmission electron microscopy


annular dark field


bright field


high angle annular dark field


  1. Haider, M., Uhlemann, S., Schwan, E., Rose, H., Kabius, B., Urban, K.: Electron microscopy image enhanced. Nature 392(6678), 768 (1998)

    Article  CAS  Google Scholar 

  2. Batson, P., Dellby, N., Krivanek, O.: Sub-ångström resolution using aberration corrected electron optics. Nature 418(6898), 617 (2002)

    Article  CAS  Google Scholar 

  3. Pennycook, S.J., Varela, M., Hetherington, J., Kirkland, A.I.: Materials advances through aberration-corrected electron microscopy. MRS Bull. 31(1), 36–43 (2006)

    Article  CAS  Google Scholar 

  4. Nellist, P.D., Chisholm, M.F., Dellby, N., Krivanek, O., Murfitt, M., Szilagyi, Z., Lupini, A.R., Borisevich, A., Sides, W., Pennycook, S.J.: Direct sub-ångström imaging of a crystal lattice. Science 305(5691), 1741–1741 (2004)

    Article  CAS  Google Scholar 

  5. Aso, K., Shigematsu, K., Yamamoto, T., Matsumura, S.: Detection of picometer-order atomic displacements in drift-compensated HAADF-STEM images of gold nanorods. J. Electron Microsc. 65(5), 391–399 (2016)

    CAS  Google Scholar 

  6. Kisielowski, C., Freitag, B., Bischoff, M., Van Lin, H., Lazar, S., Knippels, G., Tiemeijer, P., van der Stam, M., von Harrach, S., Stekelenburg, M., et al.: Detection of single atoms and buried defects in three dimensions by aberration-corrected electron microscope with 0.5-Å information limit. Microsc. Microanal. 14(5), 469–477 (2008)

    Article  CAS  Google Scholar 

  7. O’Keefe, M.A.: Seeing atoms with aberration-corrected sub-ångström electron microscopy. Ultramicroscopy 108(3), 196–209 (2008)

    Article  Google Scholar 

  8. Sawada, H., Tanishiro, Y., Ohashi, N., Tomita, T., Hosokawa, F., Kaneyama, T., Kondo, Y., Takayanagi, K.: Stem imaging of 47-pm-separated atomic columns by a spherical aberration-corrected electron microscope with a 300 kV cold field emission gun. J. Electron Microsc 58(6), 357–361 (2009)

    Article  CAS  Google Scholar 

  9. Krivanek, O., Dellby, N., Lupini, A.: Towards sub-Å electron beams. Ultramicroscopy 78(1–4), 1–11 (1999)

    Article  CAS  Google Scholar 

  10. Erni, R., Rossell, M.D., Kisielowski, C., Dahmen, U.: Atomic-resolution imaging with a sub-50-pm electron probe. Phys. Rev. Lett. 102(9), 096101 (2009)

    Article  Google Scholar 

  11. Kimoto, K., Asaka, T., Yu, X., Nagai, T., Matsui, Y., Ishizuka, K.: Local crystal structure analysis with several picometer precision using scanning transmission electron microscopy. Ultramicroscopy 110(7), 778–782 (2010)

    Article  CAS  Google Scholar 

  12. Gao, P., Kumamoto, A., Ishikawa, R., Lugg, N., Shibata, N., Ikuhara, Y.: Picometer-scale atom position analysis in annular bright-field STEM imaging. Ultramicroscopy 184, 177–187 (2018)

    Article  CAS  Google Scholar 

  13. Yankovich, A.B., Berkels, B., Dahmen, W., Binev, P., Sanchez, S.I., Bradley, S.A., Li, A., Szlufarska, I., Voyles, P.M.: Picometre-precision analysis of scanning transmission electron microscopy images of platinum nanocatalysts. Nat. Commun. 5, 4155 (2014)

    Article  CAS  Google Scholar 

  14. Zhu, Y., Ophus, C., Ciston, J., Wang, H.: Interface lattice displacement measurement to 1 pm by geometric phase analysis on aberration-corrected HAADF STEM images. Acta Materialia 61(15), 5646–5663 (2013)

    Article  CAS  Google Scholar 

  15. Mukherjee, D., Prokhorenko, S., Miao, L., Wang, K., Bousquet, E., Gopalan, V., Alem, N.: Atomic-scale measurement of polar entropy. Phys. Rev. B 100(10), 104102 (2019)

    Article  CAS  Google Scholar 

  16. Yadav, A., Nelson, C., Hsu, S., Hong, Z., Clarkson, J., Schlepütz, C., Damodaran, A., Shafer, P., Arenholz, E., Dedon, L., et al.: Observation of polar vortices in oxide superlattices. Nature 530(7589), 198 (2016)

    Article  CAS  Google Scholar 

  17. Nelson, C.T., Winchester, B., Zhang, Y., Kim, S.-J., Melville, A., Adamo, C., Folkman, C.M., Baek, S.-H., Eom, C.-B., Schlom, D.G., et al.: Spontaneous vortex nanodomain arrays at ferroelectric heterointerfaces. Nano Lett. 11(2), 828–834 (2011)

    Article  CAS  Google Scholar 

  18. Azizi, A., Wang, Y., Stone, G., Elias, A.L., Lin, Z., Terrones, M., Crespi, V.H., Alem, N.: Defect coupling and sub-angstrom structural distortions in \({\text{ W }}_{{\rm 1-x}} {\text{ Mo }}_{{\rm x}} {\text{ S }}_{2}\) monolayers. Nano Lett. 17(5), 2802–2808 (2017)

    Article  CAS  Google Scholar 

  19. Stone, G., Ophus, C., Birol, T., Ciston, J., Lee, C.-H., Wang, K., Fennie, C.J., Schlom, D.G., Alem, N., Gopalan, V.: Atomic scale imaging of competing polar states in a Ruddlesden-Popper layered oxide. Nat. Commun. 7, 12572 (2016)

    Article  CAS  Google Scholar 

  20. Matsumoto, T., Ishikawa, R., Tohei, T., Kimura, H., Yao, Q., Zhao, H., Wang, X., Chen, D., Cheng, Z., Shibata, N., et al.: Multivariate statistical characterization of charged and uncharged domain walls in multiferroic hexagonal \({\text{ YMnO }}_{3}\) single crystal visualized by a spherical aberration-corrected stem. Nano Lett. 13(10), 4594–4601 (2013)

    Article  CAS  Google Scholar 

  21. Williams, D.B., Carter, C.B.: Transmission Electron Microscopy. Springer, Berlin (1996)

    Book  Google Scholar 

  22. MacArthur, K., Pennycook, T., Okunishi, E., D’Alfonso, A., Lugg, N., Allen, L., Nellist, P., et al.: Probe integrated scattering cross sections in the analysis of atomic resolution HAADF-STEM images. Ultramicroscopy 133, 109–119 (2013)

    Article  Google Scholar 

  23. Watanabe, K., Yamazaki, T., Kikuchi, Y., Kotaka, Y., Kawasaki, M., Hashimoto, I., Shiojiri, M.: Atomic-resolution incoherent high-angle annular dark field STEM images of Si (011). Phys. Rev. B 63(8), 085316 (2001)

    Article  Google Scholar 

  24. Abe, E., Kawamura, Y., Hayashi, K., Inoue, A.: Long-period ordered structure in a high-strength nanocrystalline Mg-1 at% Zn-2 at% Y alloy studied by atomic-resolution Z-contrast STEM. Acta Materialia 50(15), 3845–3857 (2002)

    Article  CAS  Google Scholar 

  25. Rosenauer, A., Schowalter, M.: STEMSIM—a new software tool for simulation of STEM HAADF Z-contrast imaging. In: Microscopy of Semiconducting Materials 2007, pp. 170–172. Springer, Berlin (2008)

  26. Wang, Z., Li, Z., Park, S., Abdela, A., Tang, D., Palmer, R.: Quantitative Z-contrast imaging in the scanning transmission electron microscope with size-selected clusters. Phys. Rev. B 84(7), 073408 (2011)

    Article  Google Scholar 

  27. Spaldin, N.A.: A beginner’s guide to the modern theory of polarization. J. Solid State Chem. 195, 2–10 (2012)

    Article  CAS  Google Scholar 

  28. Lines, M.E., Glass, A.M.: Principles and Applications of Ferroelectrics and Related Materials. Oxford University Press, Oxford (1977)

    Google Scholar 

  29. Okunishi, E., Ishikawa, I., Sawada, H., Hosokawa, F., Hori, M., Kondo, Y.: Visualization of light elements at ultrahigh resolution by STEM annular bright field microscopy. Microsc. Microanal. 15(S2), 164 (2009)

    Article  Google Scholar 

  30. Watanabe, K., Asano, E., Yamazaki, T., Kikuchi, Y., Hashimoto, I.: Symmetries in BF and HAADF STEM image calculations. Ultramicroscopy 102(1), 13–21 (2004)

    Article  CAS  Google Scholar 

  31. Hossain, J., Sharma, S., Kishore, V.: Multi-peak gaussian fit applicability to wind speed distribution. Renew. Sustain. Energy Rev. 34, 483–490 (2014)

    Article  Google Scholar 

  32. Mukoyama, T.: Fitting of gaussian to peaks by non-iterative method. Nucl. Instrum. Methods 125(2), 289–291 (1975)

    Article  CAS  Google Scholar 

  33. Nord, M., Vullum, P.E., MacLaren, I., Tybell, T., Holmestad, R.: Atomap: a new software tool for the automated analysis of atomic resolution images using two-dimensional gaussian fitting. Adv. Struct. Chem. imaging 3(1), 9 (2017)

    Article  Google Scholar 

  34. De Backer, A., Van den Bos, K., Van den Broek, W., Sijbers, J., Van Aert, S.: StatSTEM: an efficient approach for accurate and precise model-based quantification of atomic resolution electron microscopy images. Ultramicroscopy 171, 104–116 (2016)

    Article  Google Scholar 

  35. Wang, Y., Salzberger, U., Sigle, W., Suyolcu, Y.E., van Aken, P.A.: Oxygen octahedra picker: a software tool to extract quantitative information from STEM images. Ultramicroscopy 168, 46–52 (2016)

    Article  Google Scholar 

  36. Levenberg, K.: A method for the solution of certain non-linear problems in least squares. Q. Appl. Math. 2(2), 164–168 (1944)

    Article  Google Scholar 

  37. Marquardt, D.W.: An algorithm for least-squares estimation of nonlinear parameters. J. Soc. Ind. Appl. Math. 11(2), 431–441 (1963)

    Article  Google Scholar 

  38. Li, Y.: Centering, trust region, reflective techniques for nonlinear minimization subject to bounds. Technical report, Cornell University (1993)

  39. O’Keefe, M.A., Kilaas, R.: Advances in high-resolution image simulation. Scanning Microsc. Suppl. 2, 225–244 (1988)

    Google Scholar 

  40. Abrahams, S., Reddy, J.M., Bernstein, J.: Ferroelectric lithium niobate. 3. Single crystal x-ray diffraction study at 24 °C. J. Phys. Chem. Solids 27(6–7), 997–1012 (1966)

    Article  CAS  Google Scholar 

  41. Boysen, H., Altorfer, F.: A neutron powder investigation of the high-temperature structure and phase transition in \({\text{ LiNbO }}_{3}\). Acta Crystallogr. Sect. B Struct. Sci. 50(4), 405–414 (1994)

    Article  Google Scholar 

  42. Megaw, H.D.: A note on the structure of lithium niobate, \({\text{ LiNbO }}_{3}\). Acta Crystallogr. Sect. A Cryst. Phys. Diffr. Theor. Gen. Crystallogr. 24(6), 583–588 (1968)

    Article  CAS  Google Scholar 

Download references


The authors would like to acknowledge Dr. Jason Lapano and Prof. Venkatraman Gopalan of Penn State for helpful discussions on atom fitting metrology.


The authors acknowledge funding support from the Penn State Center of Nanoscale Science, an NSF MRSEC, funded under the grant number DMR-1420620.

Author information

Authors and Affiliations



DM and GS, advised by NA designed the algorithm. DM developed the MATLAB and Python subroutines for the algorithm implementation. DM and LM, advised by NA analyzed the data and developed the algorithm. DM performed the electron microscopy simulations. DM wrote the manuscript. NA edited the manuscript. All authors commented on the final manuscript. All authors read and approved the final manuscript.

Corresponding author

Correspondence to Nasim Alem.

Ethics declarations

Competing interests

The authors declare that they have no competing interests.

Additional information

Publisher's Note

Springer Nature remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.



Gaussian calculation parameters

The Gaussian peaks were calculated based on Eq.1

$$\begin{aligned} {Z\left( x,y \right) = Ae^{\frac{\left( \left( \left( x-x_0 \right) \cos \theta \right) + \left( \left( y-y_0 \right) \sin \theta \right) \right) ^2}{\sigma _x}} \times } \nonumber \\ {{\text{e}}^{\frac{\left( \left( \left( x-x_0 \right) \sin \theta \right) + \left( \left( y-y_0 \right) \cos \theta \right) \right) ^2}{\sigma _y}}}, \end{aligned}$$

where \(Z\left( x,y \right)\) is the Gaussian output as a function of x and y, \(\sigma _x\) and \(\sigma _y\) are the two normal distributions in the x and y directions, \(x_0\) and \(y_0\) are the position of the Gaussian peak, A is the amplitude of the Gaussian peak and \(\theta\) is the rotation in the counter-clockwise direction of the two-dimensional Gaussian peak.

Thus given a set of x,y, and z values from the experimental region of interest, a Gaussian curve is estimated from Eq.1 such that:

$$\begin{aligned} \sum _{x,y}\left( z - Z \right) = \tau, \end{aligned}$$

where \(\tau\) is the tolerance, which was \(\mathrm {10^{-8}}\) for our implementation.

The equation itself is calculated through the least-squares approach using the trust-region reflective algorithm. Trust-region algorithms are an evolution of Levenberg–Marquardt (LM) algorithms. However, compared to the LM algorithms, this algorithm is curvature independent and is thus computationally significantly faster [36,37,38].

Simulation parameters

The \({\text {LiNbO}}_{3}\) images were simulated using the MacTempasX software, with the simulation parameters enumerated in Table 1 [39].

Table 1 BF-STEM simulation conditions in MacTempasX
Fig. 8
figure 8

Effect of a Voronoi ROI. a Simulated BF-STEM image of \({\text {LiNbO}}_{3}\) with the green dots referring to the mpfit calculated positions when the region of interest is a Voronoi region around the intensity minima, while the blue dots refer to refined positions calculated from the standard mpfit algorithm. b Distance between the two results in picometers

Voronoi vs. square ROI

One other region of interest method was tried, apart from the standard box centered on the intensity minima—a ROI based on the Voronoi region around the intensity minima. A Voronoi region for a point is defined as the section of the image, for which the Cartesian distance to the point is the lowest compared to all other points in the image. However, we observed that the standard ROI actually gave better results rather than the Voronoi tessellation. This is most clearly visible in Fig. 8b where the distances between the two methods is scattered over even 20 pm, while the standard mpfit results are clustered less than 5 pm away from the known atom positions as could be observed in Fig. 7b. The standard deviation \(\left( \sigma \right)\) between the positions calculated with the two ROI techniques is 10.93 pm, much higher than the standard deviation between the simulated peak positions and the standard mpfit technique.

Rights and permissions

Open Access This article is licensed under a Creative Commons Attribution 4.0 International License, which permits use, sharing, adaptation, distribution and reproduction in any medium or format, as long as you give appropriate credit to the original author(s) and the source, provide a link to the Creative Commons licence, and indicate if changes were made. The images or other third party material in this article are included in the article's Creative Commons licence, unless indicated otherwise in a credit line to the material. If material is not included in the article's Creative Commons licence and your intended use is not permitted by statutory regulation or exceeds the permitted use, you will need to obtain permission directly from the copyright holder. To view a copy of this licence, visit

Reprints and Permissions

About this article

Verify currency and authenticity via CrossMark

Cite this article

Mukherjee, D., Miao, L., Stone, G. et al. mpfit: a robust method for fitting atomic resolution images with multiple Gaussian peaks. Adv Struct Chem Imag 6, 1 (2020).

Download citation

  • Received:

  • Accepted:

  • Published:

  • DOI:


  • Peak refinement
  • BF-STEM imaging
  • Sub-pixel resolution
  • Aberration-corrected STEM