def main(): # only used to locate the wavelenght.dpt and angle.dpt files raw_tiff_base_name = "/local/dataraid/databank/dataExchange/microCT/SRC/raw/FPA_16_18_18_TOMO_243_Fiber_2500_50_50_" hdf5_base_name = "/local/dataraid/databank/dataExchange/microCT/SRC/dx/FPA_16_18_18_TOMO_243_Fiber_2500_50_50_" log_file = raw_tiff_base_name + "wavelength.dpt" angle_file = raw_tiff_base_name + "angle.dpt" dir_name = os.path.dirname(hdf5_base_name) sample_name_prefix = os.path.basename(hdf5_base_name) print dir_name print sample_name_prefix file = open(log_file, 'r') for line in file: linelist=line.split(",") hdf5_file_name = hdf5_base_name+linelist[0]+"cm-1.h5" sample_name = hdf5_base_name+linelist[0]+"cm-1" # set to read slices between slices_start and slices_end # if omitted all data set will be converted slices_start = 30 slices_end = 36 # to create a data exchange file use convert_SRC.py module, data, white, dark, theta = tomopy.xtomo_reader(hdf5_file_name, slices_start=slices_start, slices_end=slices_end) # TomoPy xtomo object creation and pipeline of methods. d = tomopy.xtomo_dataset(log='debug') d.dataset(data, white, dark, theta) d.normalize() d.correct_drift() #d.optimize_center() #d.phase_retrieval() #d.correct_drift() d.center=64 d.gridrec() # Write to stack of TIFFs. rec_name = dir_name + "/rec/" + sample_name_prefix + linelist[0] + "cm-1" # Write to stack of TIFFs. mydata = ex.Export() mydata.xtomo_tiff(data = d.data_recon, output_file = rec_name, axis=0) file.close()
def hdf5_to_recon(inputDir = '.', inputFileName='out.h5', startSlice=None, endSlice=None, outputDir='./recon', outBase = 'recon_', center=None): # Make the output directory if it doesn't already exist. if not os.path.exists(outputDir): os.makedirs(outputDir) # This is the path to the input HDF5 file. inputFilePath = os.path.join(inputDir, inputFileName) # This is the path to the output files outputPath = os.path.join(outputDir, outBase) # Read HDF5 file. data, white, dark, theta = tomopy.xtomo_reader(inputFilePath, slices_start=startSlice, slices_end=endSlice) # Xtomo object creation and pipeline of methods. d = tomopy.xtomo_dataset(log='debug') d.dataset(data, white, dark, theta) d.normalize() d.correct_drift() d.phase_retrieval() d.correct_drift() # Appliy a median filter to the (images?) to improve the chance of success of the center finder. d.median_filter() # Find the center of rotation if center == None: d.optimize_center() else: d.center=center # Do the tomographic reconstruction d.gridrec() # Write to stack of TIFFs. tomopy.xtomo_writer(d.data_recon, outputPath, axis=0, x_start=startSlice)
def main(): # read a series of tiff # oster: pj: from 0 -> 1440; bf from 0 -> 19; df from 0 -> 19 file_name = '/local/dataraid/databank/PetraIII/2011_KW16_oster/oster02_0001/scan_0002/ccd/pco01/ccd_.tif' dark_file_name = '/local/dataraid/databank/PetraIII/2011_KW16_oster/oster02_0001/scan_0000/ccd/pco01/ccd_.tif' white_file_name = '/local/dataraid/databank/PetraIII/2011_KW16_oster/oster02_0001/scan_0001/ccd/pco01/ccd_.tif' hdf5_file_name = '/local/dataraid/databank/dataExchange/microCT/PetraIII_oster02_0001.h5' sample_name = 'PetraIII P06 oster02_0001' projections_start = 0 projections_end = 1441 white_start = 0 white_end = 20 white_step = 1 dark_start = 0 dark_end = 20 dark_step = 1 # to reconstruct slices from slices_start to slices_end # if omitted all data set is recontructed slices_start = 1001 slices_end = 1501 # mydata = dx.Import() # # Read series of images # data, white, dark, theta = mydata.series_of_images(file_name, # projections_start = projections_start, # projections_end = projections_end, # slices_start = slices_start, # slices_end = slices_end, # #projections_angle_range=360, # white_file_name = white_file_name, # white_start = white_start, # white_end = white_end, # white_step = white_step, # dark_file_name = dark_file_name, # dark_start = dark_start, # dark_end = dark_end, # dark_step = dark_step, # sample_name = sample_name, # projections_digits = 4, # projections_zeros = True, # log='INFO' # ) # if you have already created a data exchange file using convert_PetraIII.py module, # comment the call above and read the data set as data exchange using: # Read HDF5 file. data, white, dark, theta = tomopy.xtomo_reader(hdf5_file_name, slices_start=slices_start, slices_end=slices_end ) # TomoPy xtomo object creation and pipeline of methods. d = tomopy.xtomo_dataset(log='debug') d.dataset(data, white, dark, theta) d.normalize() d.correct_drift() #d.optimize_center() d.phase_retrieval(pixel_size=0.9e-4, dist=6.9, energy=15.25) #d.correct_drift() d.center=1872.87890625 d.gridrec() # Write to stack of TIFFs. # tomopy.xtomo_writer(d.data_recon, 'tmp/oster02_0001_', axis=0) tomopy.xtomo_writer(d.data_recon, 'tmp/oster02_0001_int_', axis=0, x_start = 1001, overwrite=True, dtype='uint8', data_min=-0.0001, data_max=0.0003)
######################### you input section - End ######################### ######################### initialization - Start ######################### file_name = os.path.join(data_dir, file) output_file = data_dir+'/recon_'+file.split(".")[-2]+'/recon_'+file.split(".")[-2] +'_' log_filename = data_dir+'/recon_'+file.split(".")[-2]+'/'+file.split(".")[-2] +'.log' # object d is for containing data that will be used for phase retrieval d = tomopy.xtomo_dataset(log='debug') # object d_recon is for containing data for reconstruction d_recon = tomopy.xtomo_dataset(log='debug') ######################### initialization - End ######################### ########################## finding num_overlap_pixels - Start ######################### #### phase retrieval - Start #### data, white, dark, theta = tomopy.xtomo_reader(file_name,slices_start=300,slices_end=310,white_start=3,white_end=9,dark_start=3,dark_end=9) data[0,:,:] = data[1,:,:] # in case the first projection image is corrupted d.dataset(data, white, dark, theta) d.normalize() d.stripe_removal(wname="db5",level=10,sigma=4.) data_size = d.data.shape d.phase_retrieval(dist=z, energy=eng, pixel_size=pxl, alpha=rat,padding=True) data_tem = d.data #### phase retrieval - End #### #### trial recons - Start #### for ii in range(nop_start,nop_end): d.dataset(data_tem,np.ones([d.data.shape[1],d.data.shape[2]]),None,None) d.correct_fov(num_overlap_pixels=ii) # tomopy.xtomo_writer(d.data[:,5:7,:], output_file+'sinogram_num_overlap_pixel_'+str(ii)+'_', axis=1,x_start=0,overwrite = True)
def main(): file_name = '/local/dataraid/databank/als/data/raw/sacarroll/20140731_001306_2477A_x00y08/20140731_001306_2477A_x00y08_0000_.tif' dark_file_name = '/local/dataraid/databank/als/data/raw/sacarroll/20140731_001306_2477A_x00y08/20140731_001306_2477A_x00y08drk_.tif' white_file_name = '/local/dataraid/databank/als/data/raw/sacarroll/20140731_001306_2477A_x00y08/20140731_001306_2477A_x00y08bak_.tif' log_file = '/local/dataraid/databank/als/data/raw/sacarroll/20140731_001306_2477A_x00y08/20140731_001306_2477A_x00y08.sct' hdf5_file_name = '/local/dataraid/databank/dataExchange/microCT/ALS_20140731.h5' verbose = True # start = time.clock() # Read ALS log file data file = open(log_file, 'r') for line in file: if '-scanner' in line: Source = re.sub(r'-scanner ', "", line) if verbose: print 'Facility', Source if '-object' in line: Sample = re.sub(r'-object ', "", line) if verbose: print 'Sample', Sample if '-senergy' in line: Energy = re.findall(r'\d+.\d+', line) if verbose: print 'Energy', Energy[0] if '-scurrent' in line: Current = re.findall(r'\d+.\d+', line) if verbose: print 'Current', Current[0] if '-nangles' in line: Angles = re.findall(r'\d+', line) if verbose: print 'Angles', Angles[0] if '-i0cycle' in line: WhiteStep = re.findall(r'\s+\d+', line) if verbose: print 'White Step', WhiteStep[0] if '-num_bright_field' in line: WhiteEnd = re.findall(r'\d+', line) if '-num_dark_fields' in line: DarkEnd = re.findall(r'\d+', line) file.close() dark_start = 0 dark_end = int(DarkEnd[0]) dark_step = 1 white_start = 0 white_end = int(WhiteEnd[0]) white_step = int(WhiteStep[0]) projections_start = 0 projections_end = int(Angles[0]) # set to convert slices between slices_start and slices_end # if omitted all data set will be converted slices_start = 245 slices_end = 265 # mydata = dx.Import() # Read series of images # data, white, dark, theta = mydata.series_of_images(file_name = file_name, # projections_start = projections_start, # projections_end = projections_end, ## slices_start = slices_start, ## slices_end = slices_end, # white_file_name = white_file_name, # white_start = white_start, # white_end = white_end, # dark_file_name = dark_file_name, # dark_start = dark_start, # dark_end = dark_end, # projections_digits = 4, # log='INFO' # ) start = time.clock() # if you have already created a data exchange file using convert_SLS.py module, # comment the call above and read the data set as data exchange # Read HDF5 file. data, white, dark, theta = tomopy.xtomo_reader(hdf5_file_name, slices_start=slices_start, slices_end=slices_end) elapsed = (time.clock() - start) print "Total Time to read raw files:", elapsed # TomoPy xtomo object creation and pipeline of methods. d = tomopy.xtomo_dataset(log='debug') d.dataset(data, white, dark, theta) d.normalize() d.correct_drift() #d.optimize_center() #d.phase_retrieval() #d.correct_drift() d.center=1282.5 d.gridrec() # Write to stack of TIFFs. tomopy.xtomo_writer(d.data_recon, 'tmp/ALS_new', axis=0)
# -*- coding: utf-8 -*- import tomopy file_name = '/local/data/Tapuia_dentary_ant3_M_200mm_4.hdf5' slices_start = 300 chunk_size = 32 # keep it reasoably large depending on the available memory for m in range(4): # change range manually 4*32 slices will be reconstructed starting from 300 data, white, dark, theta = tomopy.xtomo_reader(file_name, projections_start=1, slices_start=slices_start, slices_end=slices_start+chunk_size) d = tomopy.xtomo_dataset(log='debug') d.dataset(data, white, dark, theta=theta) d.zinger_removal(zinger_level=500, median_width=5) d.normalize(negvals=1, cutoff=1) d.stripe_removal() d.center=1013.90625 d.gridrec() d.apply_mask(ratio=0.95) # use the first chunks min max value for all chunks if m == 0: data_min = d.data_recon.min() data_max = d.data_recon.max() tomopy.xtomo_writer(d.data_recon, 'tmp/test/rec_', dtype='uint16', axis=0, x_start=slices_start, data_min=data_min, data_max=data_max) slices_start += chunk_size
# -*- coding: utf-8 -*- import tomopy # Read HDF5 file. data, white, dark, theta = tomopy.xtomo_reader('demo/data.h5', slices_start=0, slices_end=16) # Xtomo object creation and pipeline of methods. d = tomopy.xtomo_dataset(log='debug') d.dataset(data, white, dark, theta) d.normalize() d.correct_drift() d.phase_retrieval() d.correct_drift() d.center = 661.5 d.gridrec() # Write to stack of TIFFs. tomopy.xtomo_writer(d.data_recon, 'tmp/test_', axis=0)
RingW = 10 # for ring artifact removal M. Rivers algo chunk = 6 # number of data chunks for the reconstruction ExchangeRank = 0 # exchange rank corresponding to the dataset ######################################################################################################## print '\n#### Processing '+file_name #### for 1 slice reconstruction: #------------------------------- if 1: # slice_first = 1000 # slice_last = 1400 # Read HDF5 file. data, white, dark, theta = tomopy.xtomo_reader(file_name, exchange_rank = ExchangeRank, slices_start=slice_first, slices_end=slice_last) # Manage the missing angles: data_size = np.shape(data) theta = np.linspace(0,180,data_size[0]) data = np.concatenate((data[0:miss_angles[0],:,:], data[miss_angles[1]+1:-1,:,:]), axis=0) theta = np.concatenate((theta[0:miss_angles[0]], theta[miss_angles[1]+1:-1])) # Xtomo object creation and pipeline of methods. # d = tomopy.xtomo_dataset(log='debug') d = tomopy.xtomo_dataset(log='debug') d.dataset(data, white, dark, theta) if perform_norm: d.normalize() # flat & dark field correction if drift_correct: d.correct_drift()
def main(): # read a series of tiff # oster: pj: from 0 -> 1440; bf from 0 -> 19; df from 0 -> 19 file_name = '/local/dataraid/databank/PetraIII/2011_KW16_oster/oster02_0001/scan_0002/ccd/pco01/ccd_.tif' dark_file_name = '/local/dataraid/databank/PetraIII/2011_KW16_oster/oster02_0001/scan_0000/ccd/pco01/ccd_.tif' white_file_name = '/local/dataraid/databank/PetraIII/2011_KW16_oster/oster02_0001/scan_0001/ccd/pco01/ccd_.tif' hdf5_file_name = '/local/dataraid/databank/dataExchange/microCT/PetraIII_oster02_0001.h5' sample_name = 'PetraIII P06 oster02_0001' projections_start = 0 projections_end = 1441 white_start = 0 white_end = 20 white_step = 1 dark_start = 0 dark_end = 20 dark_step = 1 # to reconstruct slices from slices_start to slices_end # if omitted all data set is recontructed slices_start = 1001 slices_end = 1501 # mydata = dx.Import() # # Read series of images # data, white, dark, theta = mydata.series_of_images(file_name, # projections_start = projections_start, # projections_end = projections_end, # slices_start = slices_start, # slices_end = slices_end, # #projections_angle_range=360, # white_file_name = white_file_name, # white_start = white_start, # white_end = white_end, # white_step = white_step, # dark_file_name = dark_file_name, # dark_start = dark_start, # dark_end = dark_end, # dark_step = dark_step, # sample_name = sample_name, # projections_digits = 4, # projections_zeros = True, # log='INFO' # ) # if you have already created a data exchange file using convert_PetraIII.py module, # comment the call above and read the data set as data exchange using: # Read HDF5 file. data, white, dark, theta = tomopy.xtomo_reader(hdf5_file_name, slices_start=slices_start, slices_end=slices_end) # TomoPy xtomo object creation and pipeline of methods. d = tomopy.xtomo_dataset(log='debug') d.dataset(data, white, dark, theta) d.normalize() d.correct_drift() #d.optimize_center() d.phase_retrieval(pixel_size=0.9e-4, dist=6.9, energy=15.25) #d.correct_drift() d.center = 1872.87890625 d.gridrec() # Write to stack of TIFFs. # tomopy.xtomo_writer(d.data_recon, 'tmp/oster02_0001_', axis=0) tomopy.xtomo_writer(d.data_recon, 'tmp/oster02_0001_int_', axis=0, x_start=1001, overwrite=True, dtype='uint8', data_min=-0.0001, data_max=0.0003)
# -*- coding: utf-8 -*- import tomopy #main is needed on windows if __name__ == '__main__': # Read HDF5 file. data, white, dark, theta = tomopy.xtomo_reader('demo/data.h5', slices_start=0, slices_end=16) # Xtomo object creation and pipeline of methods. d = tomopy.xtomo_dataset(log='debug') d.dataset(data, white, dark, theta) d.normalize() d.correct_drift() d.phase_retrieval() d.correct_drift() d.center = 661.5 d.gridrec() # Write to stack of TIFFs. tomopy.xtomo_writer(d.data_recon, 'tmp/test_', axis=0)
chunk_size = 60 margin_slices = 20 num_chunk = np.int(num_proj/chunk_size) + 1 if num_proj == chunk_size: num_chunk = 1 z = 15 eng = 27.4 #pxl = 5.5e-4 #for 2X lens pxl = 2.2e-4 #for 5X lens rat = 5e-04 center = 1034 ##________________________rescale_for_16-bit_image____________________ data, white, dark, theta = tomopy.xtomo_reader(file_name, projections_start=1, slices_start=(num_proj/3), slices_end=(num_proj/3)+chunk_size) d = tomopy.xtomo_dataset(log='debug') d.dataset(data, white, dark, theta=theta) d.zinger_removal(zinger_level=500, median_width=5) d.normalize(negvals=1, cutoff=1) d.stripe_removal() d.center=center d.gridrec() d.apply_mask(ratio=0.95) data_min = d.data_recon.min() data_max = d.data_recon.max() ##________________________reconstruction______________________________ for ii in xrange(num_chunk):
# d = tomopy.xtomo_dataset(log='debug') # d.dataset(data, white, dark, theta=theta) # d.zinger_removal(zinger_level=500, median_width=5) # d.normalize(negvals=1, cutoff=1) # # d.stripe_removal() # d.phase_retrieval(alpha=0.005) # d.center=1010 # d.gridrec(ringWidth=30) # d.apply_mask(ratio=0.95) # tomopy.xtomo_writer(d.data_recon, 'tmp/Tapuia_dentary_ant2_200mm_4_/rec_', dtype='uint16', axis=0) file_name = '/local/data/Tapuiasaurus_dentary_ant_200mm_1.hdf5' data, white, dark, theta = tomopy.xtomo_reader(file_name, projections_start=1, slices_start=300, slices_end=332) d = tomopy.xtomo_dataset(log='debug') d.dataset(data, white, dark, theta=theta) d.zinger_removal(zinger_level=500, median_width=5) d.normalize(negvals=1, cutoff=1) d.stripe_removal() d.phase_retrieval(alpha=0.005) d.center=1010 d.gridrec(ringWidth=0) d.apply_mask(ratio=0.95) tomopy.xtomo_writer(d.data_recon, 'tmp/Tapuiasaurus_dentary_ant_200mm_1/rec_', dtype='uint16', axis=0)
level = 1 # 2^level binning RingW = 10 # for ring artifact removal M. Rivers algo chunk = 6 # number of data chunks for the reconstruction ExchangeRank = 0 # exchange rank corresponding to the dataset ######################################################################################################## print '\n#### Processing ' + file_name #### for 1 slice reconstruction: #------------------------------- if 1: # slice_first = 1000 # slice_last = 1400 # Read HDF5 file. data, white, dark, theta = tomopy.xtomo_reader(file_name, exchange_rank=ExchangeRank, slices_start=slice_first, slices_end=slice_last) # Manage the missing angles: data_size = np.shape(data) theta = np.linspace(0, 180, data_size[0]) data = np.concatenate( (data[0:miss_angles[0], :, :], data[miss_angles[1] + 1:-1, :, :]), axis=0) theta = np.concatenate( (theta[0:miss_angles[0]], theta[miss_angles[1] + 1:-1])) # Xtomo object creation and pipeline of methods. # d = tomopy.xtomo_dataset(log='debug') d = tomopy.xtomo_dataset(log='debug') d.dataset(data, white, dark, theta)
center = 1028 for ii in xrange(num_chunk): if ii == 0: SliceStart = offset + ii*chunk_size SliceEnd = offset + (ii+1)*chunk_size else: SliceStart = offset + ii*(chunk_size-margin_slices) SliceEnd = offset + SliceStart + chunk_size if SliceEnd > (offset+num_proj): SliceEnd = offset+num_proj data, white, dark, theta = tomopy.xtomo_reader(file_name,slices_start=SliceStart,slices_end=SliceEnd,white_start=3,white_end=9,dark_start=3,dark_end=9) data[0,:,:] = data[1,:,:] d.dataset(data, white, dark, theta) d.zinger_removal(median_width=10) d.normalize() d.correct_drift(10) d.stripe_removal(wname="sym16",level=10,sigma=4) d.phase_retrieval(dist=z, energy=eng, pixel_size=pxl, alpha=rat,padding=True) d.center = center d.gridrec() tomopy.xtomo_writer(d.data_recon[np.int(margin_slices/2):(SliceEnd-SliceStart-np.int(margin_slices/2)),:,:], output_file, axis=0,dtype='float32', x_start=SliceStart+np.int(margin_slices/2),overwrite = True) d.FLAG_THETA = False
def recon_180(data_dir='.', file = 'out.h5', output_dir='/Volumes/Socha_MP8/', num_proj=1800, startSlice=None, endSlice=None, z=15, eng=27.4, lens=2, center=None): ##_________________________inputs_and_parameters_______________________ file_name = os.path.join(data_dir, file) output_file = output_dir+'/recon_'+file.split(".")[-2]+'/recon_'+file.split(".")[-2] +'_' d = tomopy.xtomo_dataset(log='debug') # Program does not complete a sample if actual number of slices is input. This somewhat arbitrary scaled value seems to work well. #num_proj = (3/2)*num_proj # These values work well with the computer's available memory and produce quality images. chunk_size = 60 margin_slices = 20 # Define pixel size from function argument lens. pxl = 0 if lens == 2: pxl = 5.5e-4 #for 2X lens elif lens == 5: pxl = 2.2e-4 #for 5X lens rat = 5e-04 num_chunk = np.int(num_proj/chunk_size) + 1 if num_proj == chunk_size: num_chunk = 1 #Set defalt start and end slice values. if endSlice == None: endSlice = num_proj if startSlice == None: startSlice=0 offset = startSlice else: offset = startSlice - (margin_slices/2) ##________________________rescale_for_16-bit_image____________________ data, white, dark, theta = tomopy.xtomo_reader(file_name, projections_start=1, slices_start=(num_proj/2), slices_end=(num_proj/2)+chunk_size) d = tomopy.xtomo_dataset(log='debug') d.dataset(data, white, dark, theta=theta) #d.zinger_removal(zinger_level=500, median_width=5) d.normalize(negvals=1, cutoff=1) # Helps minimize ring artifacts. d.stripe_removal() # Finds center of rotation if center == None: d.optimize_center(ratio=1) else: d.center=center d.gridrec() data_min = d.data_recon.min() data_max = d.data_recon.max() ##________________________reconstruction______________________________ for ii in xrange(num_chunk): if ii == 0: SliceStart = offset + ii*chunk_size SliceEnd = offset + (ii+1)*chunk_size else: SliceStart = offset + ii*(chunk_size-margin_slices) SliceEnd = offset + SliceStart + chunk_size if SliceEnd >= (endSlice-(margin_slices/2)) and SliceEnd < (endSlice-margin_slices+chunk_size): SliceEnd = (endSlice-(margin_slices/2)) if SliceEnd >= (endSlice-margin_slices+chunk_size): break data, white, dark, theta = tomopy.xtomo_reader(file_name,slices_start=SliceStart,slices_end=SliceEnd,white_start=3,white_end=9,dark_start=3,dark_end=9) data[0,:,:] = data[1,:,:] d.dataset(data, white, dark, theta) #d.zinger_removal(median_width=10) d.normalize() d.correct_drift(10) d.stripe_removal(wname="sym16",level=11,sigma=2) d.phase_retrieval(dist=z, energy=eng, pixel_size=pxl, alpha=rat,padding=True) # Finds center of rotation if center == None: d.optimize_center(ratio=0.8) else: d.center=center d.gridrec() d.apply_mask(ratio=0.95) #data[0,:,:] = data[1,:,:] #d = tomopy.xtomo_dataset(log='debug') #d.dataset(data, white, dark, theta) ##d.zinger_removal(median_width=15,zinger_level=200) #d.normalize() ##d.stripe_removal(wname="sym16",level=10,sigma=2) ##d.stripe_removal(level=10,sigma=1) #d.phase_retrieval(dist=z, energy=eng, pixel_size=pxl, alpha=rat,padding=True) ##d.stripe_removal(wname="sym16",level=10,sigma=4) #data_size = d.data.shape ##d.median_filter(10) ##d.optimize_center(ratio=0.3) ##print d.center tomopy.xtomo_writer(d.data_recon[np.int(margin_slices/2):(SliceEnd-SliceStart-np.int(margin_slices/2)),:,:], output_file, dtype='unit16', axis=0, x_start=SliceStart+np.int(margin_slices/2), data_min=data_min, data_max=data_max, overwrite=True) d.FLAG_THETA = False print 'Finished reconstructing slices from ' + file