Пример #1
0
def test_update_histogram_fix_bins():
    """ Test that the function properly update the value of the histogram
    and fixing the number of bins. """

    # Load the data and then call the function independently
    currdir = os.path.dirname(os.path.abspath(__file__))
    path_data = os.path.join(currdir, 'data', 'dce')
    # Create an object to handle the data
    dce_mod = DCEModality()

    dce_mod.read_data_from_path(path_data)

    # Change something in the data to check that the computation
    # is working
    dce_mod.data_[0, 20:40, :, :] = 1000.
    nb_bins = [100, 100]
    dce_mod.update_histogram(nb_bins=nb_bins)

    # We need to check that the minimum and maximum were proprely computed
    assert_equal(dce_mod.min_series_, 0.)
    assert_equal(dce_mod.max_series_, 1000.)

    # Check that bin is what we expect
    data = np.load(os.path.join(currdir, 'data',
                                'bin_dce_data_update_100_bins.npy'))
    # Check that each array are the same
    for exp, gt in zip(dce_mod.bin_series_, data):
        assert_array_equal(exp, gt)

    # Check that pdf is what we expect
    data = np.load(os.path.join(currdir, 'data',
                                'pdf_dce_data_update_100_bins.npy'))
    # Check that each array are the same
    for exp, gt in zip(dce_mod.pdf_series_, data):
        assert_array_equal(exp, gt)
Пример #2
0
def test_build_heatmap_roi():
    """ Test if the heatmap is built properly when providing a ROI. """

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

    # Read the data
    dce_mod.read_data_from_path(path_data)
    dce_mod.data_ /= 2.
    dce_mod.update_histogram()

    # Create some ground-truth
    pos = np.ones((368, 448), dtype=bool)
    neg = np.zeros((368, 448), dtype=bool)
    gt_index = np.rollaxis(np.array([neg, pos, pos, pos, neg]), 0, 3)

    # Build the heatmap
    heatmap, bins_heatmap = dce_mod.build_heatmap(roi_data=(gt_index))

    # Check that heatmap is what we expect
    data = np.load(os.path.join(currdir, 'data', 'heatmap_roi_mod.npy'))
    assert_array_equal(heatmap, data)
    data = np.load(os.path.join(currdir, 'data', 'bins_heatmap_roi_mod.npy'))
    assert_array_equal(bins_heatmap, data)
    # Read the GT
    print 'Read GT images'
    gt_mod = GTModality()
    gt_mod.read_data_from_path(label_gt, p_gt)

    # Load the approproate normalization object
    filename_norm = (pat.lower().replace(' ', '_') +
                     '_norm.p')
    dce_norm = StandardTimeNormalization.load_from_pickles(
        os.path.join(path_norm, filename_norm))

    dce_mod = dce_norm.normalize(dce_mod)

    for idx in range(dce_mod.data_.shape[0]):
        dce_mod.data_[idx, :] += shift[idx]

    dce_mod.update_histogram()

    # Fit the parameters for Brix
    print 'Extract Brix'
    brix_ext.fit(dce_mod, ground_truth=gt_mod, cat=label_gt[0])

    # Extract the matrix
    print 'Extract the feature matrix'
    data = brix_ext.transform(dce_mod, ground_truth=gt_mod, cat=label_gt[0])

    pat_chg = pat.lower().replace(' ', '_') + '_brix.npy'
    filename = os.path.join(path_store, pat_chg)
    np.save(filename, data)
    dce_mod.read_data_from_path(p_dce)

    # Read the GT
    print 'Read GT images'
    gt_mod = GTModality()
    gt_mod.read_data_from_path(label_gt, p_gt)

    # Load the approproate normalization object
    filename_norm = (pat.lower().replace(' ', '_') + '_norm.p')
    dce_norm = StandardTimeNormalization.load_from_pickles(
        os.path.join(path_norm, filename_norm))

    dce_mod = dce_norm.normalize(dce_mod)

    for idx in range(dce_mod.data_.shape[0]):
        dce_mod.data_[idx, :] += shift[idx]

    dce_mod.update_histogram()

    # Fit the parameters for Brix
    print 'Extract Weibull'
    pun_ext.fit(dce_mod, ground_truth=gt_mod, cat=label_gt[0])

    # Extract the matrix
    print 'Extract the feature matrix'
    data = pun_ext.transform(dce_mod, ground_truth=gt_mod, cat=label_gt[0])

    pat_chg = pat.lower().replace(' ', '_') + '_pun.npy'
    filename = os.path.join(path_store, pat_chg)
    np.save(filename, data)