Because of the presence of thermal drift, AFM (atomic force microscopy) images are always contaminated. Such contamination is one of the major hampers to achieve accurate and efficient AFM based nanomanipulation. Based on contaminated images, the manipulation operations often fail. In this paper, we apply a local scan method to identify and compensate the thermal drift contamination in the AFM image. After an AFM image is captured, the entire image is divided into several parts along y direction. A local scan is immediately performed in each part of the image to calculate the drift value at that very part. In this manner, the drift value is calculated in a small local area instead of the global image. Thus, the drift can be more precisely estimated and the image can be more accurately recovered, which lead to improved accuracy for AFM imaging and enhanced productivity for AFM based nanomanipulation.