def test_fit(): """Test the routine to fit the parameters of the dce normalization.""" # 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) # Create a synthetic model to fit on stn.model_ = np.array([30., 30., 32., 31., 31., 30., 35., 55., 70., 80.]) stn.is_model_fitted_ = True # Fit the parameters on the model stn.fit(dce_mod, gt_mod, label_gt[0]) assert_almost_equal(stn.fit_params_['scale-int'], 1.2296657327848537, decimal=PRECISION_DECIMAL) assert_equal(stn.fit_params_['shift-time'], 0.0) data = np.array([191.29, 193.28, 195.28, 195.28, 195.28, 197.28, 213.25, 249.18, 283.12, 298.10]) assert_array_almost_equal(stn.fit_params_['shift-int'], data, decimal=PRECISION_DECIMAL)
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
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')