A method of flattening a deformable mirror (DM) such as a piezoelectric DM to correct for distortion includes inputting an incident light beam into a reference beam optical path while blocking the DM response, recording a flat wavefront (Φn, R) as a reference wavefront from a reference mirror, blocking the reference beam to obtain a DM response, activating a close-loop mode of DM Control Software and computing iterations until a difference between the reference wavefront and the DM response is minimized, recording a wavefront created by the DM (Φn, DM) and the corresponding voltage vector (Vn) applied to the DM; and applying a voltage vector to the DM to thereby flatten the DM and correct for the distortion. The method is useful in an application such as for ground-to-space links at Short Wave Infrared (SWIR) wavelengths.