Exemplo n.º 1
0
def CT(pix, phantom, angles, src_rad, noise, Exp_bin, bin_param, f_load_path,
       g_load_path):
    voxels = [pix, pix, pix]
    det_rad = 0
    if g_load_path is not None and f_load_path is not None:
        data_obj = ddf.phantom(voxels, phantom, angles, noise, src_rad, 
                               det_rad, load_data_g=g_load_path, 
                               load_data_f=f_load_path)
    elif g_load_path is not None:
        data_obj = ddf.phantom(voxels, phantom, angles, noise, src_rad, 
                               det_rad, load_data_g=g_load_path)
    elif f_load_path is not None:
        data_obj = ddf.phantom(voxels, phantom, angles, noise, src_rad, 
                               det_rad, load_data_f=f_load_path)
    else:
        data_obj = ddf.phantom(voxels, phantom, angles, noise, src_rad, 
                               det_rad)

  
    # %% Create the circular cone beam CT class
    CT_obj = ddf.CCB_CT(data_obj)

    CT_obj.init_algo()
    CT_obj.init_DDF_FDK(bin_param, Exp_bin)
    return CT_obj
Exemplo n.º 2
0
def CT(load_path, dset, sc, ang_freq, Exp_bin, bin_param, nTrain, nTD, nVal,
       nVD, bpath):
    dataset = ddf.load_and_preprocess_real_data(load_path, dset, sc)
    meta = ddf.load_meta(load_path + dset + '/', sc)
    pix_size = meta['pix_size']
    src_rad = meta['s2o']
    det_rad = meta['o2d']

    data_obj = ddf.real_data(dataset,
                             pix_size,
                             src_rad,
                             det_rad,
                             ang_freq,
                             zoom=False)

    CT_obj = ddf.CCB_CT(data_obj)
    CT_obj.init_algo()
    spf_space, Exp_op = ddf.support_functions.ExpOp_builder(
        bin_param, CT_obj.filter_space, interp=Exp_bin)
    # Create the FDK binned operator
    #    CT_obj.FDK_bin_nn = CT_obj.FDK_op * Exp_op

    # Create the NN-FDK object
    CT_obj.NNFDK = nn.NNFDK_class(CT_obj,
                                  nTrain,
                                  nTD,
                                  nVal,
                                  nVD,
                                  Exp_bin,
                                  Exp_op,
                                  bin_param,
                                  dset=dset,
                                  base_path=bpath)
    CT_obj.rec_methods += [CT_obj.NNFDK]
    return CT_obj
Exemplo n.º 3
0
def CT(pix, phantom, angles, src_rad, noise, nTrain, nTD, nVal, nVD,
              Exp_bin, bin_param, f_load_path, g_load_path):
    
    voxels = [pix, pix, pix]
    det_rad = 0
    if g_load_path is not None:
        if f_load_path is not None:
            data_obj = ddf.phantom(voxels, phantom, angles, noise, src_rad,
                                   det_rad, load_data_g=g_load_path,
                                   load_data_f=f_load_path)
        else:
            data_obj = ddf.phantom(voxels, phantom, angles, noise, src_rad,
                               det_rad, load_data_g=g_load_path)
            
    else:
        data_obj = ddf.phantom(voxels, phantom, angles, noise, src_rad,
                                   det_rad)

    CT_obj = ddf.CCB_CT(data_obj)
    CT_obj.init_algo()
    spf_space, Exp_op = ddf.support_functions.ExpOp_builder(bin_param,
                                                         CT_obj.filter_space,
                                                         interp=Exp_bin)
    # Create the FDK binned operator
    CT_obj.FDK_bin_nn = CT_obj.FDK_op * Exp_op

    # Create the NN-FDK object
    CT_obj.NNFDK = nn.NNFDK_class(CT_obj, nTrain, nTD, nVal, nVD, Exp_bin,
                                   Exp_op, bin_param)
    CT_obj.rec_methods += [CT_obj.NNFDK]
    return CT_obj
Exemplo n.º 4
0
def CT(pix, phantom, angles, src_rad, noise):
    voxels = [pix, pix, pix]
    det_rad = 0
    data_obj = ddf.phantom(voxels, phantom, angles, noise, src_rad, det_rad)

    CT_obj = ddf.CCB_CT(data_obj)
    CT_obj.init_algo()
    return CT_obj
Exemplo n.º 5
0
def CT(load_path, dset, sc, ang_freq):
    dataset = ddf.load_and_preprocess_real_data(load_path, dset, sc)
    meta = ddf.load_meta(load_path + dset + '/', sc)
    pix_size = meta['pix_size']
    src_rad = meta['s2o']
    det_rad = meta['o2d']
    
    data_obj = ddf.real_data(dataset, pix_size, src_rad, det_rad, ang_freq,
                 zoom=False)

    CT_obj = ddf.CCB_CT(data_obj)
    CT_obj.init_algo()
    return CT_obj
Exemplo n.º 6
0
def CT(path, dset, sc, ang_freq, vox):
    dataset, vecs = cap.load_and_preprocess(path, dset, ang_freq=ang_freq)
    meta = ddf.load_meta(f'{path}{dset}/', 1)
    pix_size = sc * meta['pix_size']
    src_rad = meta['s2o']
    det_rad = meta['o2d']

    data_obj = ddf.real_data(dataset,
                             pix_size,
                             src_rad,
                             det_rad,
                             ang_freq,
                             vox=vox,
                             vecs=vecs)

    CT_obj = ddf.CCB_CT(data_obj)
    CT_obj.init_algo()
    return CT_obj
Exemplo n.º 7
0
def CT(pix, phantom, angles, src_rad, noise, Exp_bin, bin_param, f_load_path,
       g_load_path):
    voxels = [pix, pix, pix]
    det_rad = 0
    data_obj = ddf.phantom(voxels,
                           phantom,
                           angles,
                           noise,
                           src_rad,
                           det_rad,
                           samp_fac=1)

    # %% Create the circular cone beam CT class
    CT_obj = ddf.CCB_CT(data_obj)

    CT_obj.init_algo()
    CT_obj.init_DDF_FDK(bin_param, Exp_bin)
    return CT_obj
Exemplo n.º 8
0
def CT(load_path, dset, sc, ang_freq, Exp_bin, bin_param, offset):
    dataset = ddf.load_and_preprocess_real_data(load_path, dset, sc)
    meta = ddf.load_meta(load_path + dset + '/', sc)
    pix_size = meta['pix_size']
    src_rad = meta['s2o']
    det_rad = meta['o2d']

    data_obj = ddf.real_data(dataset,
                             pix_size,
                             src_rad,
                             det_rad,
                             ang_freq,
                             zoom=True,
                             offset=offset)

    CT_obj = ddf.CCB_CT(data_obj)
    CT_obj.init_algo()
    CT_obj.init_DDF_FDK()
    return CT_obj
Exemplo n.º 9
0
def CT(path, dset, sc, ang_freq, Exp_bin, bin_param, nTrain, nTD, nVal, nVD,
       vox, bp):
    dataset, vecs = cap.load_and_preprocess(path, dset, ang_freq=ang_freq)
    meta = ddf.load_meta(f'{path}{dset}/', 1)
    pix_size = sc * meta['pix_size']
    src_rad = meta['s2o']
    det_rad = meta['o2d']

    data_obj = ddf.real_data(dataset,
                             pix_size,
                             src_rad,
                             det_rad,
                             ang_freq,
                             vox=vox,
                             vecs=vecs)

    CT_obj = ddf.CCB_CT(data_obj)
    CT_obj.init_algo()
    spf_space, Exp_op = ddf.support_functions.ExpOp_builder(
        bin_param, CT_obj.filter_space, interp=Exp_bin)
    # Create the FDK binned operator
    #    CT_obj.FDK_bin_nn = CT_obj.FDK_op * Exp_op

    # Create the NN-FDK object
    CT_obj.NNFDK = nn.NNFDK_class(CT_obj,
                                  nTrain,
                                  nTD,
                                  nVal,
                                  nVD,
                                  Exp_bin,
                                  Exp_op,
                                  bin_param,
                                  dset=dset,
                                  base_path=bp)
    CT_obj.rec_methods += [CT_obj.NNFDK]
    return CT_obj
Exemplo n.º 10
0
def Create_dataset(pix, phantom, angles, src_rad, noise, Exp_bin, bin_param):
    if phantom == 'Defrise':
        phantom = 'Defrise random'
    if phantom == 'Fourshape_test':
        phantom = 'Fourshape'
    # Maximum number of voxels considered per dataset
    MaxVoxDataset = np.max([int(pix**3 * 0.005), 1 * 10**6])

    # The size of the measured objects in voxels
    voxels = [pix, pix, pix]
    data_obj = ddf.phantom(voxels, phantom)
    det_rad = 0

    case = ddf.CCB_CT(data_obj, angles, src_rad, det_rad, noise)
    # Initialize the algorithms (FDK, SIRT)
    case.init_algo()
    # Create a binned filter space and a expansion operator
    spf_space, Exp_op = ddf.support_functions.ExpOp_builder(bin_param,
                                                            case.filter_space,
                                                            interp=Exp_bin)
    # Create FDK operator that takes binned filters
    FDK_bin_nn = case.FDK_op * Exp_op

    # Create a sampling operator
    S = SamplingOp(case.reco_space, MaxVoxDataset, case.WV_path)

    # Create the Operator related to the learning matrix
    B = S * FDK_bin_nn
    # Compute the learning matrix
    Bmat = odl.operator.oputils.matrix_representation(B)

    # Create the target data
    v_gt = np.asarray(S(case.phantom.f))
    Data = np.concatenate((Bmat, v_gt[:, None]), 1)

    return Data
Exemplo n.º 11
0
# Variables above are expressed in the phyisical size of the measured object

# Noise model
# Options: None,  ['Gaussian', %intensity], ['Poisson', I_0], ['loaded data',
#                    filename]

# Create a data object
data_obj = ddf.phantom(voxels, phantom, angles, noise, src_rad,
                       det_rad)  #, load_data=f_load_path)

# Expansion operator and binnin parameter
expansion_op = 'linear'
bin_param = 2

# %% Create the circular cone beam CT class
case = ddf.CCB_CT(data_obj)  #,
##                  load_data=g_load_path)
## Initialize the algorithms (FDK, SIRT)
case.init_algo()
case.init_DDF_FDK()
# %%
rec_RL = case.FDK.do('Ram-Lak', compute_results='no')
rec_RL_B2 = case.FDK.filt_LP('Shepp-Logan', ['Bin', 2], compute_results='no')
rec_RL_B4 = case.FDK.filt_LP('Shepp-Logan', ['Bin', 4], compute_results='no')
rec_RL_G2 = case.FDK.filt_LP('Shepp-Logan', ['Gauss', 2], compute_results='no')
rec_RL_G5 = case.FDK.filt_LP('Shepp-Logan', ['Gauss', 5], compute_results='no')
rec_T = case.TFDK.do(lam=6e-5, compute_results='no')

# %%
seg_GT = (np.asarray(data_obj.f) > 0.239)
Exemplo n.º 12
0
def main(pix, phantom, nTD, nTrain, nVD, nVal, train, bpath, stop_crit,
         PH, angles, src_rad, det_rad, noise, Exp_bin, bin_param):
    # Specific phantom

    
    # %%
    t1 = time.time()
    nn.Create_TrainingValidationData(pix, phantom, angles, src_rad, noise,
                                     Exp_bin, bin_param, nTD + nVD,
                                     base_path=bpath)
    print('Creating training and validation datasets took', time.time() - t1,
          'seconds')
    
    # %% Create a test phantom

    voxels = [pix, pix, pix]
    # Create a data object
    t2 = time.time()
    if not train:
        data_obj = ddf.phantom(voxels, phantom, angles, noise, src_rad,
                               det_rad)#,
        #                       compute_xHQ=True)
        print('Making phantom and mask took', time.time() -t2, 'seconds')
        # The amount of projection angles in the measurements
        # Source to center of rotation radius
         
        t3 = time.time()
        # %% Create the circular cone beam CT class
        case = ddf.CCB_CT(data_obj)#, angles, src_rad, det_rad, noise)
        print('Making data and operators took', time.time()-t3, 'seconds')
        # Initialize the algorithms (FDK, SIRT)
        t4 = time.time()
        case.init_algo()
        
        # %% Create NN-FDK algorithm setup
        # Create binned filter space and expansion operator
        spf_space, Exp_op = ddf.support_functions.ExpOp_builder(bin_param,
                                                             case.filter_space,
                                                             interp=Exp_bin)
        # Create the FDK binned operator
        case.FDK_bin_nn = case.FDK_op * Exp_op
        
        # Create the NN-FDK object
        case.NNFDK = nn.NNFDK_class(case, nTrain, nTD, nVal, nVD, Exp_bin,
                                    Exp_op,
                                     bin_param, base_path=bpath)
        case.rec_methods += [case.NNFDK]
        case.MSD = msd.MSD_class(case, case.NNFDK.data_path)
        case.rec_methods += [case.MSD]
        print('Initializing algorithms took', time.time() - t4, 'seconds')
    else:
        data_path = nn.make_data_path(pix, phantom, angles, src_rad, noise,
                                      Exp_bin, bin_param, base_path=bpath)
        MSD = msd.MSD_class(None, data_path)

    
    # %%

    
    l_tr, l_v = nn.Preprocess_datasets.random_lists(nTD, nVD)
    if nVD == 0:
        list_tr = [0]
        list_v = None
    elif nVD == 1:
        list_tr = [0]
        list_v = [1]
    else:
        list_tr = [i for i in range(10)]
        list_v = [i + 10 for i in range(5)]
        
    if train:
        print('Started training function')
        MSD.train(list_tr, list_v, stop_crit=stop_crit, ratio=3)
    
    else:
        case.MSD.add2sp_list(list_tr, list_v)
        case.MSD.do()
        # %%
        print('MSD rec time:', case.MSD.results.rec_time[0])
#        print('NNFDK rec time:', case.NNFDK.results.rec_time[0])
#        print('FDK rec time:', case.FDK.results.rec_time[0])
        # %%
        save_path = '/bigstore/lagerwer/NNFDK_results/figures/'
        pylab.close('all')
        case.table()
        case.show_phantom()
        case.MSD.show(save_name=f'{save_path}MSD_{PH}_nTD{nTD}_nVD{nVD}')
Exemplo n.º 13
0
t2 = time.time()
offset = 1.26 / 360 * 2 * np.pi
data_obj = ddf.real_data(dataset,
                         pix_size,
                         src_rad,
                         det_rad,
                         ang_freq,
                         zoom=True,
                         offset=offset)
print('Making phantom and mask took', time.time() - t2, 'seconds')
# The amount of projection angles in the measurements
# Source to center of rotation radius

t3 = time.time()
# %% Create the circular cone beam CT class
case = ddf.CCB_CT(data_obj)  #, angles, src_rad, det_rad, noise)
print('Making data and operators took', time.time() - t3, 'seconds')
# Initialize the algorithms (FDK, SIRT)
t4 = time.time()
case.init_algo()

print('Initializing algorithms took', time.time() - t4, 'seconds')
# %%
offset = 1.26 / 360 * 2 * np.pi
rec1 = case.FDK.do('Hann', compute_results=False)
voxels = np.shape(rec1)
hann = make_hann_filt(voxels, case.w_detu)
rec = ddf.FDK_ODL_astra_backend.FDK_astra(data_obj.g,
                                          hann,
                                          case.geometry,
                                          case.reco_space,
Exemplo n.º 14
0
def main(phantom, nTD, nVD, train):
    pix = 1024
    # Specific phantom

    if phantom == 'Fourshape_test':
        PH = '4S'
        src_rad = 10
        noise = ['Poisson', 2**8]
    elif phantom == 'Defrise':
        PH = 'DF'
        src_rad = 2
        noise = None

    # Number of angles
    angles = 360
    # Source radius
    det_rad = 0
    # Noise specifics

    # Number of voxels used for training, number of datasets used for training
    nTrain = 1e6
    # Number of voxels used for validation, number of datasets used for validation
    nVal = 1e6

    # Specifics for the expansion operator
    Exp_bin = 'linear'
    bin_param = 2
    bpath = '/export/scratch2/lagerwer/data/NNFDK/'

    # %%
    t1 = time.time()
    nn.Create_TrainingValidationData(pix,
                                     phantom,
                                     angles,
                                     src_rad,
                                     noise,
                                     Exp_bin,
                                     bin_param,
                                     nTD + nVD,
                                     base_path=bpath)
    print('Creating training and validation datasets took',
          time.time() - t1, 'seconds')

    # %% Create a test phantom
    voxels = [pix, pix, pix]
    # Create a data object
    t2 = time.time()
    data_obj = ddf.phantom(voxels, phantom, angles, noise, src_rad,
                           det_rad)  #,
    #                       compute_xHQ=True)
    print('Making phantom and mask took', time.time() - t2, 'seconds')
    # The amount of projection angles in the measurements
    # Source to center of rotation radius

    t3 = time.time()
    # %% Create the circular cone beam CT class
    case = ddf.CCB_CT(data_obj)  #, angles, src_rad, det_rad, noise)
    print('Making data and operators took', time.time() - t3, 'seconds')
    # Initialize the algorithms (FDK, SIRT)
    t4 = time.time()
    case.init_algo()

    # %% Create NN-FDK algorithm setup
    # Create binned filter space and expansion operator
    spf_space, Exp_op = ddf.support_functions.ExpOp_builder(bin_param,
                                                            case.filter_space,
                                                            interp=Exp_bin)
    # Create the FDK binned operator
    case.FDK_bin_nn = case.FDK_op * Exp_op

    # Create the NN-FDK object
    case.NNFDK = nn.NNFDK_class(case,
                                nTrain,
                                nTD,
                                nVal,
                                nVD,
                                Exp_bin,
                                Exp_op,
                                bin_param,
                                base_path=bpath)
    case.rec_methods += [case.NNFDK]
    print('Initializing algorithms took', time.time() - t4, 'seconds')

    # %%
    if not train:
        case.FDK.do('Hann')
        case.NNFDK.train(4)
        case.NNFDK.do()