INR, NeRF and the hash grid¶
Three terms, from the most general to what pySRX runs.
Implicit neural representation (INR)¶
An image is an array of samples. An implicit neural representation stores the signal as a function instead: a network \(f_\theta\) takes a position \(\mathbf{r} = (z, y, x)\) in µm and returns the value there. The array is whatever you get by asking the function on a grid.

One synthetic cell stored two ways. Zoomed in, the explicit grid
is only blocks; the implicit representation, fitted with pySRX's NeuralField, can be
read on any grid. Between the samples it interpolates smoothly: it does not create detail
beyond what it was fitted to.
- No fixed grid. The same field can be read on the reconstruction grid, on a finer one, or at single points. pySRX's digital confocal and virtual pinhole on the light-field page read the field at arbitrary positions.
- Shared parameters. Each weight affects a whole neighbourhood of points, not one voxel. This is the implicit prior from the world-model section: structure that many points share is easy to fit, and isolated noise is hard to fit.
- Spectral bias. A plain MLP fed raw coordinates can only learn smooth functions, so every practical INR first encodes the position: NeRF uses sines and cosines at octave frequencies, Instant-NGP uses a hash grid (below).
NeRF¶
A neural radiance field (NeRF; Mildenhall et al., ECCV 2020) is an INR of a 3D scene, fitted from photographs through a differentiable renderer. For each pixel it marches along a ray, asks the network for density and colour, and compares the rendered pixel with the photo (below).

A neural radiance field (NeRF; Mildenhall et al., ECCV 2020), re-drawn. (1) Each camera pixel looks along one ray, cut into samples; each sample absorbs part of the light and, being fluorescent, also emits. (2) Each point is mapped to sines and cosines at octave frequencies, so a small network can represent fine detail. (3) A network maps the encoded point to a density and a colour: the network is the scene, continuous in space. (4) Rendering compares the predicted pixel with the photo, and the gradient of that loss trains the network. In a fluorescence microscope the picture is simpler: the sample only emits, and the "camera" is the microscope itself, so rendering becomes the forward operator. See the light field and lattice SIM versions.
In fluorescence the sample only emits light, so rendering is linear, and it is exactly the forward operator \(H\). In pySRX, "NeRF" therefore means an INR fitted through the calibrated \(H\) with the Poisson loss: the LF4D NeRF (37 lenslet views) and the Lattice SIM NeRF (13 phases per plane). Neither needs a training set: each fit uses only its own measurement.

The fluorescence version: in LF4D each lenslet is a calibrated camera, whose position in the pupil is the camera pose (parallax) and whose focal group is the lens (defocus blur). With emission only, rendering is the forward projection \(H\).
The multi-resolution hash grid¶
pySRX encodes position with the multi-resolution hash grid of Instant-NGP
(Instant Neural Graphics Primitives with a multiresolution hash encoding; Müller
et al., ACM Trans. Graph. 2022), the fast NeRF variant, in plain PyTorch
(pysrx.field.hashgrid). A grid is a lattice of corner points laid over the
whole volume, like the voxel corners of a 3D image, with learned numbers at the
corners instead of intensities. The field is

and \(\operatorname{enc}\) works in four steps:
- 16 grids, coarse to fine. Level \(l\) divides the largest side of the
volume into \(N_l\) cubic cells, growing geometrically from
n_min= 16 ton_max= 512. For the 360 µm light-field volume that is 22.5 µm cells (the outline of the tissue) down to 0.7 µm cells (one reconstruction pixel, where membranes are). - Learned features at the corners. Every grid corner holds
features= 2 learned numbers. A coarse level has few corners and stores them directly. A level with more corners than its table (\(2^{21}\) = 2 097 152 rows, set bylog2_table) maps corners to rows with a spatial hash, so a few distant corners share a row (a collision). - Interpolate. At a point \(\mathbf{r}\), each level interpolates its 8 surrounding corners trilinearly; the 16 levels give 16 × 2 = 32 numbers.
- Decode. A tiny MLP (2 hidden layers of 64) turns the 32 numbers into the density; softplus keeps it non-negative, and \(s\) sets the scale of the data.
Why it works:
- Coarse levels are smooth. One coarse corner is shared by thousands of voxels, so the coarse levels can only carry broad structure. The fine levels add detail where the data demand it. That is the multi-scale prior.
- Collisions resolve themselves. Colliding corners are usually far apart, and at most one of them sits in bright structure. Its gradient dominates the shared row, and the MLP, which sees all levels at once, separates the rest.
- Fast. Most of the work is table look-ups and interpolation, not matrix multiplication; the network has only about 6 300 weights.
For the light-field volume (360 × 360 µm, about 16 µm thick), only the two finest levels (0.89 and 0.7 µm) are hashed. The tables hold about 15 M numbers, against 31.7 M voxels in the dense grid. The point is not mainly memory: it is the multi-scale prior and a field that can be read anywhere.
What pySRX changes from Instant-NGP:
| Change | Why |
|---|---|
| Positions in µm; cells are cubes in µm, although the volume is anisotropic | the resolution is the same in every direction, in physical units |
The hash is followed by a splitmix64 mix (hash="mix") |
Instant-NGP's xor hash has separable low bits: whole lines collide and show as streaks. Mixed, collisions scatter as single points. hash="ngp" gives the original |
| The field is rendered on the operator's grid, not along rays | \(H\) is a convolution that needs the whole volume. Each step gathers every level's table into a dense corner grid and interpolates with grid_sample |
| A two-pass step | (1) render the volume without gradients, (2) the loss and \(\partial L / \partial x\) through \(H\), (3) re-render plane_chunk planes at a time with gradients and back-propagate into the tables and the MLP. The full autograd graph is never held in memory |
| A warm start | the field is first distilled from a short Richardson-Lucy result on random batches of points (init_rl, distill_steps), then fitted to the data |
| Optional coarse-to-fine | coarse_to_fine switches the fine levels on gradually; lam_tv and lam_l1 add a small TV or sparsity term |
The settings are in InrConfig:
| Setting | Default | Meaning |
|---|---|---|
levels, features |
16, 2 | grids, and learned numbers per corner |
n_min, n_max |
16, 512 | cells across the largest side, coarsest and finest level |
log2_table |
21 | rows per hashed table: \(2^{21}\) |
hidden, layers |
64, 2 | the MLP |
steps, lr, lr_mlp |
600, 0.01, 0.002 | Adam steps and learning rates (tables, MLP) |
plane_chunk, z_chunk |
16, 8 | memory: planes per chunk (Run on a GPU) |
Because n_max counts cells across the largest side, the finest cell depends on
the volume: 0.7 µm for the 360 µm light field, 16 nm for an 8 µm lattice SIM
crop. Choose n_max so the finest cell is at or below the reconstruction pixel.