Skip to content

Rendering realism fixes - #12

Draft
marktsuchida wants to merge 3 commits into
mainfrom
rendering-realism
Draft

marktsuchida wants to merge 3 commits into
mainfrom
rendering-realism

Conversation

@marktsuchida

@marktsuchida marktsuchida commented Sep 25, 2026 •

Copy link
Copy Markdown
Owner
  • Blur when at or near focus was artificially large; use a more realistic formula.
  • Filaments were drawn at the same pixel width in all mags, which scaled intensity incorrectly. Set them to be 25 nm (microtubules) but handle the case where they would vanish in our 8-bit rendering by scaling intensity.
  • Set default objective to 20x because filaments are not visible at 100 ms exposure at 10x (which might well be a realistic effect).

I'm not going to merge these right now because (1) they need further thought and review and (2) the changes may throw off @gselzer's data-driven acquisition example for our I2K/BINA2026 workshop.

- q() now returns F instead of float.
- ForwardFilter / BackwardFilter are rewritten with index loops, so they
  no longer create pointers outside the array. The existing tests for
  them, including the nullptr, 0 cases, pass unchanged.
- DirectGaussian2D is new in gaussian_internal. It blurs rows then
  columns with a sampled Gaussian kernel that reaches out to max(1,
  ceil(3σ)) and is scaled to sum to 1. Edge pixels are repeated at the
  borders, and a single line buffer is reused.
- FastGaussian2D:
  - It returns early unless sigma > 0.
  - It uses DirectGaussian2D when sigma < 1, with a rationale comment.
  - Otherwise it goes to SIMD or scalar, now using #else.
- New tests:
  - DirectGaussian2D at σ=0.7: a single-pixel spike blurs to a total of
    ≈1, the result is mirror- and diagonal-symmetric, the center value
    equals w0², and a constant image stays constant.
  - FastGaussian2D-small-sigma for σ ∈ {0.1, 0.3, 0.7}: no negative
    values, a total of ≈1, and a constant image stays constant.

(Assisted by Claude Code; any errors are mine.)
Blur when (close to) in focus; magnification-dependent filament
thickness/brightness.

- Image readback: rows are now addressed with the byte stride, which
  works whichever direction Blend2D stores the image. The image is
  created with img.create(...), and if that fails the signal is filled
  with zeros.
- Blur now depends on NA: GaussianSigmaForDefocus takes the emission
  wavelength. The in-focus width is 0.21 λ / NA and the defocus width is
  0.5 · NA · |dz| / n; the two combine as a root sum of squares. There's
  a new EMISSION_WAVELENGTH_UM = 0.52f constant.
- Filament width: filaments are 0.025 µm wide. They're drawn at least 1
  px wide, with intensity scaled down by filamentWidthUm_ / strokeWidth.
  The origin marker gets the same intensity scaling.
- relativeBrightness_ manually set to be reasonable-ish.

(Assisted by Claude Code; any errors are mine.)
With the current filament intensity, filaments aren't visible at 10x
under default settings.

(Assisted by Claude Code; any errors are mine.)
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