lama/snake_contour_tool/label_fixer.py
def fix_label(rigid_img_path, inverted_labels_path, label_of_interest, kmean, num_iterations, prop_scaling):
    """Uses the active contour tool to automatically segment a poorly inverted label to a cluster image"""

    rigid, r_head = nrrd.read(rigid_img_path)
    inv_labels, inv_head = nrrd.read(inverted_labels_path)

    # # Get the bounding box of the inverted label - # Kyle - you don't need an ROI to fix the segmentation.
    #                                               # just get the label of interest
    single_label, _ = nrrd.read(inverted_labels_path)
    single_label[single_label != label_of_interest] = 0

    # Perform the snake contouring to get a corrected label
    rigid_img = sitk.GetImageFromArray(rigid)
    out_arr = cluster(rigid_img, kmean)

    corrected_label = geodesic_active_segmentation.snake(single_label, out_arr, label_of_interest, num_iterations,
                                                         prop_scaling)

    # Replace the old label with the corrected label
    corrected_array = sitk.GetArrayFromImage(corrected_label)

    # set over-labelled vals in original label to 0
    overlabelled_vals = np.logical_and(inv_labels == label_of_interest, corrected_array != 1)
    inv_labels[overlabelled_vals == True] = 0

    # set non-labelled values to the label of interest and write the file
    inv_labels[corrected_array == 1] = label_of_interest
    nrrd.write(str(inverted_labels_path), inv_labels, header=inv_head)
Uses the active contour tool to automatically segment a poorly inverted label to a cluster image
Uses the active contour tool to automatically segment a poorly inverted label to a cluster image
Uses the active contour tool to automatically segment a poorly inverted label to a cluster image
def fix_label(rigid_img_path, inverted_labels_path, label_of_interest, kmean, num_iterations, prop_scaling):
    rigid, r_head = nrrd.read(rigid_img_path)
    inv_labels, inv_head = nrrd.read(inverted_labels_path)
    single_label, _ = nrrd.read(inverted_labels_path)
    single_label[single_label != label_of_interest] = 0
    rigid_img = sitk.GetImageFromArray(rigid)
    out_arr = cluster(rigid_img, kmean)
    corrected_label = geodesic_active_segmentation.snake(single_label, out_arr, label_of_interest, num_iterations,
                                                         prop_scaling)
    corrected_array = sitk.GetArrayFromImage(corrected_label)
    overlabelled_vals = np.logical_and(inv_labels == label_of_interest, corrected_array != 1)
    inv_labels[overlabelled_vals == True] = 0
    inv_labels[corrected_array == 1] = label_of_interest
    nrrd.write(str(inverted_labels_path), inv_labels, header=inv_head)
def fix_label ( rigid_img_path , inverted_labels_path , label_of_interest , kmean , num_iterations , prop_scaling ) : rigid , r_head = nrrd . read ( rigid_img_path ) inv_labels , inv_head = nrrd . read ( inverted_labels_path ) single_label , _ = nrrd . read ( inverted_labels_path ) single_label [ single_label != label_of_interest ] = 0 rigid_img = sitk . GetImageFromArray ( rigid ) out_arr = cluster ( rigid_img , kmean ) corrected_label = geodesic_active_segmentation . snake ( single_label , out_arr , label_of_interest , num_iterations , prop_scaling ) corrected_array = sitk . GetArrayFromImage ( corrected_label ) overlabelled_vals = np . logical_and ( inv_labels == label_of_interest , corrected_array != 1 ) inv_labels [ overlabelled_vals == True ] = 0 inv_labels [ corrected_array == 1 ] = label_of_interest nrrd . write ( str ( inverted_labels_path ) , inv_labels , header = inv_head )
Uses the active contour tool to automatically segment a poorly inverted label to a cluster image
Uses the active contour tool to automatically segment a poorly inverted label to a cluster image
"""Uses the active contour tool to automatically segment a poorly inverted label to a cluster image""" # # Get the bounding box of the inverted label - # Kyle - you don't need an ROI to fix the segmentation.
 #                                               # just get the label of interest
 # Perform the snake contouring to get a corrected label
 # Replace the old label with the corrected label
 # set over-labelled vals in original label to 0
 # set non-labelled values to the label of interest and write the file

rigid_img_path
inverted_labels_path
label_of_interest
kmean
num_iterations
prop_scaling