def test_normalize_denormalize_3():
    """Test the data normalization and denormalization with shift > 0."""

    # 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)

    # Simulate that we fitted the data
    stn.model_ = np.array([30., 30., 32., 31., 31., 30., 35., 55., 70., 80.])
    stn.is_model_fitted_ = True
    stn.fit_params_ = {'scale-int': 1.2296657327848537,
                       'shift-time': 3.0,
                       'shift-int': np.array([191.29, 193.28, 195.28, 195.28,
                                              195.28, 197.28, 213.25, 249.18,
                                              283.12, 298.10])}
    stn.is_fitted_ = True

    # Store the data somewhere
    data_gt_cp = dce_mod.data_.copy()

    # Normalize the data
    dce_mod_norm = stn.normalize(dce_mod)

    # Check if the data are properly normalized
    dce_mod_norm.data_.flags.writeable = False
    data = np.load(os.path.join(currdir, 'data', 'data_normalized_dce_3.npy'))
    assert_equal(hash(dce_mod_norm.data_.data), data)

    dce_mod_norm.data_.flags.writeable = True

    dce_mod_2 = stn.denormalize(dce_mod_norm)
    dce_mod_2.data_.flags.writeable = False
    assert_equal(hash(dce_mod_2.data_.data), -3781160829709175881)
Ejemplo n.º 2
0
path_dce = '/data/prostate/experiments/Patient 387/DCE'

# Define the list of path for the GT
path_gt = ['/data/prostate/experiments/Patient 387/GT_inv/prostate']
# Define the associated list of label for the GT
label_gt = ['prostate']

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

# Read the GT
gt_mod = GTModality()
gt_mod.read_data_from_path(label_gt, path_gt)

# Fit the data to get the normalization parameters
dce_norm.fit(dce_mod, ground_truth=gt_mod,
                           cat='prostate')

dce_mod_norm = dce_norm.normalize(dce_mod)
# Plot the figure
plt.figure()
heatmap, bins_heatmap = dce_mod.build_heatmap(np.nonzero(gt_mod.data_[0, :, :, :]))
sns.heatmap(heatmap, cmap='jet')
# plt.plot(dce_norm.shift_idx_, np.arange(0, dce_mod.n_serie_)[::-1] + .5 ,'ro')
# plt.plot(dce_norm.shift_idx_ + dce_norm.rmse,
#          np.arange(0, dce_mod.n_serie_)[::-1] + .5 ,'go')
# plt.plot(dce_norm.shift_idx_ - dce_norm.rmse,
#          np.arange(0, dce_mod.n_serie_)[::-1] + .5 ,'go')
plt.savefig('heatmap.png')