{'fraction_non_alphanumeric': 0.03156068279872444, 'fraction_numerical': 0.015194147439504783, 'mean_word_length': 4.739335217332795, 'pattern_counts': {'":': 0, '<': 2, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Snapshot coherence-gated direct wavefront sensing for multi-photon microscopy

: Deep imaging in turbid media such as biological tissue is challenging due to scattering and optical aberrations. Adaptive optics has the potential to compensate the tissue aberrations. We present a wavefront sensing scheme for multi-photon scanning microscopes using the pulsed, near-infrared light reﬂected back from the sample utilising coherence gating and a confocal pinhole to isolate the light from a layer of interest. By interfering the back-reﬂected light with a tilted reference beam, we create a fringe pattern with a known spatial carrier frequency in an image of the back-aperture plane of the microscope objective. The wavefront aberrations distort this fringe pattern and thereby imprint themselves at the carrier frequency, which allows us to separate the aberrations in the Fourier domain from low spatial frequency noise. A Fourier analysis of the modulated fringes combined with a virtual Shack-Hartmann sensor for smoothing yields a modal representation of the wavefront suitable for correction. We show results with this method correcting both DM-induced and sample-induced aberrations in rat tail collagen ﬁbres as well as a Hoechst-stained MCF-7 spheroid of cancer cells.


Introduction
Microscopy is of fundamental importance in biological and biomedical research and applications. This is to a great extent due to the development of imaging methods that provide 3D imaging in (optically thick) specimens, such as confocal microscopy [1][2][3] and multi-photon excitation microscopy [4,5]. However, these techniques suffer from specimen-induced aberrations [6,7], which results in reduced depth penetration, loss of spatial resolution, and increased phototoxicity [8] (see Fig. 1). Fig. 1. Left: without sample, a plane wave focusses into a diffraction limited spot. Centre: in the presence of a perturbing sample, the focus is distorted leading to loss of signal and resolution. Right: using adaptive optics to pre-aberrate the wavefront, the focus can be improved.
Adaptive optics (AO) has been successfully used in scanning microscopy to correct these aberrations, demonstrating the potential for AO in this field [9,10]. One class of methods are sensorless methods [10][11][12][13][14] that iteratively optimise a metric such as the mean intensity or sharpness based on the fluorescence signal, without using a dedicated wavefront sensor. Alternatively, the fluorescence can be used to measure the wavefront directly, either using fluorescent beads [15,16], or fluorescent proteins [17][18][19][20] as the biological equivalent of astronomical guide stars [21,22].
Another strategy uses the back-reflected excitation light for wavefront sensing. In this case, selecting only the light from the focal plane and rejecting the light reflected elsewhere along the optical path is a major challenge. Previous attempts solved this with coherence-gated wavefront-sensing methods [23][24][25] or a pinhole [26] to select light from a plane of interest. The former methods use a low-coherence interferometer with either temporal-or spectral modulation, similar to optical coherence tomography (OCT) [27], while the latter uses a pinhole to select a volume overlapping with the laser focus.
In this paper we describe an optical system that combines coherence-gating with interferometric wavefront measurements by interfering the back-reflected beam from the sample with a tilted reference wavefront. The coherent mixing of these two signals produces a fringe pattern where the wavefront aberrations are encoded in the fringe deformation, separating it in the Fourier domain from low-frequency noise. A confocal pinhole provides axial sectioning to reject ghost reflections from e.g. the cover glass, while additionally smoothing out speckles due to scattering samples. The wavefront is then recovered using Fourier transform fringe analysis methods [28][29][30][31].
This paper is organised as follows: Section 2 describes the optical setup, coherence gating, the fringe analysis and the wavefront reconstruction. Section 3 presents results for deformable mirror-induced as well as sample-induced aberrations and corrections. Finally, section 4 discusses advantages and potential improvements of this method.

Method
We use the back-scattered near-infrared light to measure the wavefront aberration induced by (biological) samples in a scanning microscope setup. This light is usually discarded as the specimen is imaged using the fluorescent light. By interfering the back-scattered light with a flat reference wavefront with a known tilt, we measure a fringe pattern in a re-imaged backaperture plane of the objective. The wavefront aberrations in the sample arm are then encoded as deformations of the fringe pattern [28]. Figure 2 shows the optical schematic for coherence-gated wavefront sensing. We use a Coherent Chameleon Ultra II Ti:Sa 140 fs pulsed, near-infrared laser beam as the source, which is expanded 12 times to a 14 mm beam (L1, L2 in Fig. 2). The beam is divided by a non-polarizing 50/50 beamsplitter (BS1, BS017 Thorlabs) into a reference beam (long-dashed) and a sample beam (solid). We stop down the beam to 9.5 mm before it is reflected by the deformable mirror (DM, Okotech MMDM 19-channel deformable mirror) such that we only use the central, well-controlled region [32]. The beam is then re-imaged by lenses L3 and L4 (both f=300 mm, Thorlabs NIR achromats) onto the back aperture of the objective. Since the deformable mirror can only introduce wavefront correction in one direction, we bias the mirror to mid-actuation to allow for both positive and negative path-length correction. The collimated beam reflecting off the deformable mirror is therefore converging, which is compensated for by lenses L3 and L4. We use a Nikon 20×/0.75 NA multi-immersion objective with water, which has a backaperture diameter of 16 mm; the effective numerical aperture is 0.42. Additionally, we use a Nikon 40×/0.90 NA air objective whose 9.5 mm back-aperture is filled.

Optical setup
The sample is mounted on an XYZ piezo stage (PI, Nanocube P-611.3S). Fluorescence emitted from the sample is split off by a 705 nm cut-off dichroic beamsplitter (DBS, Semrock, FF705-Di01-25x36) where we use an additional 720 nm short-pass filter (Semrock FF01-720/SP-25) to block stray laser light. The fluorescence is then imaged onto a 600 µm fibre feeding a photo multiplier tube (PMT, Hamamatsu, GaAsP photocathode H7422P-40). Laser light reflected back from the sample passes back through the objective and the DM into the wavefront sensor arm via BS1. The sample beam is de-magnified by a factor 3 by lenses L6 and L7 (f=300 mm, 100 mm, Thorlabs NIR achromats) onto the wavefront-sensing camera (CCD, AVT, Guppy Pro F-033b, 12bit, 656×492 pixels, each 9.9×9.9 µm). We use a 400 µm pinhole (PH, custom made) confocal to the focal plane to reject unwanted light, e.g. from the cover glass, similar to [33]. At the position of the pinhole, the diameter at the first minimum of the diffraction-limited Airy disc is 62 µm at a wavelength of 750 nm. The reference beam's optical path length is matched to the sample beam path length by moving mirrors M5 and M6, and the intensity is matched by a neutral density filter (ND, reflective, Thorlabs). The beams are combined by a 50/50 beamsplitter (BS2, BS017 Thorlabs). Mirrors M3 and M4 are optional and used for the deformable mirror calibration.
We use a data acquisition board (National Instruments, PCI-e 6259) for reading out the PMT signal, as well as for controlling and reading out the piezo stage. We drive the piezo stage using a sinusoidal signal for the fast axis with a typical frequency of 20 Hz. Simultaneous to driving the piezo stage, we record the stage position using the strain gauge sensors. With a constant PMT integration time this yields non-square pixels due to the varying piezo speed, which is corrected in software using the position feedback. The camera is connected to a Firewire controller, and the deformable mirror is connected to a stabilised high-voltage amplifier, which is connected to a 32-channel PCI DAQ card. We control the PMT and piezo stage using a Windows computer running LabView, and the camera and deformable mirror are controlled by a Linux computer with Python.

Coherence gating
The sample and reference beams have identical optical path lengths when arriving at the CCD. Since the laser is pulsed, this creates interference only between the reference wavefront and light reflected off a thin layer of interest in the sample to which the optical path length of the reference beam is tuned. This principle is shown graphically in Fig. 3. Light that is reflected outside of this layer does not arrive at the camera coincidentally with the reference beam pulse and does not interfere, although it does add a background signal. This background signal is reduced by the confocal pinhole.

Sample
Coherence gate CCD Fig. 3. Excitation light entering from above is split into a reference and sample beam. In the sample, the light is reflected at different depths, but only back-scattered light from a thin layer, the coherence gate (solid red), has the same optical path length as the reference beam and will interfere to form fringes on the CCD. Pulses that originate from deeper or shallower in the sample (dashed red lines) arrive later or earlier (dashed red waves) than the reference pulse and do not contribute to the fringe pattern and add a static background.
As the reference beam wavefront is static, the interference pattern only depends on the wavefront aberration in the sample beam. By inducing a wavefront tilt in the reference beam, we generate an interference fringe-pattern on the CCD. The deformation of these fringes contains information on the wavefront aberration, which are due both to the sample being studied and static aberrations in the optical system [28,31].
We can recover the complex wave using Fourier analysis of the fringe pattern. When bandpass-filtering the modulated fringe pattern in Fourier space, both low-and high-frequency noise such as ghost reflections and other spurious signals will be strongly suppressed.
The coherence length, or the spatial extent over which the pulses of the two beams overlap, is given by the correlation of the reference and sample pulses. With 140 fs hyperbolic secantsquared pulses generated by the laser, the FWHM of the autocorrelation is 65 µm in air. We measured a FWHM coherence length of l c = 83.7 ± 0.3 µm using a mirror as a target, which is 29 % broadened compared to the value given by the manufacturer, most likely by group velocity dispersion due to the optics in the setup. In an aqueous fedium with n ≈ 1.3 this corresponds to a coherence gate length of l c /2n = 32 µm [34], similar to values obtained by [23,35].
Although dispersion compensation could be used to improve the fringe contrast or minimize the coherence gate [24,35], these were not as much a limiting factor here as the speckle-induced amplitude aberrations and the limited deformable mirror stroke and number of actuators. Further exploitation of the method could, however, benefit from such correction.

Confocal pinhole
We use a confocal pinhole in the back-reflected light detection path before the wavefront sensor for two purposes: it rejects out-of-focus light, and the pinhole acts as a low-pass filter that smoothes out speckles in the coherence-gated image. It thereby acts as a low-pass filter for wavefront (and amplitude) aberrations with a cutoff that is commensurate with the number of degrees of freedom of the DM.
The first benefit works in tandem with the coherence gating. The axial depth sectioning of a detection pinhole with diameter d ph in the geometrical regime is given by where M is the magnification of the system and α the objective acceptance angle of the detection path [36]. The 400 µm pinhole in our case gives ∆z = 40 µm for the 20× objective in water and ∆z = 6.8 µm for the 40× objective in air.
Empirically we determined the axial sectioning of the pinhole by measuring the integrated intensity on the wavefront sensing camera off a cover glass as function of the axial position of the cover glass. We found a full width at half maximum (FWHM) axial resolution of ∆z = 46 µm and ∆z = 6.8 µm for the 20× and 40× objectives, respectively.

Fourier transform fringe analysis
The fringe analysis method is based on [28,31], who describes a heterodyne technique to encode the low-frequency aberrations with a higher frequency carrier signal, separating it from low-frequency noise. Here we apply the method for coherence-gated wavefront sensing in scanning microscopes. Using Fourier filtering we extract the wavefront aberrations from the fringe pattern deformation. In this experiment we use a spatial carrier signal to allow wavefront measurements in a single frame, whereas in time-domain method such as for example in [24], four frames are required for a single wavefront measurement.
The fringe pattern is described by Eq. (1) in [28] g(x, y) = a(x, y) where φ (x, y) represents the wavefront and a(x, y) and b(x, y) represent irradiance variations. In this context, a(x, y) is a static background from e.g. ghost reflections and b(x, y) are amplitude variations in the fringe pattern, such as those due to speckles. f 0 is the known spatial carrier frequency induced by the tilt in the reference wavefront, in this case along the x-axis. a(x, y) can be measured by de-tuning the coherence (such that the second term is zero). b(x, y) can be determined by modulating the fringe pattern by varying the path length difference between the sample and the reference beams. Using the Fourier analysis described in [28], we can recover the complex phase from the real fringe pattern. Note that temporal variations slower than the exposure time (4 ms to 8 ms) do not influence the wavefront measurements because the phase is recovered from a single measurement. During the experiments the fringe contrast was sufficient for wavefront sensing in approximately 95 % of the frames, while fringes moved significantly from one frame to the next. We did not experience any problems with internal seeing and mechanical vibrations.

Calibration
The wavefront sensor is calibrated before use by removing system aberrations (including the initial non-flatness of our DM), recording a flat-field and the carrier frequency, and measuring the non-common path aberrations between the focal plane and the wavefront sensor. One sideband at f 0 is isolated and inverse transformed, yielding the complex wave (top right). The wave is propagated through a virtual Shack Hartman wavefront sensor to obtain a spot pattern (bottom right), which is reduced to a vector of spot displacements (bottom center). By multiplying this vector with a response matrix of a certain basis (e.g. Zernike), we obtain a modal description of the wavefront (bottom right).
We first maximise the two-photon fluorescence signal from a fluorescein solution by optimising the deformable mirror shape using a Nelder-Mead simplex algorithm [37,38]. Since the fluorescence signal is given by the integral over the PSF squared, maximising the intensity minimises the volume of the PSF [39]. This system correction removes static aberrations in the setup, including the initial non-flatness of the deformable mirror. We observe a significant improvement of tens of percents of the fluorescence signal after this correction, indicating that we successfully correct static aberrations.
We obtain a flat-field image by de-tuning the coherence gate and averaging over 250 frames. This image is used to divide the raw frames thus correcting for a(x, y), and the inhomogeneous illumination of the CCD. Inhomogeneity in b(x, y) is accounted for by tuning the carrier frequency f 0 such that the sideband is well-separated from the low-frequency noise peak in the Fourier domain. We verify this by inspecting the power spectrum of the fringe pattern. Through trial and error, we find that approximately 30 fringes across the camera is an optimal value for the fringe analysis method. The radius of the region of interest around f 0 (dashed circle in Fig. 4, panel two) is set to half the length of f 0 .
Finally, we use a scattering-bead solution consisting of fluorescein-containing silica beads (d=106 nm, 2 × 10 14 mL −1 = 2 × 10 2 µm −3 ) suspended in water to measure the response of the wavefront sensor on the previously defined flat wavefront, where we average over 200 frames to obtain a robust measurement. A scattering-bead solution is more suitable than a mirror since this back-scattering is more similar to what is expected from real samples. This wavefront measurement corresponds to the non-common path errors between the focal plane and the wavefront sensor, and is subtracted from subsequent measurements to obtain the real wavefront errors induced by the specimen.

Wavefront recovery
To obtain the wavefront phase, we record an image using a CCD and process it as described above. This image is apodised and Fourier transformed, and a region around f 0 is isolated, rejecting both the low-frequency and high-frequency noise as suggested by [40] (see Fig. 4 upper-centre panel). The crop window size is a tradeoff between the spatial resolution of the wavefront (larger window) and noise rejection (smaller window). Using a radius of approximately 0.5| f 0 | for the circular crop window, we were able to successfully isolate the sideband. We then inverse Fourier transform the isolated sideband to yield the complex wave.
In theory, the phase can be recovered from the complex wave (Eq. 6 from [28]), however this only works robustly if the fringe pattern is well-behaved. In our experience, this straightforward approach produces unreliable phase maps with discontinuities and singularities. While the former can be solved by unwrapping the phase [41,42], singularities are more difficult to overcome.
We use a virtual Shack-Hartmann wavefront sensor (vSHWFS) to mitigate this, as proposed by [23,24]. We take the complex wave and divide it into 16 by 16 sub-apertures of 20 by 20 pixels each, comparable to [24]. For each of these sub-apertures we compute the power of the Fourier transform, which gives an image of the complex wave at the location of the sub-aperture. This yields an image like one obtained with a Shack-Hartmann wavefront sensor ( Fig. 4 bottom-left panel), where the displacement of the spot position from the center is proportional to the local phase gradient [43].
To convert this spot pattern into a modal description of the wavefront z we first compute the displacement vector for each spot, v (Fig. 4 bottom-center panel). We then compute the theoretical vSHWFS response matrix H for a number of Zernike modes [44,45] and solve v = H z in the least-squares sense using the average intensity of each sub-image w as weights to obtain z. This is done for each iteration as both v and w change. Hence sub-apertures that receive little light are weighted less, preventing those from adding noise.

Scattering and speckles
As biological tissue is generally highly scattering, imaging the back-reflected coherent light onto a detector will produce strong speckle patterns [46]. These speckles arise from coherent superposition of light scattered by the (biological) tissue, which forms an interference pattern observed as speckles. This effect was found to be problematic in phase-step interferometry applications [23,24] where multiple images have to be combined to recover the complex wave, and the authors solved this by averaging several measurements with different speckle patterns. [34] investigated the behaviour of speckles and quantified the influence of a confocal aperture on the speckle sizes, among other things. They found that a smaller aperture will yield larger speckles, which can be explained by the spatial filtering of the aperture.
In our case, the confocal pinhole used for axial sectioning also provides low-pass filtering, smoothing out speckles smaller than the diffraction-limited resolution of the pinhole. This effect is illustrated in Fig. 5, where a wavefront sensor image is shown using the scattering beads solution with and without the 400 µm pinhole (left and center panels). When using a confocal pinhole a trade-off needs to be made between speckle reduction [34] and wavefront measurement resolution [33]; a larger pinhole will allow wavefront aberration measurements with higher resolution while a smaller pinhole will reject scattered light better.
In addition to the spatial filtering by the confocal pinhole, the Fourier bandpass filter separates the fringes from the speckles as long as their spatial frequencies do not overlap. The spatial resolution of a plane wave incident on a circular aperture is given by . These images were observed by the WFS camera at the back aperture plane. The left images was obtained without a confocal pinhole, while the center and right images were taken with one in place. Additionally, the right images were flatfield corrected and interfered with the reference beam to produce fringes. The scattering bead solution shows a strong and homogeneous speckle pattern, while the spheroid shows larger speckles, indicating it is less scattering. The speckle pattern is spatially filtered by the confocal pinhole such that the fringe pattern contrast is enhanced, although larger-scale amplitude variations were still present. As can be seen in the center and right columns, the spatial frequency of the filtered speckles is similar for both samples. The fringe pattern has a higher spatial frequency than imposed by the confocal pinhole because the reference beam is introduced after the pinhole. All images were taken with the 20× objective and all fields of view are the same.
where θ is the half-opening angle of the beam. In this case, the 400 µm pinhole and the f=100 mm lens (L7) yield a resolution of 230 µm at the CCD, such that any feature smaller than this (i.e. speckles) will be smoothed out. This is in agreement with what was found by [34], where their smallest field of view corresponds to a ∼3 mm confocal aperture, which has a resolution of ∼30 µm, or ∼3 pixels on their CCD 1. As expected, this ∼3 pixel resolution is a lower limit in their Figure 5 (top row). Because the reference beam is combined with the sample beam after the confocal pinhole, the spatial frequency of the fringe pattern can be higher than the maximum spatial frequency of the transmitted wave by the confocal pinhole. Since the fringe frequency as well as the pinhole diameter are free parameters, these can be selected such that the speckles and fringes are wellseparated in the Fourier domain.
Something the confocal pinhole does not prevent, however, is the amplitude modulation induced by the speckles. As can be seen in Fig. 5, there are both saturated and dark spots in the image where the fringe contrast is reduced significantly. In these locations the phase cannot be reconstructed properly, and to mitigate this we measure the wavefront at different locations in the specimen with different speckle patterns, similar to [23,24,34]. However, compared to those methods we obtain the wavefront from one frame, after which the wavefront measurements are averaged, as opposed to the 4-frame requirement of phase-stepping interferometry.

Double pass
In direct wavefront sensing, the beam passes through the sample twice, once towards the focus and once back-reflected. Because of this, the sensitivity for different wavefront aberration modes can be different. [33] show that there is a difference between even and odd modes in the case of a pure specular reflection, something which has long been known in retinal imaging [47,48]. In the other extreme when a purely scattering sample is used instead of the mirror, there is little to no correlation between the incoming angle and back-reflected angle, such that the scatterers in the specimen all act as point sources and their back-reflections are coherently super-imposed [49]. In real samples, the sensitivity to modes can differ significantly, but unlike a mirror reflection, odd modes can have non-zero sensitivities and thus can be detected [33].

Wavefront correction
To verify the wavefront-sensing method, we control the deformable mirror in closed loop, minimising the residual aberrations measured by the wavefront sensor.
Before correction, we characterise the response of the deformable mirror using mirrors M3 and M4 to direct the laser beam directly onto the wavefront sensor after reflecting off the deformable mirror only once. To interfere the reference beam with the shorter calibration beam, we use the alignment laser, which is a continuous wave and as such also interferes with a beam of unequal optical path length. Because this gives a well-behaved fringe pattern, we can directly obtain the phase from the complex wave using Eq. 6 from [28]. This phase is unwrapped using Itoh's weighted phase unwrapping scheme [40] with the amplitude of c(x, y) as weight.
The result of the above calibration produces an influence matrix of the deformable mirror, mapping the input voltages to mirror shape. We use the pseudo-inverse of this matrix to control the mirror, where we typically use all but one singular value in the inversion. Using a basis set of Zernike modes we can construct a matrix that maps a vector of Zernike amplitudes to mirror voltages, which we use for our control. Because of the finite number of actuators, we limit the control of the DM to Zernike modes 5 to 15 (ordering from [45]), excluding mode 12, which the DM cannot produce due to the actuator configuration. When driving only even modes, we use Zernike modes 5, 6, 11, 13, 14 and 15. When running the system there are occasionally frames with blurred out fringes, probably due to lab seeing or vibrations, for which the wavefront is poorly defined. To mitigate this, we reject frames with a low fringe contrast, as defined by the power in the extracted side band. Images with less than 75 % of the average power of the last 100 frames are discarded. For accepted frames, we take sets of 4 images, for each of which we compute the vSHWFS spot pattern. We take the median image of this set, from which we compute the spot displacement vector. We compute the modal phase representation by multiplying the displacement vector with the response matrix, weighing it with the average intensity in each sub-image, as described above.
Although the speckle pattern induced by the scattering samples is smoothed by the spatial filtering of the confocal pinhole, it nonetheless induces strong amplitude variations. As described above, we mitigate this by averaging speckle patterns recorded at different positions. This is achieved by applying the phase corrections to the deformable mirror with a proportional gain of 0.05 while scanning the sample over a variable-sized area. System-corrected Aberration-corrected Fig. 6. Correction of DM-induced aberrations Z 5 , Z 6 , Z 11 (top) and Z 5 -Z 8 (bottom) with the 20× objective in rat tail collagen fibres using the 20× objective. The panels show an image with the DM in aberrated shape (left), the system-corrected image (centre) and an image after aberration correction (right). For both cases, modes Z 5 -Z 15 were controlled with the DM when correcting, and the sample was scanned over the area indicated by the dashed box. After correction we obtain images similar to the system-corrected DM case, although the even-only aberration correction (top) performed better in this case. The grayscale is identical in each row. The cross-section profile is taken along the arrow: dashed for aberrated, gray for system-corrected, and black for aberration-corrected data.

Results
To verify our wavefront-sensing method, we test it in different biologically relevant scenarios using both a 20×/0.75 NA and a 40×/0.90 NA objective. We perform DM-induced aberration correction and correction of sample aberrations, which are compared with a flat DM with respect to the fluorescent optimum as described in section 2.5.1. When running the correction, scanning over an area to average out the amplitude modulation effect of speckles also allows us to record the fluorescence intensity during the correction. We stop the correction when the average intensity of the scanned area stops to increase, which is typically after approximately 100 iterations, or roughly one minute. After correction, a 256 by 256 pixel image is recorded at 0.5 ms pix −1 , which takes 30 s.

Collagen tendons
Collagen fibres were extracted from a rat tail and washed 4 times in distilled water. Following fixation in 4 % paraformaldehyde, the collagen fibres were washed in PBS and then embedded in 3 % agarose (Sigma-Aldrich chemie GmbH) in a 35 mm glass bottom dish (MatTek Corpo-ration). We image the fibres using 900 nm excitation light to produce the second harmonic signal approximately 50 µm deep inside the rat tail fibre, using the underfilled Nikon 20×/0.75 NA objective. The DM is set to an aberrated shape using mostly even modes (Z 5 , Z 6 , Z 11 , Figs. 6 & 7 top) as well as both even and odd modes (Z 5 , Z 6 , Z 7 , Z 8 , Figs. 6 & 7 bottom) and run the control loop as described above.
During correction of the aberrations, we scan the sample over a sub-region of 20 by 20 µm, indicated by a dashed box in the figures. We run the loop until the fluorescence intensity in the scanned area stabilises. Using this corrected DM shape, we image the original region again for comparison, shown on the right in Fig. 6, while the centre column shows images obtained with only correction of system aberrations for comparison.
Correction of only even aberrations yields better results than correction of even-and-odd aberrations, as can be seen from the increased brightness and contrast in Fig. 6. This is possibly due to the double-pass effect, which makes the correction of odd modes more difficult, although as can be seen in Fig. 7, these modes can, to a large extent, be corrected. In both cases, we are able to correct the induced aberrations as shown Fig. 7 and recover the image quality as obtained after only correcting system aberrations. While the amplitude of the induced aberrations should decrease, it does not necessarily have to go to zero in the case that there are aberrations in addition to the system-correction. In any case the corrected shape should be the same for both correction runs, as they were obtained at the same location. As can be seen in the left panels of Fig. 7, the correction generally obtains the correct value for each mode, although some modes show a discrepancy (such as Z 11 ).  Fig. 6: the top and bottom rows correspond to the respective rows in Fig. 6. Left: modal decomposition of deformable mirror shape during the correction experiment. The triangles note the initial DM shape and the squares indicate the final shape with respect to a system-corrected DM, the dots in between denote intermediate corrections. Right: norm of the DM shape during the experiment. The decay in the norm of the DM shape indicates that the correction is successful in recovering the system-corrected setting. See text for details.

MCF-7 Spheroids
We also measure and correct wavefront aberrations inside an MCF-7 breast cancer spheroid [50]. The spheroids were generated from cultured MCF-7 using liquid-overlay technique as described in [51]. After aggregating for 7 days, spheroids of 0.5 mm to 1.2 mm diameter were harvested for measurement. These spheroids were fixed in 4 % formaldehyde and permeablised in 0.2 % Triton x-100 (Sigma-Aldrich). The samples were washed 3 times in PBS. Following blocking with 10 % FBS, the spheroids were incubated with Hoechst 33342 (Molecular Probes) and finally washed with PBS. The samples were then embedded in 3 % agarose in concave microscope slides (Marienfeld-superior). We excite the Hoechst using 750 nm excitation light, and during the experiments we note no significant bleaching (<5 %).

Aberrated 10µm
System-corrected Aberration-corrected Fig. 8. DM-induced aberrations Z 5 -Z 8 correction in a Hoechst-stained MCF7-spheroid sample using the 20× objective. The averaging area for the correction is indicated by the dashed box. Note that there is no observable bleaching in this area. The grayscale is identical, the cross-section profile is taken along the arrow. As with the collagen fibres, we introduce even and odd aberrations with Zernike modes 5 through 8 (Figs. 8 & 9). We image a region of 80 µm by 80 µm at 35 µm depth inside the spheroid using the underfilled 20×/0.75 NA objective with the DM set to the aberrated shape. We run the loop until the fluorescence intensity in the small scanned area stabilises, after which we image the larger region. These results, comparing the aberrated, flat and corrected DM shapes, are shown in Fig. 8.
As with the collagen fibres, also here we are able to correct the induced aberrations and significantly improve the image quality as given by a system-aberration corrected setup. Odd aberrations are also corrected here, indicating that we indeed also obtain odd aberration information from the wavefront sensing (Fig. 9). During correcting, the sample was scanned over the region indicated by the dashed box. The grayscale is identical in each row. The cross-section profile is taken along the arrow: dashed for aberrated, gray for system-corrected, and black for aberration-corrected data.
Subsequently, we imaged the same sample with a 40×/0.90 NA air objective. We image a region 20 µm deep inside the spheroid, and use the correction collar to correct for depth-induced spherical aberration, setting the collar to correct for 17 µm glass ≈ 20 µm water (assuming n sample ≈ 1.3). We add even-and-odd and even aberrations on the DM with the same modes and amplitudes as before, and correct these.
The results are shown in Fig. 10. We observe a slightly different image location, which is possibly due to correction of spherical aberration, which reduces the depth of focus, or accidental introduction of (de-)focus due to inaccuracies in the calibration. In both cases we are able to correct the DM-induced aberrations. In the second case when correcting even-and-odd aberrations (bottom panels), the control loop improves the image compared to only system-aberration correction, showing increased brightness but also contrast. As can be seen in Fig. 11, the correction does not converge to zero amplitude for the different modes, however the two experiments do both converge to similar values (e.g. Z 5 , Z 6 and Z 7 ), indicating that we are correcting sample-induced aberrations as well.
Finally, we image a deeper region at 35 µm without further adjustment of the correction-collar   ring on the objective. This yields depth-dependent sample aberrations due to the refractive index mismatch of air and the spheroid. In this case we had to stop the correction prematurely due to saturation of the DM actuators. These results are shown in Fig. 12, showing both higher intensity and contrast as compared to only system correction, and smaller features in the cell nuclei become visible. As can be seen in Fig. 13, there is significant spherical aberration (Z 11 ) as expected because of the uncorrected refractive index mismatch, but we additionally find strong coma (Z 7 ). Since these images were obtained at the edge of the spheroid, the spherical surface might induce such coma aberration. Additionally, we find <0.5 rad amplitudes for modes Z 5 , Z 6 , Z 8 and Z 9 . Correcting depth-dependent sample aberrations is important as there is never a perfect match between immersion fluid and sample, which results in these types of aberrations [12]. We find that our method is capable of correcting such aberrations, but during the experiments we were constrained by the limited stroke of the deformable mirror. A mirror with large stroke, especially for spherical aberration, is therefore desirable.

Discussion
We developed a direct wavefront-sensing method that is capable of deriving the phase from a single image instead of four. By using a confocal pinhole, we strongly reduce ghost reflections and smooth out speckles in our camera. The Fourier analysis of the fringe pattern additionally allows us to filter out low and high spatial frequency noise. Since we retrieve the complete wavefront information from a single measurement, as compared with time-domain methods [23-25, 34, 52], this method is faster and does not require moving parts to generate the interferogram. Because of this, vibrations and internal seeing are less problematic. Although in strongly scattering samples averaging is required to overcome speckle-induced amplitude variations, this is similar to other methods. In addition, most low spatial frequency noise can easily be separated in the Fourier domain, as long as there is sufficient fringe pattern contrast. Finally, this method accommodates varying back aperture sizes and aberration characteristics without changing optical elements, and the trade-off between dynamic range and sensitivity can be adjusted by simply changing the reference-wavefront tilt.   Like [24], we find that the phase extracted from the fringes is ill-defined and contains singularities and discontinuities. This is likely due to the back-scattering occurring in a volume, such that the measured image is a coherent super-position of fringe patterns from different scatterers in the focal volume. We observe this fact in, for example, the scattering-bead solution, where the fringes bifurcate, indicative of a phase singularity. We find that using a virtual Shack-Hartmann wavefront sensor overcomes these problems.
The double-pass through the sample changes the sensitivity for different wavefront modes, where even modes are more easily sensed than odd modes [33]. While odd modes are measured by direct wavefront sensing, these measurements have a lower SNR. One way to solve this is to combine a direct wavefront-sensing method with intensity optimisation. Since the methods measure the wavefront differently, the reconstruction becomes better defined, alleviating the even-odd asymmetry problem. Combining these two feedbacks for the correction is therefore a logical next step.
Since speed is important in scanning microscopy, so is the speed of the adaptive optics method to be used. In this context, we estimate that the method is, in principle, fast enough to keep up with scanning microscopes [24]. The wavefront sensor camera exposure time used for these experiments is 4 ms to 8 ms. Using a more sensitive and faster camera should be sufficient to run the control loop at up to 1 kHz. Although this does not include computational load, the core of our wavefront-sensing analysis comprises Fourier transforms, which for 10 5 pixels can be done at 1 kHz. Currently we need ∼100 iterations per correction, in part due to the low 0.05 gain, which was chosen for robustness, and we are confident that this can be decreased if the control is improved. One improvement is using quadratic programming as done by [24], which additionally prevents saturation of the DM.
Although per-point correction is not feasible in this way, considering that the wavefront changes gradually over the sample [53], we can measure and correct the wavefront on a coarser grid than what we are scanning, such that 6 2 to 8 2 wavefront measurements are needed per sample. We conclude that our method is, in principle, fast enough to be applied to real-time systems.

Conclusions
We present an aberration correction method that directly measures the wavefront of the backreflected light in multi-photon microscopes. By measuring the interference pattern between a reference beam and a sample beam, we are able to retrieve the wavefront and correct aberrations. Using coherence gating and a confocal pinhole, only light from a shallow layer of interest of the order of 10 µm is selected. Furthermore, the pinhole smoothes out speckles produced by the scattering samples. Coherence-gated fringe analysis is insensitive to temporal variations slower than the exposure time (internal seeing, vibrations) as it obtains the wavefront information from a single measurement as opposed to four measurements in phase-step interferometry.
We use the back-reflected laser light for wavefront sensing, by using both a confocal pinhole for smoothing speckles and to reduce the background signal from e.g. the cover slip, as well as coherence gating to extract wavefront information. Although coherence gating could, in principle, be used exclusively for depth selection, this adds a strong background signal, degrading the fringe contrast and making it difficult to extract the wavefront. Furthermore, using a confocal pinhole is advantageous in the presence of speckles, which are generally present in scattering specimen. While we have not investigated this in these experiments, the size of the confocal pinhole is a free parameter and allows for a trade-off between speckle rejection [34] versus wavefront sensing resolution [33]. Since the reference beam is combined with the sample beam after the confocal pinhole, this does not constrain the fringe frequency, which can also be freely chosen. These degrees of freedom could allow for deeper measurements of the wavefront, and requires further investigation.
The maximum depth at which direct wavefront sensing in scattering samples works was investigated by [34]. They find that at a certain depth the wavefront cannot be recovered anymore, which they attribute to multiply scattered photons from random locations in the sample acci-dentally falling in the coherence gate. Because of this, there is not a single unique wavefront that can describe the phase of those photons anymore. Since a pinhole rejects scattered light, we suspect that using this allows measuring deeper in the sample. The depth gains that a pinhole brings need to be investigated in more detail.
We show the feasibility of the method in rat tail collagen fibres as well as in a spheroid of Hoechst-stained MCF-7 cells, indicating that it also works in the presence of scattering-induced speckles. We correct both only even and even-and-odd DM-induced aberrations, and are able to improve the image compared to only system-aberration correction. Additionally we are able to correct depth-dependent sample aberrations present in any microscopy system due to refractive index mismatches between sample and immersion fluid.