Skip to content

fix(models): scale z padding by the axial upsampling factor in 3D transfer functions - #608

Open
arashmparsa wants to merge 2 commits into
Biohub:mainfrom
arashmparsa:fix/z-padding-upsampled-grid
Open

arashmparsa wants to merge 2 commits into
Biohub:mainfrom
arashmparsa:fix/z-padding-upsampled-grid

Conversation

@arashmparsa

Copy link
Copy Markdown

waveorder's phase_thick_3d and isotropic_fluorescent_thick_3d build their transfer function on a z grid upsampled to axial Nyquist by z_factor, then crop it to Z + 2 * z_padding slices. The padding reached the upsampled grid unscaled, so with z_factor = 2 the transfer function was sampled at the wrong axial frequencies. Padding should not change the PSF, but on main it does:

kw = dict(zyx_shape=(48, 64, 64), yx_pixel_size=0.15, z_pixel_size=1.0,
          wavelength_emission=0.532, index_of_refraction_media=1.3,
          numerical_aperture_detection=0.8)
# axial PSF at +-1 um, relative to its peak
# z_padding = 0, 8, 16, 24 -> 0.369, 0.473, 0.539, 0.584 on main

The change passes z_padding * z_factor to the upsampled grid, one line per model; with z_factor = 1 nothing changes. A second commit makes apply_transfer_function zero-pad the object instead of slicing the unshifted OTF, which dropped the DC term so simulated stacks summed to zero. The new tests fail on main and pass here, and pytest tests/models passes. Results with z_padding > 0 on coarse z stacks will change. Heads-up: draft #597 keeps the old padding in Sampling.upsampled().

Related issue

Summary

Testing

Checklist

  • I added or updated tests, or this change does not require tests.
  • I updated the documentation, or this change does not require documentation.
  • I confirmed this change does not include confidential or sensitive information.

…nsfer functions

calculate_transfer_function in phase_thick_3d and
isotropic_fluorescent_thick_3d computes the transfer function on a grid
upsampled to axial Nyquist (z_factor) and then crops it in Fourier space
to zyx_shape[0] + 2 * z_padding slices. The padding was passed to the
upsampled grid unscaled, so that grid spanned (Z + 2 * z_padding /
z_factor) * z_pixel_size instead of (Z + 2 * z_padding) * z_pixel_size,
and the cropped transfer function was sampled on the wrong axial
frequencies whenever z_padding > 0 and z_pixel_size is coarser than
axial Nyquist.

Pass z_padding * z_factor to the upsampled grid. Add tests that the
axial response does not change with z padding when z is upsampled.
…transfer_function

isotropic_fluorescent_thick_3d.apply_transfer_function (also used by
phase_thick_3d.apply_transfer_function) handled z_padding > 0 by
slicing optical_transfer_function[z_padding:-z_padding]. The OTF is in
unshifted FFT order, so that slice removes the DC term and the lowest
axial frequencies: the simulated stack sums to zero and keeps only
high-frequency content.

Zero-pad the object to the OTF's padded grid, apply the OTF, and crop
the simulated data back to the object's shape.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant