Thermal drift is a problem in imaging with atomic force microscopes. In this work we present an extension of the well known gradient-based methods for optical flow calculation, developed by Horn & Schunk as well as Lucas & Kanade. We also analyse different trajectories and evaluate their suitability for use with the aforementioned methods. As part of this theoretical work, we are able to show that the methods by Horn & Schunk and Lucas & Kanade are extendable to the thermal drift problem. Furthermore, we compare different standard trajectories with a self-developed evaluation system and propose a favourable trajectory for drift estimation and compensation.