MLDT: an open-source multilayer diffusion theory Python implementation Thomas T. Livecchi, Mark C. Pierce, Steven L. Jacques Abstract Abstract.SignificanceDiffuse reflectance spectroscopy and imaging are powerful noninvasive tools for quantifying tissue biomarkers such as hemoglobin, melanin, and water. A theoretical model of light propagation is required to interpret these reflectance measurements and translate them into quantitative biomarker concentrations. Although Monte Carlo (MC) simulations offer the gold-standard in accuracy, their high computational burden renders them impractical for real-time iterative inverse solving. Conversely, standard analytical approximations can be efficient but often oversimplify tissue as a semi-infinite homogeneous medium, leading to significant errors when analyzing layered structures.AimWe aim to develop a generalized, computationally efficient forward model capable of rapidly predicting light transport in complex, multilayered tissue structures.ApproachWe present a generalized derivation and open-source Python implementation of the P1 diffusion approximation for predicting diffuse reflectance from tissue with an arbitrary number of layers. This framework utilizes a vectorized banded matrix approach to solve the fluence rate equations efficiently. The model was validated against 400 randomized MC simulations encompassing architectures ranging from one to eight layers.ResultsDiffuse reflectance spectra predicted by the generalized multilayer diffusion theory model show strong agreement with MC simulations in the diffusion regime (μa≪μs′), achieving a median spectral root mean square error of 0.0145 across the validation set. Computation times were over 5 orders of magnitude faster than GPU-accelerated MC, yielding a mean calculation time of 0.0087 s to generate a single predicted diffuse reflectance spectrum given a set of input optical properties and a speedup of ∼277,607×. Notably, validation results demonstrated that numerical error does not scale with structural complexity, indicating that multilayer architectures maintained high stability.ConclusionsWe provide an accurate, computationally efficient, and generalized tool for modeling light transport in stratified media. By combining the ability of MC modeling to simulate complex tissue structures, with the speed of analytical diffusion methods, this tool facilitates real-time, depth-resolved quantitative tissue profiling. The full source code is made freely available to the community. Introduction Noninvasive optical diagnostics are increasingly utilized in clinical applications ranging from skin cancer detection to monitoring tissue hemodynamics. These techniques rely on solving the inverse problem of deducing physiological properties such as tissue oxygenation and melanin concentration from measured optical signals. To achieve this, a forward model is required that accurately relates a tissue’s optical properties (absorption coefficient μa and reduced scattering coefficient μs′) to its diffuse reflectance spectrum. A fundamental challenge in tissue optics is accurately modeling the stratified architecture of biological tissues. Human skin, for example, is inherently multilayered, consisting of a thin, melanin-rich epidermis, a blood-rich dermis, and a subcutaneous fat layer.– Functional near-infrared spectroscopy uses multilayer tissue models for scalp, skull, and brain tissue. Standard homogeneous models, which assume a semi-infinite uniform medium, are mathematically convenient but physically inadequate for such structures. They often fail to distinguish between surface absorption and deeper absorption, leading to cross-talk errors where changes in one layer fundamentally bias the recovered parameters of another. In quantitative tissue optics, the relationship between light and matter is characterized by two distinct problems. The forward problem involves predicting the measurable reflectance spectrum based on a known set of underlying optical properties (μa,μs′). This requires a solution to the radiative transport equation (RTE) to simulate how light propagates through a specific geometry. Conversely, the inverse problem is the process of deducing those unknown physiological properties from the measured reflectance signals. Because the inverse problem is typically solved by iteratively adjusting parameters until the model’s output matches the measurement, the accuracy of the recovered properties is fundamentally dependent on the precision of the underlying forward model. These models range from fast analytical approximations to computationally intensive numerical simulations. For applications where computational speed is paramount, the RTE can be simplified into an analytically solvable form. The most common approach is diffusion theory, which can be formally derived using the P1 approximation. The P1 approximation assumes that the radiance can be approximated by a linear combination of an isotropic component (the fluence rate) and a directional component (the flux). This simplification is valid in highly scattering media where the scattering coefficient is much larger than the absorption coefficient (μs′≫μa). Higher-order spherical harmonics approaches, such as the P3 approximation, have been developed for multilayer media to bridge the accuracy gap between the standard P1 approximation and Monte Carlo simulations. To address tissue heterogeneity, researchers have traditionally relied on stochastic Monte Carlo (MC) simulations and deterministic analytical approximations. Monte Carlo methods, particularly accelerated GPU-based implementations like MCX,– are considered the gold standard for accuracy as they rigorously solve the RTE. However, despite hardware acceleration, MC remains computationally expensive for iterative inverse fitting routines that may require thousands of forward calls per measurement. Although look-up table approaches– and machine learning– surrogates have been employed to bypass this bottleneck, they often lack flexibility, requiring extensive retraining or regeneration when the model geometry changes. Early work by Farrell et al. established the utility of the diffusion approximation for estimating the spatially resolved diffuse reflectance from semi-infinite media. This work utilized a dipole source model to simplify the relationship between optical properties and measured signals. Hielscher et al. and Kienle et al. proved that the partial-current boundary condition offers a much more accurate representation of photon migration than simpler models. This improvement is especially important for steady-state reflectance where the refractive index mismatch significantly impacts the light distribution near the surface. Although these advancements refined the accuracy of the diffusion approximation for uniform tissue volumes, they also introduced more complex math when internal boundaries are added. To address the layered nature of biological tissue, researchers developed multilayer diffusion models to separate the epidermis and dermis. Early work by Keijzer et al. established that boundary conditions for surfaces and internal interfaces could be solved using numerical methods to account for refractive index mismatches. Later, Spott et al. further refined two-layer diffusion models using photon density waves. Although these models represented a major step forward, they often rely on solving transcendental equations or finite element meshes that can become unstable or computationally demanding as more layers are added. There is still a practical gap in the field because current analytical tools lack a unified and efficient way to scale from a few layers to many layers. Most existing software is either closed source or not optimized for the rapid iterative calls needed for inverse profiling. This work addresses that gap by providing a generalized matrix approach that remains stable and fast for any number of layers. This work presents the derivation and validation of a generalized multilayer diffusion theory (MLDT) solver implemented in Python. By employing a vectorized matrix formalism, this solver extends the analytical diffusion solution to N layers with negligible computational overhead. The approach is validated across a wide range of optical properties and structural complexities against gold-standard Monte Carlo simulations to evaluate its forward predictive accuracy, numerical stability, and speed. The complete source code is provided as an open-source resource (https://github.com/ttlivecchi/mldt.git), enabling the biomedical optics community to easily integrate multilayer physics into inverse profiling workflows. Methods Physics This derivation extends the two-layer diffusion model derived by Spott et al. to a generalized system of N stratified layers. By retaining the core boundary conditions used in the two-layer case, we formulate a recursive matrix approach that solves for the fluence rate across arbitrary geometries. For each layer i, the optical properties are the absorption coefficient (μa,i) and the reduced scattering coefficient (μs,i′). We assume an incident light power Φt (which will factor out in reflectance calculations) and a uniform bulk refractive index nr for the tissue medium, assuming index-matched internal layers. The first fundamental relationship of the diffusion approximation is the conservation of energy, which states that the rate of change of energy density within a volume is equal to the net flow of energy into or out of the volume plus any energy generated or absorbed within it. The second fundamental relationship of the diffusion approximation is Fick’s Law, which relates the net flow of energy (the flux) to the gradient of the energy density (the fluence rate). Combining these two principles, the steady-state diffusion equation for the fluence rate φ(z), which describes the total radiant energy flowing across an infinitesimal sphere at position z, can be derived. For a homogeneous medium with a source q(z), the equation is ∇2φ−φδ2=−qD.(1) The key parameters of this equation are the transport coefficient μtr, the diffusion length D, and the penetration depth δ. The transport coefficient, μtr, is a combination of the absorption and reduced scattering coefficients, as shown in Eq. (2). μtr=μa+μs′.(2) The diffusion length, D, relates the flux to the fluence rate and is defined as D=13μtr.(3) The penetration depth, δ, is the average distance a photon travels from the point of scattering to the point of absorption, and it is related to the transport and absorption coefficients by δ=13μaμtr.(4) For a collimated incident light beam, the source term q(z) is often approximated as light scattered out of the beam into diffuse light. Here, a distributed source term is implemented, which assumes an exponential decay in intensity with increasing distance from the surface.,, For layer i, this is qi(z)=Φtμs,i′e−μtr,iz′.(5) Here, Φt is the transmitted irradiance, representing the power per unit area of the incident beam that successfully enters the tissue after specular reflection. z′ is the depth into the current layer. The total light field is decoupled into a collimated component and a diffuse component. The distributed source term qi(z) specifically represents the spatial rate at which the collimated incident beam undergoes its initial scattering events and transitions into diffuse, nearly isotropic light. Crucially, Φt represents the initial transmitted irradiance entering the surface of the first layer (z=0). As this collimated beam passes straight down through a multilayered medium, it undergoes exponential decay governed by the cumulative transport coefficients (μtr) and thicknesses of all overlying layers. Every coordinate along this decaying path acts as a local birth site for diffuse photons. Within any given layer, the linear superposition of these isotropic source elements yields a particular mathematical solution that shares the exponential decay profile of the driving collimated beam. When integrated with the boundary-driven diffuse waves that migrate back and forth due to mismatch reflections at internal and physical boundaries, this forms the complete framework of MLDT expanded in Sec. . Generalized Solution for N Layers Although two-layer models have been derived by Spott et al. and Keijzer et al., biological tissues are often more complex. This section expands the diffusion approximation to an arbitrary number of layers, providing a more generalized solution based on multilayer diffusion theory (MLDT). Consider a system with N layers. The first Nfinite layers have finite thicknesses, and the last layer is semi-infinite. Thus, N=Nfinite+1. For each layer k (where k ranges from 0 to N−1), the thicknesses of the finite layers are dk for k from 0 to Nfinite−1. The absolute starting depth of layer k is zk,start. The general solution for the fluence rate φk(z) in layer k (for 0≤k