Suppose I have a scan from an STM image (very much like the things you see here). Suppose I have a simple square lattice with lattice parameter a.

What I'd like to do is to numerically find the lattice parameter, measured in units of pixels, assuming that calibration is done elsewhere.

A first idea of mine was to have a function that creates a grid of points with lattice constant a, some offsets where the grid starts and also some angle for the rotation of the lattice. I'd then sum the values of the STM image at each grid point and return that. I'd then use some optimization toolbox (MATLAB, Python, ...) to find the parameters that maximize this sum.

Unfortunately, I run into problems doing this. For example, the grid points are calculated from the angle, lattice constant and offset and are then rounded to an integer value so that I can actually address my 2D image in the form


but most optimization routines will then go on to vary the parameters only very slightly, so that the rounded coordinates don't change. The program then assumes that it has found a local minimum/maximum since the function value doesn't change if the parameters are changed only slightly.

There are other problems regarding the stability of this method, so I wondered if there is a more sophisticated way of doing this in an automated fashion. I could always take the FT of the image data and read off the lattice constant manually, but I'd then still like to put a best-fid grid overlay over my image data so I'd have to optimize for angle and offset.

  • $\begingroup$ Is there any way you could automate the process of taking the Fourier transform of the image data to fit the lattice constant? The fewer decision variables you need for the fit of the STM image, the quicker the problem will solve. You may also be able to take advantage of knowing the lattice parameter when you formulate your optimization problem. Also, could you describe how you take the numerical image data and determine where the atoms (I'm presuming that's what the lattice points are) are? $\endgroup$ Jan 10, 2012 at 23:49
  • $\begingroup$ Very often the image contains lots of defects, so some human insight into choosing the correct points in the Fourier transform is necessary. Just picking the most intense points doesn't work. From the image data I define where the lattice points are as the points where the absolute value of the image data is largest. (This may or may not coincide with actual atomic positions depending on the electron orbitals). $\endgroup$
    – Lagerbaer
    Jan 11, 2012 at 4:09
  • $\begingroup$ If the image contains a lot of defects, and some human insight in choosing the correct points is necessary for the Fourier transform case, how do you think an optimization routine will overcome the need for human intervention? Finding the lattice spacing from the FT of the image data seems like an easier version of your problem (because you are solving for a subset of the information you ask for in your question). Is there a way to combine reasonably the two approaches? $\endgroup$ Jan 12, 2012 at 21:42

1 Answer 1


What you're doing is something like a fourier transform: you're projecting the image onto a function ($e^{ikx}$ in the case of the FT, and a sort of periodic "block" function in your case). It might be a little slow, but you could calculate the inner product of the lattice function and your image for every possible lattice function, and then find the maximum.

If that doesn't work, there's a trick that might make the FT work in your case. You could select some value, and then zero out all parts of your image that are below this value. If the defects in your image are mostly low amplitude, this could make sure the largest FT peak is the correct one.

  • $\begingroup$ I'm not adding them up with a complex phase, so I'm not calculating the FT by hand. I'm just sampling the image data at the lattice points and try to then optimize the lattice position/spacing to get maximum values at these samplings $\endgroup$
    – Lagerbaer
    Jan 11, 2012 at 4:41
  • 1
    $\begingroup$ My answer was badly worded; I meant you were taking the inner product of your image with a lattice function, just like the FT is an inner product with a complex phase. I edited my answer to reflect this and things you've said in other comments. $\endgroup$
    – Dan
    Jan 11, 2012 at 6:23
  • $\begingroup$ Okay, I see now what you mean. Yes, that will definitely be worth a try. $\endgroup$
    – Lagerbaer
    Jan 13, 2012 at 17:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.