def test_compute_dice_coefficient():
    ref = np.zeros([3, 3, 3])
    test = np.zeros([3, 3, 3])    
    
    dice = compute_dice_coefficient(ref, test, 1)
    assert dice == 1.0, "Unexpected Dice coefficient"

    test += 1
    dice = compute_dice_coefficient(ref, test, 1)
    assert dice == 0.0, "Unexpected Dice coefficient"    

    ref += 1
    dice = compute_dice_coefficient(ref, test, 1)
    assert dice == 1.0, "Unexpected Dice coefficient"        

    ref[1, 1, 1] = 0
    dice = compute_dice_coefficient(ref, test, 1)
    assert dice == 26*2/(27+26.), "Unexpected Dice coefficient"    

    ref[1, 1, 1] = 2
    dice = compute_dice_coefficient(ref, test, 1)
    assert dice == 26*2/(27+27.), "Unexpected Dice coefficient"    
예제 #2
0
def test_compute_dice_coefficient():
    ref = np.zeros([3, 3, 3])
    test = np.zeros([3, 3, 3])

    dice = compute_dice_coefficient(ref, test, 1)
    assert dice == 1.0, "Unexpected Dice coefficient"

    test += 1
    dice = compute_dice_coefficient(ref, test, 1)
    assert dice == 0.0, "Unexpected Dice coefficient"

    ref += 1
    dice = compute_dice_coefficient(ref, test, 1)
    assert dice == 1.0, "Unexpected Dice coefficient"

    ref[1, 1, 1] = 0
    dice = compute_dice_coefficient(ref, test, 1)
    assert dice == 26 * 2 / (27 + 26.), "Unexpected Dice coefficient"

    ref[1, 1, 1] = 2
    dice = compute_dice_coefficient(ref, test, 1)
    assert dice == 26 * 2 / (27 + 27.), "Unexpected Dice coefficient"
예제 #3
0
def test_vessel_particles_mask_workflow():
    # Get the path to the this test so that we can reference the test data
    this_dir = os.path.dirname(os.path.realpath(__file__))

    # Set up the inputs and run the workflow
    ct_file_name = this_dir + '/../../../../Testing/Data/Input/vessel.nrrd'
    label_map_file_name = \
      this_dir + '/../../../../Testing/Data/Input/vessel_volumeMask.nrrd'
    seeds_mask_file_name = \
      this_dir + '/../../../../Testing/Data/Input/vessel_vesselSeedsMask.nrrd'
    tmp_dir = tempfile.mkdtemp()
    vessel_seeds_mask_file_name = os.path.join(tmp_dir, 'vesselSeedsMask.nrrd')

    wf = VesselParticlesMaskWorkflow(ct_file_name, label_map_file_name, 
                                     tmp_dir, vessel_seeds_mask_file_name)
    wf.run()

    ref, ref_header = nrrd.read(seeds_mask_file_name)
    test, test_header = nrrd.read(vessel_seeds_mask_file_name)    
    dice = compute_dice_coefficient(ref, test, 1)
    shutil.rmtree(tmp_dir)
    
    assert dice > 0.995, "Dice coefficient lower than expected"
    # Get the path to the this test so that we can reference the test data
    this_dir = os.path.dirname(os.path.realpath(__file__))

    # Set up the inputs and run the workflow
    ct_file_name = '/Users/jinho/Github/ChestImagingPlatform/Testing/Data/Input/vessel.nrrd'
    label_map_file_name = '/Users/jinho/Github/ChestImagingPlatform/Testing/Data/Input/vessel_volumeMask.nrrd'
    seeds_mask_file_name = '/Users/jinho/Github/ChestImagingPlatform/Testing/Data/Input/vessel_vesselSeedsMask.nrrd'
    tmp_dir = tempfile.mkdtemp()
    vessel_seeds_mask_file_name = os.path.join(tmp_dir, 'vesselSeedsMask.nrrd')

    gaussianStd = [0.7, 4.0, params['num_steps']]

    wf = VesselParticlesMaskWorkflow(ct_file_name, label_map_file_name,
                                     tmp_dir, vessel_seeds_mask_file_name)
    wf.get_node('compute_feature_strength').inputs.alpha = params['alpha']
    wf.get_node('compute_feature_strength').inputs.beta = params['beta']
    wf.get_node('compute_feature_strength').inputs.C = params['C']
    wf.get_node('compute_feature_strength').inputs.std = gaussianStd
    wf.get_node('unu_heq').inputs.amount = params['amount']
    wf.get_node('unu_heq').inputs.smart = params['smart']
    wf.run()

    ref, ref_header = nrrd.read(seeds_mask_file_name)
    test, test_header = nrrd.read(vessel_seeds_mask_file_name)
    score = compute_dice_coefficient(ref, test, 1)
    #print vessel_seeds_mask_file_name

    scientist.update(params, score)

    shutil.rmtree(tmp_dir)