A method is proposed for increasing the accuracy of nanomechanical measurements in an atomic force microscope. To describe the contact interaction of the cantilever with the sample, an analytical model was used that takes into account the following factors: the cantilever probe sticks to the sample surface or slides along it, the geometric and mechanical characteristics of the sample and cantilever, and their relative position. Under the assumption of sliding, a filter was developed to correct the signals of contact stiffness and deformation measured on a sample with a developed relief. The use of the filter is illustrated in images obtained in an atomic force microscope with an imaging mode based on point-by-point registration of the force quasistatic interaction of the cantilever probe with the sample.