Inhomogeneous optical properties of biological samples make it difficult to obtain diffraction-limited resolution in depth.
Correcting the sample-induced optical aberrations needs adaptive optics (AO). However, the direct wavefront-sensing
approach commonly used in astronomy is not suitable for most biological samples due to their strong scattering of light.
We developed an image-based AO approach that is insensitive to sample scattering. By comparing images of the sample
taken with different segments of the pupil illuminated, local tilt in the wavefront is measured from image shift. The
aberrated wavefront is then obtained either by measuring the local phase directly using interference or with phase
reconstruction algorithms similar to those used in astronomical AO. We implemented this pupil-segmentation-based
approach in a two-photon fluorescence microscope and demonstrated that diffraction-limited resolution can be recovered
from nonbiological and biological samples.