We present a procedure that compensates for phase aberrations in digital holographic microscopy by computing a polynomial phase mask directly from the hologram. The phase-mask parameters are computed automatically without knowledge of physical values such as wave vectors, focal lengths, or distances. This method enables one to reconstruct correct and accurate phase distributions, even in the presence of strong and high-order aberrations. Examples of applications are shown for microlens imaging and for compensating for the deformations associated with a tilted thick plate. Finally we show that this method allows compensation for the curvature of the specimen, revealing its surface defects and roughness. Examples of applications are shown for microlenses and metallic sphere imaging.