We report on a versatile method to compensate the linear attenuation in a
medium, independently of its microscopic origin. The method exploits
diffraction-limited Bessel beams and tailored on-axis intensity profiles which
are generated using a phase-only spatial light modulator. This technique for
compensating one of the most fundamental limiting processes in linear optics is
shown to be efficient for a wide range of experimental conditions (modifying
the refractive index and the attenuation coefficient). Finally, we explain how
this method can be advantageously exploited in applications ranging from
bio-imaging light sheet microscopy to quantum memories for future quantum
communication networks