From 20c05aff63c7e5a39ada8cda6627e89e70a4cd4d Mon Sep 17 00:00:00 2001 From: Ye Han Date: Tue, 19 Nov 2024 15:20:41 -0500 Subject: [PATCH] ENH: Transform to altas space for better mesh splitting --- oai_analysis/mesh_processing.py | 10 ++-------- oai_analysis/pipeline.py | 26 ++++++++++++++++++++------ 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/oai_analysis/mesh_processing.py b/oai_analysis/mesh_processing.py index ba74931..25c9367 100644 --- a/oai_analysis/mesh_processing.py +++ b/oai_analysis/mesh_processing.py @@ -401,16 +401,12 @@ def split_mesh(mesh, mesh_type="FC"): # Obtain the thickness of the input itk_image by creating a mesh and splitting it. -def get_thickness_mesh(itk_image, mesh_type="FC", num_iterations=150): +def get_split_mesh(vtk_mesh, mesh_type="FC", num_iterations=150): """ Takes the probability map obtained from the segmentation algorithm as an itk image. Constructs a VTK mesh from it and returns the thickness between the inner and outer splitted mesh. Takes as argument the type of mesh 'FC' or 'TC'. """ - # Get mesh from itk image - itk_mesh = get_mesh_from_probability_map(itk_image) - vtk_mesh = itk_mesh_to_vtk_mesh(itk_mesh) - # Keep the largest 1 (FC) or 2 (TC) regions connect = vtk.vtkPolyDataConnectivityFilter() connect.SetInputData(vtk_mesh) @@ -431,9 +427,7 @@ def get_thickness_mesh(itk_image, mesh_type="FC", num_iterations=150): # Split the mesh into inner and outer inner_mesh, outer_mesh = split_mesh(mesh, mesh_type) - # Get the distance between inner and outer mesh - distance_inner, distance_outer = get_distance(inner_mesh, outer_mesh) - return distance_inner, distance_outer + return inner_mesh, outer_mesh # Map the attributes from the source mesh to target mesh (atlas mesh) diff --git a/oai_analysis/pipeline.py b/oai_analysis/pipeline.py index 2e1f152..4827bdb 100644 --- a/oai_analysis/pipeline.py +++ b/oai_analysis/pipeline.py @@ -140,20 +140,34 @@ def analysis_pipeline(input_path, output_path, laterality, keep_intermediate_out itk.transformwrite(phi_AB, os.path.join(output_path, "resampling.tfm")) itk.transformwrite(phi_BA, os.path.join(output_path, "modelling.tfm")) + print("Computing the thickness map") + # Get mesh from itk image + fc_mesh_itk = mp.get_mesh_from_probability_map(FC_prob) + tc_mesh_itk = mp.get_mesh_from_probability_map(TC_prob) + fc_mesh = mp.itk_mesh_to_vtk_mesh(fc_mesh_itk) + tc_mesh = mp.itk_mesh_to_vtk_mesh(tc_mesh_itk) + thickness_via_mesh_splitting = True if thickness_via_mesh_splitting: print("Computing the thickness map via mesh splitting into inner and outer") - fc_inner, fc_mesh = mp.get_thickness_mesh(FC_prob, mesh_type='FC') - tc_inner, tc_mesh = mp.get_thickness_mesh(TC_prob, mesh_type='TC') + # Transform to atlas space for splitting + fc_mesh_atlas = transform_mesh(fc_mesh, phi_BA, output_path + "/FC_mesh", False) + tc_mesh_atlas = transform_mesh(tc_mesh, phi_BA, output_path + "/TC_mesh", False) + fc_inner_atlas, fc_outer_atlas = mp.get_split_mesh(fc_mesh_atlas, mesh_type='FC') + tc_inner_atlas, tc_outer_atlas = mp.get_split_mesh(tc_mesh_atlas, mesh_type='TC') + + # Transform back to patient space for distance measuring + fc_inner_patient = transform_mesh(fc_inner_atlas, phi_AB, output_path + "/FC_mesh", False) + fc_outer_patient = transform_mesh(fc_outer_atlas, phi_AB, output_path + "/FC_mesh", False) + tc_inner_patient = transform_mesh(tc_inner_atlas, phi_AB, output_path + "/TC_mesh", False) + tc_outer_patient = transform_mesh(tc_outer_atlas, phi_AB, output_path + "/TC_mesh", False) + fc_inner, fc_mesh = mp.get_distance(fc_inner_patient, fc_outer_patient) + tc_inner, tc_mesh = mp.get_distance(tc_inner_patient, tc_outer_patient) if keep_intermediate_outputs: write_vtk_mesh(fc_inner, output_path + "/FC_inner.vtk") write_vtk_mesh(tc_inner, output_path + "/TC_inner.vtk") else: print("Computing the thickness map via distance transformation from mask edges") - fc_mesh_itk = mp.get_mesh_from_probability_map(FC_prob) - tc_mesh_itk = mp.get_mesh_from_probability_map(TC_prob) - fc_mesh = mp.itk_mesh_to_vtk_mesh(fc_mesh_itk) - tc_mesh = mp.itk_mesh_to_vtk_mesh(tc_mesh_itk) fc_thickness_image, fc_distance, fc_mask = compute_thickness(FC_prob) tc_thickness_image, tc_distance, tc_mask = compute_thickness(TC_prob) fc_mesh = sample_distance_from_image(fc_thickness_image, fc_mesh)