def run(input_directories: list,
        output_path: str,
        segment_type: list,
        open_viewer=True):
    flair_input_path = input_directories[0]
    t1_input_path = input_directories[1]
    ir_input_path = input_directories[2]

    logging.info("Starting brain pipeline")
    flair_array = read_input_path_as_np_array(flair_input_path)
    t1_array = read_input_path_as_np_array(t1_input_path)
    ir_array = read_input_path_as_np_array(ir_input_path)
    segmented_array = brain_model.predict(flair_array, t1_array, ir_array)

    meshes = [
        generate_mesh(segment, 0)
        for segment in seperate_segmentation(segmented_array,
                                             unique_values=segment_type)
    ]

    if open_viewer:
        meshes = convert_meshes_trimesh(meshes)
        segment_dict = get_seg_types(this_plid)
        mesh_names = [k for k, v in segment_dict.items() if v in segment_type]
        view_mesh(
            meshes=meshes,
            mesh_names=mesh_names,
            output_file=output_path,
            plid=this_plid,
        )
    else:
        write_mesh_as_glb_with_colour(meshes, output_path)
    logging.info("Brain pipeline finished successfully")
Exemplo n.º 2
0
def run(input_path: str,
        output_path: str,
        segment_type: list,
        open_viewer=True) -> None:
    logging.info("Starting abdominal pipeline")
    image_array = read_input_path_as_np_array(input_path)
    image_array = downscale_and_conditionally_crop(image_array)
    # NOTE: Numpy array is flipped in the Y axis here as this is the specific image input for the NiftyNet model
    image_array = flip_numpy_array_dimensions_y_only(image_array)

    nifti_image = convert_np_ndarray_to_nifti_image(image_array)
    initial_nifti_output_file_path = abdominal_model.get_input_path()
    write_nifti_image(nifti_image, initial_nifti_output_file_path)
    segmented_nifti_output_file_path = abdominal_model.predict()

    segmented_array = read_nifti_as_np_array(segmented_nifti_output_file_path,
                                             normalise=False)

    meshes = [
        generate_mesh(segment, 0)
        for segment in seperate_segmentation(segmented_array,
                                             unique_values=segment_type)
    ]

    if open_viewer:
        metadata = get_metadata(input_path)
        meshes = convert_meshes_trimesh(meshes)
        segment_dict = get_seg_types(this_plid)
        mesh_names = [k for k, v in segment_dict.items() if v in segment_type]
        view_mesh(
            meshes=meshes,
            mesh_names=mesh_names,
            output_file=output_path,
            patient_data=metadata,
            plid=this_plid,
            scan_path=input_path,
        )
    else:
        write_mesh_as_glb_with_colour(meshes, output_path)

    abdominal_model.cleanup()
    logging.info("Abdominal pipeline finished successfully")
Exemplo n.º 3
0
def run(
    input_path: str, output_path: str, segment_type: list, open_viewer=True
) -> None:
    logging.info("Starting kidney pipeline")
    image = read_nifti_image(input_path)
    initial_nifti_output_file_path = kidney_model.get_input_path()
    write_nifti_image(image, initial_nifti_output_file_path)
    segmented_nifti_output_file_path = kidney_model.predict()

    segmented_array = read_nifti_as_np_array(
        segmented_nifti_output_file_path, normalise=False
    )

    meshes = [
        generate_mesh(segment, 0)
        for segment in seperate_segmentation(
            segmented_array, unique_values=segment_type
        )
    ]

    if open_viewer:
        metadata = get_metadata(input_path)
        meshes = convert_meshes_trimesh(meshes)
        segment_dict = get_seg_types(this_plid)
        mesh_names = [k for k, v in segment_dict.items() if v in segment_type]
        view_mesh(
            meshes=meshes,
            mesh_names=mesh_names,
            output_file=output_path,
            patient_data=metadata,
            plid=this_plid,
            scan_path=input_path,
        )
    else:
        write_mesh_as_glb_with_colour(meshes, output_path)

    kidney_model.cleanup()
    logging.info("Kidney pipeline finished successfully")
def run(input_path: str,
        output_path: str,
        segment_type: list,
        open_viewer=True) -> None:
    logging.info("Starting bone pipeline")
    image_data = read_input_path_as_np_array(input_path)
    image_data = downscale_and_conditionally_crop(image_data)
    meshes = [generate_mesh(image_data, bone_hu_threshold)]
    if open_viewer:
        metadata = get_metadata(input_path)
        meshes = convert_meshes_trimesh(meshes)
        segment_dict = get_seg_types(this_plid)
        mesh_names = [k for k, v in segment_dict.items() if v in segment_type]
        view_mesh(
            meshes=meshes,
            mesh_names=mesh_names,
            output_file=output_path,
            patient_data=metadata,
            plid=this_plid,
            scan_path=input_path,
        )
    else:
        write_mesh_as_glb_with_colour(meshes, output_path)
    logging.info("Bone pipeline finished successfully")
def run(input_path: str,
        output_path: str,
        segment_type: list,
        open_viewer=True) -> None:
    logging.info("Starting lung pipeline")
    image_data = read_input_path_as_np_array(input_path)
    image_data = downscale_and_conditionally_crop(image_data)
    segmented_lung, segmented_airway = perform_lung_segmentation(image_data)

    meshes = []
    if 1 in segment_type:  # lung segmentation
        meshes.append(generate_mesh(segmented_lung, hu_threshold))
    if 2 in segment_type:  # airway segmentation
        meshes.append(generate_mesh(segmented_airway, hu_threshold))

    if len(meshes) == 0:
        raise Exception(
            "No valid segmentation specified, segmentation type must be either 1 or 2"
        )

    if open_viewer:
        metadata = get_metadata(input_path)
        meshes = convert_meshes_trimesh(meshes)
        segment_dict = get_seg_types(this_plid)
        mesh_names = [k for k, v in segment_dict.items() if v in segment_type]
        view_mesh(
            meshes=meshes,
            mesh_names=mesh_names,
            output_file=output_path,
            patient_data=metadata,
            plid=this_plid,
            scan_path=input_path,
        )
    else:
        write_mesh_as_glb_with_colour(meshes, output_path)
    logging.info("Lung pipeline finished successfully")