Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/register_config_test_elastic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ coherent_point_drift:

ILP:
min_neighbours: 10
max_dist: 30
max_dist: 15

mobie_export: False
mobie_export: True
semantic_seg: True
mobie_dataset_name: "platy1_muscles_stardist"
59 changes: 45 additions & 14 deletions matchmaker/cpd_nonrigid_registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,67 @@
get_attrs
)


from matchmaker.utils import overlay_pcds, visualize_displacement_field, extract_centroids, run_cpd, create_pcd



def cpd_from_images(fixed_img, fixed_resolution, moving_img, moving_resolution, output_dir, w, beta, lmd, maxiter):
fixed_labels, fixed_center_coords = extract_centroids(fixed_img, fixed_resolution)
moving_labels, moving_center_coord = extract_centroids(moving_img, moving_resolution)

fixed_pcd = create_pcd(fixed_center_coords, fixed_labels)
moving_pcd = create_pcd(moving_center_coord, moving_labels)

overlay_pcds(fixed_pcd, moving_pcd, projection="xz", save_path = output_dir / "pcds_before_registration_xz.png")
overlay_pcds(fixed_pcd, moving_pcd, projection="yz", save_path = output_dir / "pcds_before_registration_yz.png")
overlay_pcds(fixed_pcd, moving_pcd, projection="xy", save_path = output_dir / "pcds_before_registration_xy.png")
overlay_pcds(fixed_pcd, moving_pcd, projection="xz", save_path=output_dir / "plots/pcds_before_registration_xz.png")
overlay_pcds(fixed_pcd, moving_pcd, projection="yz", save_path=output_dir / "plots/pcds_before_registration_yz.png")
overlay_pcds(fixed_pcd, moving_pcd, projection="xy", save_path=output_dir / "plots/pcds_before_registration_xy.png")

logging.info(f"Point cloud registration with parameters w={w}, beta={beta}, lmd={lmd}, maxiter={maxiter}")

registered_pcd = run_cpd(fixed_pcd, moving_pcd, w, beta, lmd, maxiter)

overlay_pcds(fixed_pcd, registered_pcd, projection="xz", save_path = output_dir / "pcds_after_registration_xz.png")
overlay_pcds(fixed_pcd, registered_pcd, projection="yz", save_path = output_dir / "pcds_after_registration_yz.png")
overlay_pcds(fixed_pcd, registered_pcd, projection="xy", save_path = output_dir / "pcds_after_registration_xy.png")
overlay_pcds(
fixed_pcd,
registered_pcd,
projection="xz",
save_path=output_dir / "plots/pcds_after_registration_xz.png",
)
overlay_pcds(
fixed_pcd,
registered_pcd,
projection="yz",
save_path=output_dir / "plots/pcds_after_registration_yz.png",
)
overlay_pcds(
fixed_pcd,
registered_pcd,
projection="xy",
save_path=output_dir / "plots/pcds_after_registration_xy.png",
)

visualize_displacement_field(moving_pcd, registered_pcd, projection="xz", save_path = output_dir / "displacement_field_xz.png")
visualize_displacement_field(moving_pcd, registered_pcd, projection="yz", save_path = output_dir / "displacement_field_yz.png")
visualize_displacement_field(moving_pcd, registered_pcd, projection="xy", save_path = output_dir / "displacement_field_xy.png")
visualize_displacement_field(
moving_pcd,
registered_pcd,
projection="xz",
save_path=output_dir / "plots/displacement_field_xz.png",
)
visualize_displacement_field(
moving_pcd,
registered_pcd,
projection="xz",
save_path=output_dir / "plots/displacement_field_xz.pdf",
)
visualize_displacement_field(
moving_pcd,
registered_pcd,
projection="yz",
save_path=output_dir / "plots/displacement_field_yz.png",
)
visualize_displacement_field(
moving_pcd,
registered_pcd,
projection="xy",
save_path=output_dir / "plots/displacement_field_xy.png",
)

o3d.t.io.write_point_cloud(str(output_dir / "fixed_pcd.pcd"), fixed_pcd, write_ascii=True)
o3d.t.io.write_point_cloud(str(output_dir / "moving_pcd.pcd"), moving_pcd, write_ascii=True)
Expand Down Expand Up @@ -90,8 +124,5 @@ def main(fixed_path, fixed_key, moving_path, moving_key, output_dir, w, beta, lm
)





if __name__ == "__main__":
main()
16 changes: 6 additions & 10 deletions matchmaker/match_pointclouds.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
from matchmaker.utils import sparse_ilp_matching, write_index_pairs, plot_matching_qc




def match_points(fixed_pcd, registered_pcd, output_dir, max_dist, min_neighbours):

logging.info(f"Number of points in fixed pcd: {len(fixed_pcd.point.positions)}")
Expand Down Expand Up @@ -44,16 +42,14 @@ def match_points(fixed_pcd, registered_pcd, output_dir, max_dist, min_neighbours
]

if swap_order:
plot_matching_qc(pos_2, pos_1, output_dir / "point_matching_xz.png", pairs=matched_idx_pairs, projection="xz")
plot_matching_qc(pos_2, pos_1, output_dir / "point_matching_yz.png", pairs=matched_idx_pairs, projection="yz")
plot_matching_qc(pos_2, pos_1, output_dir / "point_matching_xy.png", pairs=matched_idx_pairs, projection="xy")
plot_matching_qc(pos_2, pos_1, output_dir / "plots/point_matching_xz.png", pairs=matched_idx_pairs, projection="xz")
plot_matching_qc(pos_2, pos_1, output_dir / "plots/point_matching_yz.png", pairs=matched_idx_pairs, projection="yz")
plot_matching_qc(pos_2, pos_1, output_dir / "plots/point_matching_xy.png", pairs=matched_idx_pairs, projection="xy")

else:
plot_matching_qc(pos_1, pos_2, output_dir / "point_matching_xz.png", pairs=matched_idx_pairs, projection="xz")
plot_matching_qc(pos_1, pos_2, output_dir / "point_matching_yz.png", pairs=matched_idx_pairs, projection="yz")
plot_matching_qc(pos_1, pos_2, output_dir / "point_matching_xy.png", pairs=matched_idx_pairs, projection="xy")


plot_matching_qc(pos_1, pos_2, output_dir / "plots/point_matching_xz.png", pairs=matched_idx_pairs, projection="xz")
plot_matching_qc(pos_1, pos_2, output_dir / "plots/point_matching_yz.png", pairs=matched_idx_pairs, projection="yz")
plot_matching_qc(pos_1, pos_2, output_dir / "plots/point_matching_xy.png", pairs=matched_idx_pairs, projection="xy")

return matched_idx_pairs, matched_label_pairs

Expand Down
Loading