예제 #1
0
def flat_correction(proj, flat, dark, params):

    log.info('  *** normalization')
    if (params.flat_correction_method == 'standard'):
        try:
            data = tomopy.normalize(proj,
                                    flat,
                                    dark,
                                    cutoff=params.normalization_cutoff /
                                    params.bright_exp_ratio)
            data *= params.bright_exp_ratio
        except AttributeError:
            log.warning('  *** *** No bright_exp_ratio found.  Ignore')
        log.info('  *** *** ON %f cut-off' % params.normalization_cutoff)
    elif (params.flat_correction_method == 'air'):
        data = tomopy.normalize_bg(proj, air=params.air)
        log.info('  *** *** air %d pixels' % params.air)
    elif (params.flat_correction_method == 'none'):
        data = proj
        log.warning('  *** *** normalization is turned off')
    else:
        raise ValueError("Unknown value for *flat_correction_method*: {}. "
                         "Valid options are {}"
                         "".format(
                             params.flat_correction_method,
                             config.SECTIONS['flat-correction']
                             ['flat-correction-method']['choices']))
    return data
예제 #2
0
def project(ct_series, outdir, console_out):
    """convert ct image series to projection series"""
    if os.path.exists(outdir):
        msg = "%s existed, assume projection has already been done. skip this\n" % (
            outdir,)
        console_out.write(msg)
        return
    import tomopy
    data = []; N = len(ct_series.identifiers)
    prefix = "Read ct series"
    for i,angle in enumerate(ct_series.identifiers):
        # if i%3 != 0: continue
        data1 = ct_series.getImage(angle).getData()
        # data[data<=0] = 1.
        data1 = data1[100:-100, 100:-100]
        data.append(data1)
        console_out.write("\r%s: %2.0f%%" % (prefix, (i+1)*100./N))
        console_out.flush()
        continue
    console_out.write("\n"); console_out.flush()
    # project
    console_out.write("tomopy.normalize_bg..."); console_out.flush()
    proj = tomopy.normalize_bg(data) # , ncore=ncore)
    console_out.write("done\n"); console_out.flush()
    del data
    # remove negative intensities
    proj[proj<0] = 0
    # output
    console_out.write("tomopy.write_tiff_stack..."); console_out.flush()
    tomopy.write_tiff_stack(
        proj, fname=os.path.join(outdir, 'proj'), axis=1, overwrite=False)
    console_out.write("done\n"); console_out.flush()
    return
예제 #3
0
def preprocess_data(prj,
                    flat,
                    dark,
                    FF_norm=flat_field_norm,
                    remove_rings=remove_rings,
                    FF_drift_corr=flat_field_drift_corr,
                    downsapling=binning):

    if FF_norm:  # dark-flat field correction
        prj = tomopy.normalize(prj, flat, dark)
    if FF_drift_corr:  # flat field drift correction
        prj = tomopy.normalize_bg(prj, air=50)
    prj[prj <= 0] = 1  # check dark<data
    prj = tomopy.minus_log(prj)  # -logarithm
    if remove_rings:  # remove rings
        prj = tomopy.remove_stripe_fw(prj,
                                      level=7,
                                      wname='sym16',
                                      sigma=1,
                                      pad=True)
        #prj = tomopy.remove_stripe_ti(prj,2)
        # prj = tomopy.remove_all_stripe(prj)
    if downsapling > 0:  # binning
        prj = tomopy.downsample(prj, level=binning)
        prj = tomopy.downsample(prj, level=binning, axis=1)
    return prj
예제 #4
0
def preprocess_data(prj, flat, dark, FF_norm=flat_field_norm, remove_rings = remove_rings, medfilt_size=medfilt_size, FF_drift_corr=flat_field_drift_corr, downspling=binning):

    if FF_norm:
        # normalize the prj
        print('\n*** Applying flat field correction:') 
        start_norm_time = time.time()
        prj = tomopy.normalize(prj, flat, dark)
        print('   done in %0.3f min' % ((time.time() - start_norm_time)/60))

    if FF_drift_corr:
        print('\n*** Applying flat field drift correction:')
        start_norm_bg_time = time.time()
        prj = tomopy.normalize_bg(prj, air=100)
        print('   done in %0.3f min' % ((time.time() - start_norm_bg_time)/60))

    # Applying -log
    print('\n*** Applying -log:') 
    start_log_time = time.time()
    prj = tomopy.minus_log(prj)
    print('   done in %0.3f min' % ((time.time() - start_log_time)/60))

    prj = tomopy.misc.corr.remove_neg(prj, val=0.000)
    prj = tomopy.misc.corr.remove_nan(prj, val=0.000)
    prj[np.where(prj == np.inf)] = 0.000
#    prj[np.where(prj == 0)] = 0.000,2
    print('\n*** Min and max val in prj before recon: %0.3f, %0.3f'  % (np.min(prj), np.max(prj)))

    if remove_rings:
        # remove ring artefacts
        tmp = prj[-1,:,:] # use to fixe the bug of remove_stripe_ti
        print('\n*** Applying ring removal algo:') 
        start_ring_time = time.time()
#        prj = tomopy.remove_stripe_ti(prj, nblock=0, alpha=2)
        prj = tomopy.remove_stripe_fw(prj)
    #    prj = tomopy.remove_stripe_sf(prj,10); prj = tomopy.misc.corr.remove_neg(prj, val=0.000) # remove the neg values coming from remove_stripe_sf
        print('   done in %0.3f min' % ((time.time() - start_ring_time)/60))
        prj[-1,:,:] = tmp # fixe the bug of remove_stripe_ti

    # Filtering data with 2D median filter before downsampling and recon 
    if medfilt_size>1:
        start_filter_time = time.time()
        print('\n*** Applying median filter')
        #prj = tomopy.median_filter(prj,size=1)
        prj = ndimage.median_filter(prj,footprint=np.ones((1, medfilt_size, medfilt_size)))
        print('   done in %0.3f min' % ((time.time() - start_filter_time)/60))

    # Downsampling data:
    if downspling>0:
        print('\n** Applying downsampling')
        start_down_time = time.time()
        prj = tomopy.downsample(prj, level=binning)
        prj = tomopy.downsample(prj, level=binning, axis=1)
        print('   done in %0.3f min' % ((time.time() - start_down_time)/60))
        
    print('\n*** Shape of the data:'+str(np.shape(prj)))
    print('      Dimension of theta:'+str(np.shape(theta)))

    return prj
예제 #5
0
def main(arg):

    parser = argparse.ArgumentParser()
    parser.add_argument(
        "top", help="top directory where the tiff images are located: /data/")
    parser.add_argument("start",
                        nargs='?',
                        const=1,
                        type=int,
                        default=1,
                        help="index of the first image: 10001 (default 1)")

    args = parser.parse_args()

    top = args.top
    index_start = int(args.start)

    template = os.listdir(top)[1]

    nfile = len(fnmatch.filter(os.listdir(top), '*.tif'))
    index_end = index_start + nfile
    ind_tomo = range(index_start, index_end)

    fname = top + template

    # Read the tiff raw data.
    rdata = dxchange.read_tiff_stack(fname, ind=ind_tomo)
    particle_bed_reference = particle_bed_location(rdata[0], plot=False)
    print("Particle bed location: ", particle_bed_reference)

    # Cut the images to remove the particle bed
    cdata = rdata[:, 0:particle_bed_reference, :]

    # Find the image when the shutter starts to close
    dark_index = shutter_off(rdata)
    print("shutter closes on image: ", dark_index)
    # Set the [start, end] index of the blocked images, flat and dark.
    flat_range = [0, 1]
    data_range = [48, dark_index]
    dark_range = [dark_index, nfile]

    # # for fast testing
    # data_range = [48, dark_index]

    flat = cdata[flat_range[0]:flat_range[1], :, :]
    proj = cdata[data_range[0]:data_range[1], :, :]
    dark = np.zeros(
        (dark_range[1] - dark_range[0], proj.shape[1], proj.shape[2]))

    # if you want to use the shutter closed images as dark uncomment this:
    #dark = cdata[dark_range[0]:dark_range[1], :, :]

    ndata = tomopy.normalize(proj, flat, dark)
    ndata = tomopy.normalize_bg(ndata, air=ndata.shape[2] / 2.5)
    ndata = tomopy.minus_log(ndata)
    sharpening(ndata)
    slider(ndata)
예제 #6
0
파일: align.py 프로젝트: decarlof/txm_util
def main(arg):

    parser = argparse.ArgumentParser()
    parser.add_argument("top", help="top directory where the tiff images are located: /data/")
    parser.add_argument("start", nargs='?', const=1, type=int, default=1, help="index of the first image: 1000 (default 1)")

    args = parser.parse_args()

    top = args.top
    index_start = int(args.start)

    template = os.listdir(top)[0]

    nfile = len(fnmatch.filter(os.listdir(top), '*.tif'))
    index_end = index_start + nfile
    ind_tomo = range(index_start, index_end)
    
    fname = top + template

    print (nfile, index_start, index_end, fname)


    # Select the sinogram range to reconstruct.
    start = 0
    end = 512
    sino=(start, end)

    # Read the tiff raw data.
    ndata = dxchange.read_tiff_stack(fname, ind=ind_tomo, slc=(sino, None))
 
    # Normalize to 1 using the air counts
    ndata = tomopy.normalize_bg(ndata, air=5)

    # Set data collection angles as equally spaced between 0-180 degrees.
    theta = tomopy.angles(ndata.shape[0])

    ndata = tomopy.minus_log(ndata)

    # Set binning and number of iterations
    binning = 8
    iters = 21

    print("Original", ndata.shape)
    ndata = tomopy.downsample(ndata, level=binning, axis=1)
#    ndata = tomopy.downsample(ndata, level=binning, axis=2)
    print("Processing:", ndata.shape)

    fdir = 'aligned' + '/noblur_iter_' + str(iters) + '_bin_' + str(binning) 

    print(fdir)
    cprj, sx, sy, conv = alignment.align_seq(ndata, theta, fdir=fdir, iters=iters, pad=(10, 10), blur=False, save=True, debug=True)

    np.save(fdir + '/shift_x', sx)
    np.save(fdir + '/shift_y', sy)

    # Write aligned projections as stack of TIFs.
    dxchange.write_tiff_stack(cprj, fname=fdir + '/radios/image')
예제 #7
0
파일: matt.py 프로젝트: Plasmonics/util
def reconstruct(sname, rot_center, ovlpfind, s_start, s_end):
    fname = dfolder + sname + '.h5'
    print(fname)
    start = s_start
    end = s_end
    chunks = 24
    num_sino = (end - start) // chunks
    for m in range(chunks):
        sino_start = start + num_sino * m
        sino_end = start + num_sino * (m + 1)
        start_read_time = time.time()
        proj, flat, dark, thetat = dxchange.read_aps_2bm(fname,
                                                         sino=(sino_start,
                                                               sino_end))
        print('   done read in %0.1f min' %
              ((time.time() - start_read_time) / 60))
        dark = proj[9001:9002]
        flat = proj[0:1]
        proj = proj[1:9000]
        theta = tomopy.angles(proj.shape[0], 0., 360.)
        proj = tomopy.sino_360_to_180(proj, overlap=ovlpfind, rotation='right')
        proj = tomopy.remove_outlier(proj, dif=0.4)
        proj = tomopy.normalize_bg(proj, air=10)
        proj = tomopy.minus_log(proj)
        center = rot_center
        start_ring_time = time.time()
        proj = tomopy.remove_stripe_fw(proj, wname='sym5', sigma=4, pad=False)
        proj = tomopy.remove_stripe_sf(proj, size=3)
        print('   done pre-process in %0.1f min' %
              ((time.time() - start_ring_time) / 60))
        start_phase_time = time.time()
        proj = tomopy.retrieve_phase(proj,
                                     pixel_size=detector_pixel_size_x,
                                     dist=sample_detector_distance,
                                     energy=energy,
                                     alpha=alpha,
                                     pad=True,
                                     ncore=None,
                                     nchunk=None)
        print('   done phase retrieval in %0.1f min' %
              ((time.time() - start_phase_time) / 60))
        start_recon_time = time.time()
        rec = tomopy.recon(proj,
                           theta,
                           center=center,
                           algorithm='gridrec',
                           filter_name='ramalk')
        tomopy.circ_mask(rec, axis=0, ratio=0.95)
        print("Reconstructed", rec.shape)
        dxchange.write_tiff_stack(rec,
                                  fname=dfolder + '/' + sname + '/' + sname,
                                  overwrite=True,
                                  start=sino_start)
        print('   Chunk reconstruction done in %0.1f min' %
              ((time.time() - start_recon_time) / 60))
    print("Done!")
예제 #8
0
파일: rec.py 프로젝트: decarlof/txm_util
def main(arg):

    parser = argparse.ArgumentParser()
    parser.add_argument("top", help="top directory where the tiff images are located: /data/")
    parser.add_argument("start", nargs='?', const=1, type=int, default=1, help="index of the first image: 1000 (default 1)")

    args = parser.parse_args()

    top = args.top
    index_start = int(args.start)

    template = os.listdir(top)[0]

    nfile = len(fnmatch.filter(os.listdir(top), '*.tif'))
    index_end = index_start + nfile
    ind_tomo = range(index_start, index_end)
    
    fname = top + template

    print (nfile, index_start, index_end, fname)


    # Select the sinogram range to reconstruct.
    start = 0
    end = 512
    sino=(start, end)

    # Read the tiff raw data.
    ndata = dxchange.read_tiff_stack(fname, ind=ind_tomo, slc=(sino, None))

    print(ndata.shape)
    binning = 8
    ndata = tomopy.downsample(ndata, level=binning, axis=1)
    print(ndata.shape)
    
    # Normalize to 1 using the air counts
    ndata = tomopy.normalize_bg(ndata, air=5)

    ## slider(ndata)

    # Set data collection angles as equally spaced between 0-180 degrees.
    theta = tomopy.angles(ndata.shape[0])
   
    rot_center = 960
    print("Center of rotation: ", rot_center)

    ndata = tomopy.minus_log(ndata)

    # Reconstruct object using Gridrec algorithm.
    rec = tomopy.recon(ndata, theta, center=rot_center, algorithm='gridrec')

    # Mask each reconstructed slice with a circle.
    rec = tomopy.circ_mask(rec, axis=0, ratio=0.95)

    # Write data as stack of TIFs.
    dxchange.write_tiff_stack(rec, fname='/local/dataraid/mark/rec/recon')
예제 #9
0
def main(arg):

    parser = argparse.ArgumentParser()
    parser.add_argument("top", help="top directory where the tiff images are located: /data/")
    parser.add_argument("start", nargs='?', const=1, type=int, default=1, help="index of the first image: 10001 (default 1)")

    args = parser.parse_args()

    top = args.top
    index_start = int(args.start)

    # Total number of images to read
    nfile = len(fnmatch.filter(os.listdir(top), '*.tif'))

    # Read the raw data
    rdata = ximage.load_raw(top, index_start)

    particle_bed_reference = ximage.particle_bed_location(rdata[0])
    print("Particle bed location: ", particle_bed_reference)
    
    # Cut the images to remove the particle bed
    cdata = rdata[:, 0:particle_bed_reference, :]

    # Find the image when the shutter starts to close
    dark_index = ximage.shutter_off(rdata)
    print("Shutter CLOSED on image: ", dark_index)

    # Find the images when the laser is on
    laser_on_index = ximage.laser_on(rdata, particle_bed_reference, alpha=1.00)
    print("Laser ON on image: ", laser_on_index)

    # Set the [start, end] index of the blocked images, flat and dark.
    laser_on_index = 47
    flat_range = [0, 1]
    data_range = [laser_on_index, dark_index]
    dark_range = [dark_index, nfile]

    flat = cdata[flat_range[0]:flat_range[1], :, :]
    proj = cdata[data_range[0]:data_range[1], :, :]
    dark = np.zeros((dark_range[1]-dark_range[0], proj.shape[1], proj.shape[2]))  

    # if you want to use the shutter closed images as dark uncomment this:
    #dark = cdata[dark_range[0]:dark_range[1], :, :]  

    ndata = tomopy.normalize(proj, flat, dark)
    ndata = tomopy.normalize_bg(ndata, air=ndata.shape[2]/2.5)
    ndata = tomopy.minus_log(ndata)
    ximage.slider(ndata[150:160:,:])

    ndata = ximage.scale_to_one(ndata)
    ndata = ximage.sobel_stack(ndata)
    ximage.slider(ndata[150:160:,:])
예제 #10
0
def preprocess(dat, blur=None, normalize_bg=False, minus_log=True):

    dat[np.abs(dat) < 2e-3] = 2e-3
    dat[dat > 1] = 1
    if normalize_bg:
        dat = tomopy.normalize_bg(dat)
    if minus_log:
        dat = -np.log(dat)
    dat[np.where(np.isnan(dat) == True)] = 0
    if blur is not None:
        dat = gaussian_filter(dat, blur)

    return dat
예제 #11
0
파일: am_01.py 프로젝트: decarlof/txm_util
def main(arg):

    parser = argparse.ArgumentParser()
    parser.add_argument("top", help="top directory where the tiff images are located: /data/")
    parser.add_argument("start", nargs='?', const=1, type=int, default=1, help="index of the first image: 10001 (default 1)")

    args = parser.parse_args()

    top = args.top
    index_start = int(args.start)

    template = os.listdir(top)[1]

    nfile = len(fnmatch.filter(os.listdir(top), '*.tif'))
    index_end = index_start + nfile
    ind_tomo = range(index_start, index_end)

    fname = top + template

    # Read the tiff raw data.
    rdata = dxchange.read_tiff_stack(fname, ind=ind_tomo)
    particle_bed_reference = particle_bed_location(rdata[0], plot=False)
    print("Particle bed location: ", particle_bed_reference)
    
    # Cut the images to remove the particle bed
    cdata = rdata[:, 0:particle_bed_reference, :]

    # Find the image when the shutter starts to close
    dark_index = shutter_off(rdata)
    print("shutter closes on image: ", dark_index)
    # Set the [start, end] index of the blocked images, flat and dark.
    flat_range = [0, 1]
    data_range = [48, dark_index]
    dark_range = [dark_index, nfile]

    # # for fast testing
    # data_range = [48, dark_index]

    flat = cdata[flat_range[0]:flat_range[1], :, :]
    proj = cdata[data_range[0]:data_range[1], :, :]
    dark = np.zeros((dark_range[1]-dark_range[0], proj.shape[1], proj.shape[2]))  

    # if you want to use the shutter closed images as dark uncomment this:
    #dark = cdata[dark_range[0]:dark_range[1], :, :]  

    ndata = tomopy.normalize(proj, flat, dark)
    ndata = tomopy.normalize_bg(ndata, air=ndata.shape[2]/2.5)
    ndata = tomopy.minus_log(ndata)
    sharpening(ndata)
    slider(ndata)
예제 #12
0
def flat_correction(proj, flat, dark, params):

    log.info('  *** normalization')
    if (params.flat_correction_method == 'standard'):
        data = tomopy.normalize(proj,
                                flat,
                                dark,
                                cutoff=params.normalization_cutoff)
        log.info('  *** *** ON %f cut-off' % params.normalization_cutoff)
    elif (params.flat_correction_method == 'air'):
        data = tomopy.normalize_bg(proj, air=params.air)
        log.info('  *** *** air %d pixels' % params.air)
    elif (params.flat_correction_method == 'none'):
        data = proj
        log.warning('  *** *** normalization is turned off')

    return data
예제 #13
0
 def __call__usingtomopy(self, input_ct_series, output_ct_series):
     print("Intensity fluctuation correction...")
     import tomopy, numpy as np
     data = [img.data for img in input_ct_series]
     data = np.array(data)
     data2 = tomopy.normalize_bg(data)
     data2[data2 < 0] = 0
     for i, identifier in enumerate(output_ct_series.identifiers):
         img = output_ct_series.getImage(identifier)
         # skip over existing result
         if output_ct_series.exists(identifier):
             print("%s already existed" % img)
             continue
         img.data = data2[i]
         img.save()
         continue
     print("done")
     return
예제 #14
0
 def __call__usingtomopy(self, input_ct_series, output_ct_series):
     print("Intensity fluctuation correction...")
     import tomopy, numpy as np
     data = [img.data for img in input_ct_series]
     data = np.array(data)
     data2 = tomopy.normalize_bg(data)
     data2[data2<0] = 0
     for i, identifier in enumerate(output_ct_series.identifiers):
         img = output_ct_series.getImage(identifier)
         # skip over existing result
         if output_ct_series.exists(identifier):
             print("%s already existed" % img)
             continue
         img.data = data2[i]
         img.save()
         continue
     print("done")
     return
예제 #15
0
파일: matt.py 프로젝트: decarlof/txm_util
def reconstruct(sname, rot_center, ovlpfind, s_start, s_end):
    fname = dfolder + sname + '.h5'
    print (fname)
    start = s_start  
    end =   s_end
    chunks = 24 
    num_sino = (end - start) // chunks
    for m in range(chunks):
        sino_start = start + num_sino * m
        sino_end = start + num_sino * (m + 1)
        start_read_time = time.time()
        proj, flat, dark, thetat = dxchange.read_aps_2bm(fname, sino=(sino_start, sino_end))
        print('   done read in %0.1f min' % ((time.time() - start_read_time)/60))
        dark = proj[9001:9002]
        flat = proj[0:1]
        proj = proj[1:9000]
        theta = tomopy.angles(proj.shape[0], 0., 360.)
        proj = tomopy.sino_360_to_180(proj, overlap=ovlpfind, rotation='right')
        proj = tomopy.remove_outlier(proj, dif=0.4)
        proj = tomopy.normalize_bg(proj, air=10)
        proj = tomopy.minus_log(proj)
        center = rot_center
        start_ring_time = time.time()
        proj = tomopy.remove_stripe_fw(proj, wname='sym5', sigma=4, pad=False)
        proj = tomopy.remove_stripe_sf(proj, size=3)
        print('   done pre-process in %0.1f min' % ((time.time() - start_ring_time)/60))
        start_phase_time = time.time()
        proj = tomopy.retrieve_phase(proj, pixel_size=detector_pixel_size_x, dist=sample_detector_distance, energy=energy, alpha=alpha, pad=True, ncore=None, nchunk=None)
        print('   done phase retrieval in %0.1f min' % ((time.time() - start_phase_time)/60))
        start_recon_time = time.time()
        rec = tomopy.recon(proj, theta, center=center, algorithm='gridrec', filter_name='ramalk')
        tomopy.circ_mask(rec, axis=0, ratio=0.95)
        print ("Reconstructed", rec.shape)
        dxchange.write_tiff_stack(rec, fname = dfolder + '/' + sname + '/' + sname, overwrite=True, start=sino_start)
        print('   Chunk reconstruction done in %0.1f min' % ((time.time() - start_recon_time)/60))
    print ("Done!")
예제 #16
0
def main(arg):

    parser = argparse.ArgumentParser()
    parser.add_argument(
        "top", help="top directory where the tiff images are located: /data/")
    parser.add_argument("start",
                        nargs='?',
                        const=1,
                        type=int,
                        default=1,
                        help="index of the first image: 1000 (default 1)")

    args = parser.parse_args()

    top = args.top
    index_start = int(args.start)

    template = os.listdir(top)[0]

    nfile = len(fnmatch.filter(os.listdir(top), '*.tif'))
    index_end = index_start + nfile
    ind_tomo = range(index_start, index_end)

    fname = top + template

    print(nfile, index_start, index_end, fname)

    # Select the sinogram range to reconstruct.
    start = 0
    end = 512
    sino = (start, end)

    # Read the tiff raw data.
    ndata = dxchange.read_tiff_stack(fname, ind=ind_tomo, slc=(sino, None))

    # Normalize to 1 using the air counts
    ndata = tomopy.normalize_bg(ndata, air=5)

    # Set data collection angles as equally spaced between 0-180 degrees.
    theta = tomopy.angles(ndata.shape[0])

    ndata = tomopy.minus_log(ndata)

    # Set binning and number of iterations
    binning = 8
    iters = 21

    print("Original", ndata.shape)
    ndata = tomopy.downsample(ndata, level=binning, axis=1)
    #    ndata = tomopy.downsample(ndata, level=binning, axis=2)
    print("Processing:", ndata.shape)

    fdir = 'aligned' + '/noblur_iter_' + str(iters) + '_bin_' + str(binning)

    print(fdir)
    cprj, sx, sy, conv = alignment.align_seq(ndata,
                                             theta,
                                             fdir=fdir,
                                             iters=iters,
                                             pad=(10, 10),
                                             blur=False,
                                             save=True,
                                             debug=True)

    np.save(fdir + '/shift_x', sx)
    np.save(fdir + '/shift_y', sy)

    # Write aligned projections as stack of TIFs.
    dxchange.write_tiff_stack(cprj, fname=fdir + '/radios/image')
 def evaluate(self):
     self.tomo.value = tomopy.normalize_bg(
         self.tomo.value,
         air=self.air.value,
         ncore=self.ncore.value,
         nchunk=self.nchunk.value)
예제 #18
0
import dxchange as dx

from netCDF4 import Dataset

if __name__ == '__main__':
    ## Set path (without file suffix) to the micro-CT data to reconstruct.
    fname = 'data_dir/sample'

    ## Import Data.
    proj, flat, dark, theta = dx.exchange.read_aps_13bm(fname, format = 'netcdf4')

    ## Flat-field correction of raw data.
    proj = tp.normalize(proj, flat = flat, dark = dark)

    ## Additional flat-field correction of raw data to negate need to mask.
    proj = tp.normalize_bg(proj, air = 10)

    ## Set rotation center.
    rot_center = tp.find_center_vo(proj)
    print('Center of rotation: ', rot_center)

    tp.minus_log(proj, out = proj)

    # Reconstruct object using Gridrec algorith.
    rec = tp.recon(proj, theta, center = rot_center, sinogram_order = False, algorithm = 'gridrec', filter_name = 'hann')
    rec = tp.remove_nan(rec)

    ## Writing data in netCDF3 .volume.
    ncfile = Dataset('filename.volume', 'w', format = 'NETCDF3_64BIT', clobber = True)
    NX = ncfile.createDimension('NX', rec.shape[2])
    NY = ncfile.createDimension('NY', rec.shape[1])
예제 #19
0
from netCDF4 import Dataset

if __name__ == '__main__':
    ## Set path (without file suffix) to the micro-CT data to reconstruct.
    fname = 'data_dir/sample'

    ## Import Data.
    proj, flat, dark, theta = dx.exchange.read_aps_13bm(fname,
                                                        format='netcdf4')

    ## Flat-field correction of raw data.
    proj = tp.normalize(proj, flat=flat, dark=dark)

    ## Additional flat-field correction of raw data to negate need to mask.
    proj = tp.normalize_bg(proj, air=10)

    ## Set rotation center.
    rot_center = tp.find_center_vo(proj)
    print('Center of rotation: ', rot_center)

    tp.minus_log(proj, out=proj)

    # Reconstruct object using Gridrec algorith.
    rec = tp.recon(proj,
                   theta,
                   center=rot_center,
                   sinogram_order=False,
                   algorithm='gridrec',
                   filter_name='hann')
    rec = tp.remove_nan(rec)
예제 #20
0
    exchange_rank = ExchangeRank
    data, white, dark = tomopy.io.exchange.read_aps_32id(file_name, 
                                                        exchange_rank, 
                                                        sino=(slice_first, slice_first+4))

    theta  = tomopy.angles(data.shape[0])
    
    # Xtomo object creation and pipeline of methods.
    ##d = tomopy.xtomo_dataset(log='debug')
    ##d.dataset(data, white, dark, theta)

    #if perform_norm: d.normalize() # flat & dark field correction
    if perform_norm: data = tomopy.normalize(data, white, dark)

    ##if drift_correct: d.correct_drift()
    if drift_correct: data = tomopy.normalize_bg(data)

    #d.median_filter(size=medfilt_size, axis=0) # Apply a median filter in the projection plane
    data = tomopy.median_filter(data, size=medfilt_size, axis=0)

    #if remove_stripe1: d.stripe_removal(level=stripe_lvl, sigma=sig, wname=Wname)
    if remove_stripe1: data = tomopy.remove_stripe_fw(data, level=stripe_lvl, wname=Wname, sigma=sig)

#    z = 3
#    eng = 31
#    pxl = 0.325e-4
#    rat = 5e-03
#    rat = 1e-03
    #d.phase_retrieval(dist=z, energy=eng, pixel_size=pxl, alpha=rat,padding=True)
    #data = tomopy.retrieve_phase(data, dist=z, energy=eng, pixel_size=pxl, alpha=rat,pad=True)
    
예제 #21
0
def preprocess_data(prj, flat, dark, FF_norm=flat_field_norm, remove_rings = remove_rings, medfilt_size=medfilt_size, FF_drift_corr=flat_field_drift_corr, downspling=binning):

    if FF_norm:
        # normalize the prj
        print('\n*** Applying flat field correction:') 
        start_norm_time = time.time()
        prj = tomopy.normalize(prj, flat, dark)
        print('   done in %0.3f min' % ((time.time() - start_norm_time)/60))

    if FF_drift_corr:
        print('\n*** Applying flat field drift correction:')
        start_norm_bg_time = time.time()
        prj = tomopy.normalize_bg(prj, air=100)
        print('   done in %0.3f min' % ((time.time() - start_norm_bg_time)/60))

    # Applying -log
    print('\n*** Applying -log:') 
    start_log_time = time.time()
    prj = tomopy.minus_log(prj)
    print('   done in %0.3f min' % ((time.time() - start_log_time)/60))

    prj = tomopy.misc.corr.remove_neg(prj, val=0.000)
    prj = tomopy.misc.corr.remove_nan(prj, val=0.000)
    prj[np.where(prj == np.inf)] = 0.000
#    prj[np.where(prj == 0)] = 0.000
    print('\n*** Min and max val in prj before recon: %0.3f, %0.3f'  % (np.min(prj), np.max(prj)))

    if remove_rings:
        # remove ring artefacts
        tmp = prj[-1,:,:] # use to fixe the bug of remove_stripe_ti
        print('\n*** Applying ring removal algo:') 
        start_ring_time = time.time()
        prj = tomopy.remove_stripe_ti(prj,2)
    #    prj = tomopy.remove_stripe_sf(prj,10); prj = tomopy.misc.corr.remove_neg(prj, val=0.000) # remove the neg values coming from remove_stripe_sf
        print('   done in %0.3f min' % ((time.time() - start_ring_time)/60))
        prj[-1,:,:] = tmp # fixe the bug of remove_stripe_ti

    if phase_retrieval:
        # phase retrieval
        prj = tomopy.prep.phase.retrieve_phase(prj,pixel_size=detector_pixel_size_x,dist=sample_detector_distance,energy=monochromator_energy,alpha=alpha,pad=True)


    # Filtering data with 2D median filter before downsampling and recon 
    if medfilt_size>1:
        start_filter_time = time.time()
        print('\n*** Applying median filter')
        #prj = tomopy.median_filter(prj,size=1)
        prj = ndimage.median_filter(prj,footprint=np.ones((1, medfilt_size, medfilt_size)))
        print('   done in %0.3f min' % ((time.time() - start_filter_time)/60))

    # Downsampling data:
    if downspling>0:
        print('\n** Applying downsampling')
        start_down_time = time.time()
        prj = tomopy.downsample(prj, level=binning)
        prj = tomopy.downsample(prj, level=binning, axis=1)
        print('   done in %0.3f min' % ((time.time() - start_down_time)/60))
        
    print('\n*** Shape of the data:'+str(np.shape(prj)))
    print('      Dimension of theta:'+str(np.shape(theta)))

    return prj
예제 #22
0
파일: rec.py 프로젝트: Plasmonics/util
def main(arg):

    parser = argparse.ArgumentParser()
    parser.add_argument(
        "top", help="top directory where the tiff images are located: /data/")
    parser.add_argument("start",
                        nargs='?',
                        const=1,
                        type=int,
                        default=1,
                        help="index of the first image: 1000 (default 1)")

    args = parser.parse_args()

    top = args.top
    index_start = int(args.start)

    template = os.listdir(top)[0]

    nfile = len(fnmatch.filter(os.listdir(top), '*.tif'))
    index_end = index_start + nfile
    ind_tomo = range(index_start, index_end)

    fname = top + template

    print(nfile, index_start, index_end, fname)

    # Select the sinogram range to reconstruct.
    start = 0
    end = 512
    sino = (start, end)

    # Read the tiff raw data.
    ndata = dxchange.read_tiff_stack(fname, ind=ind_tomo, slc=(sino, None))

    print(ndata.shape)
    binning = 8
    ndata = tomopy.downsample(ndata, level=binning, axis=1)
    print(ndata.shape)

    # Normalize to 1 using the air counts
    ndata = tomopy.normalize_bg(ndata, air=5)

    ## slider(ndata)

    # Set data collection angles as equally spaced between 0-180 degrees.
    theta = tomopy.angles(ndata.shape[0])

    rot_center = 960
    print("Center of rotation: ", rot_center)

    ndata = tomopy.minus_log(ndata)

    # Reconstruct object using Gridrec algorithm.
    rec = tomopy.recon(ndata, theta, center=rot_center, algorithm='gridrec')

    # Mask each reconstructed slice with a circle.
    rec = tomopy.circ_mask(rec, axis=0, ratio=0.95)

    # Write data as stack of TIFs.
    dxchange.write_tiff_stack(rec, fname='/local/dataraid/mark/rec/recon')