We present a scheme for active compensation of complex extrinsic polarization perturbations introduced into an optical system. Imaging polarimeter is used to measure the polarization state across a beam profile and a liquid crystal spatial light modulator controls the polarization of the input beam. A sequence of measurements permits determination of the birefringence properties of a perturbing specimen. The necessary correction is calculated and fed back to the polarization modulator to compensate for the polarization perturbation. The system capabilities are demonstrated on a range of birefringent specimens.