Crop fully black borders after Z alignment#23
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 36070a7d7b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
|
||
| for z0 in range(0, z_max, chunk_z): | ||
| z1 = min(z0 + chunk_z, z_max) | ||
| block = mask_store[z0:z1].read().result() |
There was a problem hiding this comment.
Limit mask reads to smaller tiles
With the default destination canvas created as root_offset + pad_offset + [10000, 10000], this read materializes up to 64 full YX mask slices at once, and the following np.nonzero allocates index arrays for every true voxel. On a typical 10k x 10k aligned stack this is already more than 6 GB before the index arrays, so the new default crop can OOM after a long alignment finishes; scan one/few slices or YX tiles instead.
Useful? React with 👍 / 👎.
|
|
||
| if crop_black_borders: | ||
| logging.info('Cropping fully black borders from aligned stack...') | ||
| crop_aligned_stack_borders(destination_path, save_downsampled, project_name) |
There was a problem hiding this comment.
Account for cropped outputs before rerendering
Because the crop runs by default for the same destination that later resumable runs open, a subsequent align_dataset_z --wipe-progress <stack> without --start-over reuses the original config offsets in execute_alignment/align_stack_z against an already-cropped store. Those writes are still in the uncropped canvas coordinate system, so the rerendered stack is shifted by the crop amount and may expand the store back out with black borders; either adjust offsets by crop_bbox_yx or require --start-over/no-crop for rerenders.
Useful? React with 👍 / 👎.
Motivation
root_offset + pad_offset + [10000,10000]) which produces permanent black borders across many slices when stacks drift.Description
._mask_union_bbox,._copy_cropped_store, andcrop_aligned_stack_bordershelpers toemalign/align_dataset_z.pyto compute the union bbox of the mask over Z, create cropped temporary stores, and atomically replace the output with the cropped versions.voxel_offset,offset,uncropped_shape, andcrop_bbox_yx.align_dataset_zand added a CLI flag--no-crop-black-bordersto preserve the previous behavior..crop_tmpstores and atomicos.replaceto avoid leaving partial outputs on failure.Testing
python -m py_compile emalign/align_dataset_z.pywhich succeeded.python -m compileall emalign/align_dataset_z.pywhich succeeded.cv2failed due to a missinglibGL.so.1(test therefore could not complete in this environment).Codex Task