def main(): normalized = i3.normalize(ct_series, dfs, obs, workdir=os.path.join(workdir, 'normalization')) tilt_corrected = i3.correct_tilt(normalized, workdir=os.path.join( workdir, 'tilt-correction')) if_corrected = i3.correct_intensity_fluctuation( tilt_corrected, workdir=os.path.join(workdir, 'intensity-fluctuation-correction')) angles, sinograms = i3.build_sinograms(if_corrected, workdir=os.path.join( workdir, 'sinogram')) # take the middle part to calculate the center of rotation sino = [s.data for s in sinograms[900:1100]] sino = np.array(sino) proj = np.swapaxes(sino, 0, 1) rot_center = tomopy.find_center(proj, theta, emission=False, init=1024, tol=0.5) rot_center = rot_center[0] # reconstruct recon = i3.reconstruct(angles, sinograms, workdir=outdir, center=rot_center) return
def test(): normalized = i3.normalize(ct_series, dfs, obs, workdir=workdir) tilt_corrected = i3.correct_tilt(normalized, workdir=workdir) if_corrected = i3.correct_intensity_fluctuation(tilt_corrected, workdir=workdir) angles, sinograms = i3.build_sinograms(if_corrected, workdir=workdir) recon = i3.reconstruct(angles, sinograms, workdir=outdir) return
def main(): normalized = i3.normalize(ct_series, dfs, obs, workdir=os.path.join(workdir, 'normalization')) tilt_corrected = i3.correct_tilt(normalized, workdir=os.path.join(workdir, 'tilt-correction')) if_corrected = i3.correct_intensity_fluctuation(tilt_corrected, workdir=os.path.join(workdir, 'intensity-fluctuation-correction')) angles, sinograms = i3.build_sinograms(if_corrected, workdir=os.path.join(workdir, 'sinogram')) # take the middle part to calculate the center of rotation sino = [s.data for s in sinograms[900:1100]] sino= np.array(sino) proj = np.swapaxes(sino, 0, 1) rot_center = tomopy.find_center(proj, theta, emission=False, init=1024, tol=0.5) rot_center = rot_center[0] # reconstruct recon = i3.reconstruct(angles, sinograms, workdir=outdir, center=rot_center) return
def reconstruct( self, ct_series, workdir=None, outdir=None, rot_center=None, explore_rot_center=True): workdir = workdir or self.workdir; outdir = outdir or self.outdir theta = self.theta # preprocess angles, sinograms = i3.build_sinograms( ct_series, workdir=os.path.join(workdir, 'sinogram'), parallel = self.parallel_preprocessing, parallel_nodes = self.parallel_nodes) # take the middle part to calculate the center of rotation NSINO = len(sinograms) sino = [s.data for s in sinograms[NSINO//3: NSINO*2//3]] # sino = [s.data for s in sinograms] sino= np.array(sino) proj = np.swapaxes(sino, 0, 1) import tomopy X = proj.shape[-1] DEVIATION = 40 # max deviation of rot center from center of image if explore_rot_center: print("* Exploring rotation center using tomopy...") tomopy.write_center( proj.copy(), theta, cen_range=[X//2-DEVIATION, X//2+DEVIATION, 1.], dpath=os.path.join(workdir, 'tomopy-findcenter'), emission=False) if rot_center is None: print("* Computing rotation center using 180deg pairs...") from .tilt import find_rot_center rot_center = find_rot_center.find( ct_series, workdir=os.path.join(workdir, 'find-rot-center')) print('* Rotation center: %s' % rot_center) open(os.path.join(workdir, 'rot_center'), 'wt').write(str(rot_center)) # reconstruct if self.vertical_range: sinograms = sinograms[self.vertical_range] recon = i3.reconstruct( angles, sinograms, workdir=outdir, center=rot_center, nodes=self.parallel_nodes) return
def reconstruct( self, ct_series, workdir=None, outdir=None, rot_center=None, explore_rot_center=True, outfilename_template=None, remove_rings_at_sinograms=False, mirror=True, **kwds): workdir = workdir or self.workdir; outdir = outdir or self.outdir theta = self.theta # preprocess angles, sinograms = i3.build_sinograms( ct_series, workdir=os.path.join(workdir, 'sinogram'), parallel = self.parallel_preprocessing, parallel_nodes = self.parallel_nodes) # take the middle part to calculate the center of rotation NSINO = len(sinograms) sino = [s.data for s in sinograms[NSINO//3: NSINO*2//3]] # sino = [s.data for s in sinograms] sino= np.array(sino) proj = np.swapaxes(sino, 0, 1) import tomopy X = proj.shape[-1] DEVIATION = 40 # max deviation of rot center from center of image if explore_rot_center: print("* Exploring rotation center using tomopy...") dpath=os.path.join(workdir, 'tomopy-findcenter') if not os.path.exists(dpath): # skip if already done tomopy.write_center( proj.copy(), theta, cen_range=[X//2-DEVIATION, X//2+DEVIATION, 1.], dpath=dpath, emission=False) if rot_center is None: print("* Computing rotation center using 180deg pairs...") from .tilt import find_rot_center rot_center = find_rot_center.find( ct_series, workdir=os.path.join(workdir, 'find-rot-center')) print('* Rotation center: %s' % rot_center) self.rot_center = rot_center open(os.path.join(workdir, 'rot_center'), 'wt').write(str(rot_center)) # reconstruct if self.vertical_range: sinograms = sinograms[self.vertical_range] self.r.sinograms = sinograms # sometimes the rotation angles and the stacking sequence coulb be not in the right convention if mirror: angles = -np.array(angles) # reconstruct using original sinograms recon = i3.reconstruct( angles, sinograms, workdir=outdir, filename_template=outfilename_template, center=rot_center, nodes=self.parallel_nodes, **kwds) self.r.reconstructed = recon # reconstruct using rar filtered sinograms if remove_rings_at_sinograms: if remove_rings_at_sinograms is True: remove_rings_at_sinograms = {} self.r.rar_sino = sinograms = i3.ring_artifact_removal_Ketcham( sinograms, workdir=os.path.join(workdir, 'rar_sinograms'), parallel = self.parallel_preprocessing, **remove_rings_at_sinograms) recon = i3.reconstruct( angles, sinograms, workdir=os.path.join(outdir, 'rar_sinograms'), filename_template=outfilename_template, center=rot_center, nodes=self.parallel_nodes, **kwds) self.r.reconstructed_using_rar_sinograms = recon return recon