Skip to content

Commit 64d157c

Browse files
Merge pull request #190 from AllenNeuralDynamics/seanf-fusion/multiscale
Fixed translation fusion collision bug
2 parents b025053 + 957cc0b commit 64d157c

4 files changed

Lines changed: 27 additions & 27 deletions

File tree

Rhapso/pipelines/ray/aws/fusion_pipeline.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"from Rhapso.pipelines.ray.multiscale import MultiScale\n"
3636
f"cfg = json.loads(base64.b64decode(\\\"{serialized_config}\\\").decode())\n"
3737
"ms = MultiScale(\n"
38+
" xml_path=cfg[\\\"xml_path_multiscale\\\"],\n"
3839
" zarr_path=cfg[\\\"multiscale_zarr_path\\\"],\n"
3940
" chunk_size=cfg[\\\"multiscale_chunk_size\\\"],\n"
4041
" n_lvls=cfg[\\\"n_lvls\\\"],\n"

Rhapso/pipelines/ray/local/fusion_pipeline.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import yaml
44

55
# Point to param file
6-
with open("Rhapso/pipelines/ray/param/fusion/HCR_000000-s40.yml", "r") as file:
6+
with open("Rhapso/pipelines/ray/param/fusion/HCR_823476.yml", "r") as file:
77
config = yaml.safe_load(file)
88

99
# FUSION
@@ -28,5 +28,5 @@
2828
)
2929

3030
# Run pipeline
31-
fusion.execute_job()
31+
# fusion.execute_job()
3232
multiscale.run()

Rhapso/pipelines/ray/param/fusion/HCR_823476.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
# AFFINE FUSION
22
# -----------------------------------
3-
xml_path_translation_fusion: "s3://aind-open-data/HCR_823476-s1-ls2_2025-11-18_00-00-00_processed_2026-02-25_18-17-21/image_tile_alignment/bigstitcher.xml"
4-
input_path_translation_fusion: "s3://aind-open-data/HCR_823476-s1-ls2_2025-11-18_00-00-00_processed_2026-02-25_18-17-21/image_radial_correction/"
5-
output_s3_path_translation_fusion: "s3://aind-scratch-data/sean.fite/HCR_823476_s5_11-18-t1/fusion/fused.zarr"
3+
xml_path_translation_fusion: "s3://aind-open-data/HCR_823476-s1-ls2_2025-11-18_00-00-00_processed_2026-03-03_22-58-55/image_tile_alignment/bigstitcher.xml"
4+
input_path_translation_fusion: "s3://aind-open-data/HCR_823476-s1-ls2_2025-11-18_00-00-00_processed_2026-03-03_22-58-55/image_radial_correction/"
5+
output_s3_path_translation_fusion: "s3://aind-scratch-data/sean.fite/HCR_823476-11-18-t1/fusion/fused.zarr"
66
channel: 488
77
default_chunk_size: [1, 1, 128, 128, 128]
8-
cpu_cell_size: [256, 256, 256]
8+
cpu_cell_size: [640, 256, 256]
99

1010
# MULTISCALE
1111
# -----------------------------------
12-
multiscale_zarr_path: "s3://aind-scratch-data/sean.fite/HCR_823476_s5_12-24/channel_488.zarr/multiscale_fused"
12+
xml_path_multiscale: "s3://aind-open-data/HCR_823476-s1-ls2_2025-11-18_00-00-00_processed_2026-03-03_22-58-55/image_tile_alignment/bigstitcher.xml"
13+
multiscale_zarr_path: "s3://aind-scratch-data/sean.fite/HCR_823476-11-18-t1/fusion/fused.zarr"
1314
multiscale_chunk_size: [128, 128, 128]
1415
n_lvls: 6 # Including base level
1516
scale_factor: [[1, 2, 2], [1, 2, 2], [2, 2, 2], [2, 2, 2], [2, 2, 2]] # ZYX

Rhapso/translation_fusion/fusion.py

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ def cpu_fusion(
546546

547547
total = time.perf_counter() - t_total0
548548
# print(f"[cpu_fusion] pid={os.getpid()} DONE blend={t_blend:.3f}s write={t_write:.3f}s total={total:.3f}s", flush=True)
549-
549+
550550
class FusionVolumeSampler(cq.VolumeSampler):
551551
def __init__(
552552
self,
@@ -622,8 +622,8 @@ def __init__(
622622
for t_id, o_ids in tile_to_overlap_ids.items():
623623
# This is the base nullspace
624624
t_aabb = list(self.tile_aabbs[t_id])
625-
# t_aabb[0] = 0
626-
# t_aabb[1] = output_volume_size[0]
625+
t_aabb[0] = 0
626+
t_aabb[1] = output_volume_size[0]
627627

628628
for o_id in o_ids:
629629
o_aabb = modified_overlaps[o_id]
@@ -696,36 +696,34 @@ def __init__(
696696

697697
def _check_true_collision(
698698
self,
699-
cell_box: geometry.AABB,
700-
transform_list: list[geometry.Transform],
699+
cell_box: "geometry.AABB",
700+
transform_list: list["geometry.Transform"],
701701
src_vol_shape_zyx: tuple[int, int, int],
702702
) -> bool:
703-
# Build the 8 corners (zyx) with +/-0.5 offsets
704703
z_min, z_max, y_min, y_max, x_min, x_max = cell_box
704+
705+
# sample at voxel centers: (min+0.5, max-0.5) on each axis
705706
zs = np.array([z_min + 0.5, z_max - 0.5], dtype=np.float32)
706707
ys = np.array([y_min + 0.5, y_max - 0.5], dtype=np.float32)
707708
xs = np.array([x_min + 0.5, x_max - 0.5], dtype=np.float32)
708709

709-
cell_box_pts = np.array(
710-
[[z, y, x] for z in zs for y in ys for x in xs],
711-
dtype=np.float32
712-
) # (8, 3)
710+
# 2x2x2 grid of corners, shape (2,2,2,3) in ZYX order
711+
z_grid, y_grid, x_grid = np.meshgrid(zs, ys, xs, indexing="ij")
712+
cell_box_pts = np.stack([z_grid, y_grid, x_grid], axis=-1).astype(np.float32)
713713

714-
# Apply origin
715-
cell_box_pts += np.asarray(self.output_volume_origin, dtype=np.float32).reshape(1, 3)
714+
# move into output/global space
715+
cell_box_pts = cell_box_pts + np.asarray(self.output_volume_origin, dtype=np.float32)
716716

717-
# Apply inverse transforms (NumPy)
717+
# apply inverse transforms in reverse order
718718
for tfm in reversed(transform_list):
719+
# assumes tfm.backward can accept numpy arrays; if not, see note below
719720
cell_box_pts = tfm.backward_np(cell_box_pts)
720721

721-
# AABB of transformed points (zyx)
722-
z0, z1 = float(cell_box_pts[:, 0].min()), float(cell_box_pts[:, 0].max())
723-
y0, y1 = float(cell_box_pts[:, 1].min()), float(cell_box_pts[:, 1].max())
724-
x0, x1 = float(cell_box_pts[:, 2].min()), float(cell_box_pts[:, 2].max())
725-
cell_box_src: geometry.AABB = (z0, z1, y0, y1, x0, x1)
722+
# compute AABB in source space
723+
cell_box_src: "geometry.AABB" = geometry.aabb_3d_np(cell_box_pts)
726724

727725
sv_z, sv_y, sv_x = src_vol_shape_zyx
728-
aabb_src: geometry.AABB = (0, sv_z, 0, sv_y, 0, sv_x)
726+
aabb_src: "geometry.AABB" = (0, sv_z, 0, sv_y, 0, sv_x)
729727

730728
return utils.check_collision(cell_box_src, aabb_src)
731729

@@ -788,4 +786,4 @@ def __iter__(self):
788786
stride_condition = (cell_num % self.stride == self.start)
789787

790788
if true_overlap_condition and stride_condition:
791-
yield curr_cell, src_ids
789+
yield curr_cell, src_ids

0 commit comments

Comments
 (0)