Skip to content

Fix registration worker OOM on large images#126

Draft
arjunrajlab wants to merge 2 commits intomasterfrom
fix-registration-oom
Draft

Fix registration worker OOM on large images#126
arjunrajlab wants to merge 2 commits intomasterfrom
fix-registration-oom

Conversation

@arjunrajlab
Copy link
Collaborator

Summary

  • Auto-crops to center 2048x2048 region for registration matrix computation when no reference region is specified and the image exceeds 2048px (with a warning to the user)
  • Replaces pystackreg's sr.transform() (float64) with a scipy.ndimage.affine_transform-based helper using float32 in the output loop, cutting peak memory ~in half
  • Adds explicit garbage collection after each frame in the output loop

Context

The registration worker crashes with exit code 137 (OOM kill) when processing large images (e.g., 12089x12089 with 7 channels and 2 timepoints). pystackreg's StackReg.transform() internally converts to float64, creating ~2.9 GB temporary arrays per frame.

Test plan

  • All 23 existing + 3 new unit tests pass (./build_workers.sh --build-and-run-tests registration)
  • Test on the 12089x12089 image that was causing the OOM crash
  • Test with a user-specified reference region tag (should skip auto-crop)
  • Test on a small image (should skip auto-crop, no warning)

🤖 Generated with Claude Code

arjunrajlab and others added 2 commits February 6, 2026 08:04
Two-part fix for memory exhaustion when processing large images:
1. Auto-crop to center 2048x2048 for registration matrix computation
   when no reference region is specified and the image is large
2. Use scipy.ndimage.affine_transform with float32 in the output loop
   instead of pystackreg's sr.transform which internally uses float64,
   cutting peak memory roughly in half

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Covers how the worker operates, interface parameters, implementation
details (auto-crop, memory-efficient transform, control points),
full test inventory, lessons learned from OOM debugging, and future TODOs.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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