def find_normalization_params(pat_dce, pat_gt, label, pat_model):
    # Create the normalization object and load the model
    dce_norm = StandardTimeNormalization(DCEModality())
    dce_norm.load_model(pat_model)

    # Read the DCE
    dce_mod = DCEModality()
    dce_mod.read_data_from_path(pat_dce)

    # Read the GT
    gt_mod = GTModality()
    gt_mod.read_data_from_path(label, pat_gt)

    # Find the normalization parameters
    dce_norm.fit(dce_mod, ground_truth=gt_mod, cat=label[0])

    return dce_norm
Example #2
0
def find_normalization_params(pat_dce, pat_gt, label, pat_model):
    # Create the normalization object and load the model
    dce_norm = StandardTimeNormalization(DCEModality())
    dce_norm.load_model(pat_model)

    # Read the DCE
    dce_mod = DCEModality()
    dce_mod.read_data_from_path(pat_dce)

    # Read the GT
    gt_mod = GTModality()
    gt_mod.read_data_from_path(label, pat_gt)

    # Find the normalization parameters
    dce_norm.fit(dce_mod, ground_truth=gt_mod, cat=label[0])

    return dce_norm
def test_save_load_model():
    """Test the routine to store and load the model."""

    # Load the data with only a single serie
    currdir = os.path.dirname(os.path.abspath(__file__))
    path_data = os.path.join(currdir, 'data', 'full_dce')
    # Create an object to handle the data
    dce_mod = DCEModality()

    # Read the data
    dce_mod.read_data_from_path(path_data)

    # Load the GT data
    path_gt = [os.path.join(currdir, 'data', 'full_gt', 'prostate')]
    label_gt = ['prostate']
    gt_mod = GTModality()
    gt_mod.read_data_from_path(label_gt, path_gt)

    # Create the object to make the normalization
    stn = StandardTimeNormalization(dce_mod)
    stn.partial_fit_model(dce_mod, gt_mod, label_gt[0])

    # Store the file
    filename = os.path.join(currdir, 'data', 'model.npy')
    stn.save_model(filename)

    # Load the model in another object
    stn2 = StandardTimeNormalization(dce_mod)
    stn2.load_model(filename)

    # Check the different variable
    model_gt = np.array([22.26479174, 22.51070962, 24.66027277, 23.43488237,
                         23.75601817, 22.56173871, 26.86244505, 45.06227804,
                         62.34273874, 71.35327656])
    assert_array_almost_equal(stn.model_, model_gt, decimal=PRECISION_DECIMAL)
    assert_true(stn.is_model_fitted_)