def test_dfi_reconstruction(self): mat_rec1 = reco.dfi_reconstruction(self.sino_180, self.center, apply_log=False) num1 = np.max(np.abs(self.mat - mat_rec1)) mat_rec2 = reco.dfi_reconstruction(self.sino_360, self.center, angles=np.deg2rad(self.angles), apply_log=False) num2 = np.max(np.abs(self.mat - mat_rec2)) self.assertTrue(num1 <= 0.1 and num2 <= 0.1)
# Generate a sinogram with flat-field correction and blob removal. # Angles corresponding to this sinogram also is generated. index = max_index // 2 print("2 -> Generate a circular sinogram from the helical data") (sino_360, angle_sino) = conv.generate_sinogram_helical_scan(index, proj_data, num_proj, pixel_size, y_start, y_stop, pitch, scan_type=scan_type, angles=angles, flat=flat_field, dark=dark_field, mask=blob_mask, crop=(10,0,0,0)) print("3 -> Find the center of rotation, overlap-side, and overlap area between two halves of a 360-degree sinogram") (center0, overlap, side,_) = calc.find_center_360(sino_360, 100) print("Center-of-rotation: {0}. Side: {1} (0->'left', 1->'right'). Overlap: {2}".format(center0, side, overlap)) # Convert the 360-degree sinogram to the 180-degree sinogram. sino_180, center1 = conv.convert_sinogram_360_to_180(sino_360, center0) # Remove partial ring artifacts sino_180 = remo.remove_stripe_based_sorting(sino_180, 15) # Remove zingers sino_180 = remo.remove_zinger(sino_180, 0.08) # Denoising sino_180 = filt.fresnel_filter(sino_180, 250, 1) # Perform recosntruction img_rec = reco.dfi_reconstruction(sino_180, center1, apply_log=True) ## Use gpu for fast reconstruction # img_rec = reco.fbp_reconstruction(sino_180, center1, apply_log=True, gpu=True) losa.save_image(output_base + "/reconstruction/sino_360.tif", sino_360) losa.save_image(output_base + "/reconstruction/sino_180.tif", sino_180) losa.save_image(output_base + "/reconstruction/recon_image.tif", img_rec) print("!!! Done !!!")
data[proj_idx[0]:proj_idx[-1], index,:], flat_field[index, :], dark_field[index, :]) losa.save_image(output_base + "/sinogram/sinogram_mid.tif", sinogram) # Calculate the center-of-rotation by searching around the middle width of # the sinogram (radius=50). print("4 -> Calculate the center-of-rotation") # center = calc.find_center_vo(sinogram, width//2-50, width//2+50) center = calc.find_center_vo(sinogram) print("Center-of-rotation is {}".format(center)) # Perform reconstruction and save the result. # Users can choose CPU-based methods as follows thetas = angles[proj_idx[0]:proj_idx[-1]]*np.pi/180 # # DFI method, a built-in function: print("5 -> Perform reconstruction without artifact removal methods") img_rec = reco.dfi_reconstruction(sinogram, center, angles=thetas, apply_log=True) # # FBP-CPU method, a built-in function: # img_rec = reco.fbp_reconstruction(sinogram, center, angles=thetas, apply_log=True, gpu=False) # # # Gridrec method in Tomopy (Tomopy must be installed before use): # img_rec = reco.gridrec_reconstruction(sinogram, center, apply_log=True, ratio=1.0) # # # If GPU is available: # # # FBP-GPU method, a built-in function: # img_rec = reco.fbp_reconstruction(sinogram, center, angles=thetas, apply_log=True, gpu=True) # # # FBP-GPU method in Astra (Astra must be installed before use): # img_rec = reco.astra_reconstruction(sinogram, center, apply_log=True, ratio=1.0,method="FBP_CUDA") losa.save_image(output_base + "/reconstruction/recon_mid.tif", img_rec)
# Where to save the outputs output_base = "E:/tmp/output/" size = 1024 # Generate a built-in phantom phantom = sim.make_face_phantom(size) losa.save_image(output_base + "/face_phantom.tif", phantom) angles = np.linspace(0.0, 180.0, size) * np.pi / 180.0 # Generate sinogram sinogram = sim.make_sinogram(phantom, angles) losa.save_image(output_base + "/sinogram.tif", sinogram) # Find center of rotation center = calc.find_center_vo(sinogram) # Reconstruct using the DFI method rec_image = reco.dfi_reconstruction(sinogram, center, apply_log=False) losa.save_image(output_base + "/recon_dfi.tif", rec_image) # Reconstruct using the FBP (GPU) method rec_image = reco.fbp_reconstruction(sinogram, center, apply_log=False) losa.save_image(output_base + "/recon_fbp.tif", rec_image) # Convert to X-ray image sinogram = sim.convert_to_Xray_image(sinogram) # Add noise sinogram = sim.add_noise(sinogram, noise_ratio=0.1) # Add stripe artifacts sinogram = sim.add_stripe_artifact(sinogram, 2, size // 4, strength_ratio=0.3, stripe_type="partial") sinogram = sim.add_stripe_artifact(sinogram, 1, size // 3, strength_ratio=0.3, stripe_type="full") sinogram = sim.add_stripe_artifact(sinogram, 2, size // 2 + size // 3,
def test_make_sinogram(self): rec_image = reco.dfi_reconstruction(self.sinogram, self.size // 2, apply_log=False) mat_com = np.abs(self.phantom - rec_image) num1 = np.mean(mat_com[mat_com > 0.0]) self.assertTrue(num1 < self.error)
# Generate a sinogram without distortion correction and perform reconstruction to compare latter. index = 800 print("3 -> Generate a sinogram without distortion correction") sinogram = corr.flat_field_correction(proj_data[:, index, :], flat_field[index], dark_field[index]) sinogram = remo.remove_all_stripe(sinogram, 3.0, 51, 17) sinogram = filt.fresnel_filter(sinogram, 10, 1) t_start = timeit.default_timer() print("4 -> Calculate the center-of-rotation...") center = calc.find_center_vo(sinogram, width // 2 - 50, width // 2 + 50) t_stop = timeit.default_timer() print("Center-of-rotation = {0}. Take {1} second".format( center, t_stop - t_start)) t_start = timeit.default_timer() print("5 -> Perform reconstruction") img_rec = reco.dfi_reconstruction(sinogram, center, apply_log=True) losa.save_image(output_base + "/rec_before_00800.tif", img_rec) t_stop = timeit.default_timer() print("Done reconstruction without distortion correction!!!") # Generate a sinogram with distortion correction and perform reconstruction. print("6 -> Generate a sinogram with distortion correction") sinogram = corr.unwarp_sinogram(proj_data, index, xcenter, ycenter, list_fact) sinogram = corr.flat_field_correction(sinogram, flat_discor[index], dark_discor[index]) sinogram = remo.remove_all_stripe(sinogram, 3.0, 51, 17) sinogram = filt.fresnel_filter(sinogram, 10, 1) t_start = timeit.default_timer() print("7 -> Calculate the center-of-rotation...") # Center-of-rotation can change due to the distortion effect. center = calc.find_center_vo(sinogram, width // 2 - 50, width // 2 + 50) t_stop = timeit.default_timer()