Exemplo n.º 1
0
 def test_fbp_reconstruction(self):
     mat_rec1 = reco.fbp_reconstruction(self.sino_180,
                                        self.center,
                                        apply_log=False,
                                        gpu=False)
     num1 = np.max(np.abs(self.mat - mat_rec1))
     mat_rec2 = reco.fbp_reconstruction(self.sino_360,
                                        self.center,
                                        angles=np.deg2rad(self.angles),
                                        apply_log=False,
                                        gpu=False)
     num2 = np.max(np.abs(self.mat - mat_rec2))
     check = True
     if cuda.is_available() is True:
         mat_rec1 = reco.fbp_reconstruction(self.sino_180,
                                            self.center,
                                            apply_log=False,
                                            gpu=True)
         num3 = np.max(np.abs(self.mat - mat_rec1))
         mat_rec2 = reco.fbp_reconstruction(self.sino_360,
                                            self.center,
                                            angles=np.deg2rad(self.angles),
                                            apply_log=False,
                                            gpu=True)
         num4 = np.max(np.abs(self.mat - mat_rec2))
         if num3 > 0.1 or num4 > 0.1:
             check = False
     self.assertTrue(num1 <= 0.1 and num2 <= 0.1 and check)
print("2 -> Calculate the center-of-rotation...")
sinogram = corr.flat_field_correction(data[0:num_proj, mid_slice, left:right],
                                      flat_field[mid_slice, left:right],
                                      dark_field[mid_slice, left:right])
center = calc.find_center_vo(sinogram)
print("Center-of-rotation = {0}".format(center))
for i in range(num_tomo):
    folder_name = "tomo_" + ("0000" + str(i))[-5:]
    thetas = np.deg2rad(angles[i * num_proj:(i + 1) * num_proj])
    for slice_idx in range(start_slice, stop_slice + 1, step_slice):
        sinogram = corr.flat_field_correction(
            data[i * num_proj:(i + 1) * num_proj, slice_idx, left:right],
            flat_field[slice_idx, left:right], dark_field[slice_idx,
                                                          left:right])
        sinogram = remo.remove_zinger(sinogram, 0.05, 1)
        sinogram = remo.remove_all_stripe(sinogram, 3.0, 51, 17)
        sinogram = filt.fresnel_filter(sinogram, 100)
        # img_rec = reco.dfi_reconstruction(sinogram, center, angles=thetas, apply_log=True)
        # img_rec = reco.gridrec_reconstruction(sinogram, center, angles=thetas, apply_log=True)
        img_rec = reco.fbp_reconstruction(sinogram,
                                          center,
                                          angles=thetas,
                                          apply_log=True)
        file_name = "rec_slice_" + ("0000" + str(slice_idx))[-5:] + ".tif"
        losa.save_image(output_base + "/" + folder_name + "/" + file_name,
                        img_rec)
    print("Done tomograph {0}".format(i))

time_stop = timeit.default_timer()
print("All done!!! Total time cost: {}".format(time_stop - time_start))
Exemplo n.º 3
0
        start_sino = i * slice_chunk + offset
        stop_sino = start_sino + slice_chunk
        sinograms = corr.flat_field_correction(
            data[ii * num_proj:(ii + 1) * num_proj, start_sino:stop_sino,
                 left:right],
            flat_field[start_sino:stop_sino, left:right],
            dark_field[start_sino:stop_sino, left:right],
            option1=opt1,
            option2=opt2,
            option3=opt3)
        for j in range(start_sino, stop_sino):
            # img_rec = reco.dfi_reconstruction(sinograms[:, j - start_sino, :], center, angles=thetas, apply_log=True)
            # img_rec = reco.gridrec_reconstruction(sinograms[:, j - start_sino, :], center, angles=thetas,
            #                                       apply_log=True)
            img_rec = reco.fbp_reconstruction(sinograms[:, j - start_sino, :],
                                              center,
                                              angles=thetas,
                                              apply_log=True)
            name = "0000" + str(j)
            losa.save_image(
                output_base + "/" + folder_name + "/rec_" + name[-5:] + ".tif",
                img_rec)

        t_stop = timeit.default_timer()
        print("Tomograph {0} -> Done slice: {1} - {2} . Time {3}".format(
            ii, start_sino, stop_sino, t_stop - time_start))
    if num_rest != 0:
        for i in range(num_rest):
            start_sino = num_iter * slice_chunk + offset
            stop_sino = start_sino + num_rest
            sinograms = corr.flat_field_correction(
                data[ii * num_proj:(ii + 1) * num_proj, start_sino:stop_sino,
Exemplo n.º 4
0
artifact_rem = False  # Remove ring artifacts
t0 = timeit.default_timer()
for i in np.arange(start_slice, stop_slice + 1, step):
    name = ("0000" + str(i))[-5:]
    sino_phase = phase_hdf[:, i, :]
    if fluct_correct:
        sino_phase = filt.double_wedge_filter(sino_phase, center)
    sino_trans = trans_hdf[:, i, :]
    sino_dark = dark_hdf[:, i, :]
    if artifact_rem:
        sino_phase = rem.remove_all_stripe(sino_phase, 2.0, 51, 17)
        sino_trans = rem.remove_all_stripe(sino_trans, 2.0, 51, 17)
        sino_dark = rem.remove_all_stripe(sino_dark, 2.0, 51, 17)
    # Change to CPU methods (DFI or gridrec) if GPU not available
    rec_phase = reco.fbp_reconstruction(sino_phase,
                                        center,
                                        apply_log=False,
                                        filter_name="hann")
    rec_trans = reco.fbp_reconstruction(sino_trans,
                                        center,
                                        apply_log=True,
                                        filter_name="hann")
    rec_dark = reco.fbp_reconstruction(sino_dark,
                                       center,
                                       apply_log=True,
                                       filter_name="hann")
    losa.save_image(output_base + "/phase/rec_" + name + ".tif", rec_phase)
    losa.save_image(output_base + "/transmission/rec_" + name + ".tif",
                    rec_trans)
    losa.save_image(output_base + "/dark_signal/rec_" + name + ".tif",
                    rec_dark)
    print("Done slice: {}".format(i))
Exemplo n.º 5
0
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,
                                   strength_ratio=0.7, stripe_type="dead")
sinogram = sim.add_stripe_artifact(sinogram, 1, size // 2 - size // 4,
                                   strength_ratio=0.2,
Exemplo n.º 6
0
sino_360 = conv.stitch_image_multiple(list_sino,
                                      list_overlap,
                                      norm=True,
                                      total_width=None)
losa.save_image(output_base + "/reconstruction/sino_360_stitched.tif",
                sino_360)
print(
    "3 -> Calculate the center of rotation and convert a 360-degree sinogram to a 180-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)
losa.save_image(output_base + "/reconstruction/sino_180_converted.tif",
                sino_180)
# Apply the Fresnel filter
print("4 -> Apply a denoising method because the sinogram is undersampled")
sino_180 = filt.fresnel_filter(sino_180, 250, 1)
# Perform reconstruction
print("5 -> Perform reconstruction")
# 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)
## Using gridrec code for faster CPU reconstruction if Tomopy installed
# img_rec = reco.gridrec_reconstruction(sino_180, center1, apply_log=True)
losa.save_image(output_base + "/reconstruction/recon_image.tif", img_rec)
time_stop = timeit.default_timer()
print("!!! Done !!! Time cost: {}".format(time_stop - time_start))
Exemplo n.º 7
0
sino_360 = remo.remove_zinger(sino_360, 0.08)
# Remove ring artifacts
sino_360 = remo.remove_all_stripe(sino_360, 3, 51, 17)

# 1st way: Convert the 360-degree sinogram to the 180-degree sinogram.
sino_180, center1 = conv.convert_sinogram_360_to_180(sino_360, center0)
losa.save_image(output_base + "/reconstruction/sino_180.tif", sino_180)
## Denoising
sino_180 = filt.fresnel_filter(sino_180, 250, 1, apply_log=True)
# Perform reconstruction
img_rec = reco.dfi_reconstruction(sino_180, center1, apply_log=True)
## Using fbp with GPU for faster reconstruction
# img_rec = reco.fbp_reconstruction(sino_180, center1, apply_log=True, gpu=True)
losa.save_image(output_base + "/reconstruction/recon_image_1.tif", img_rec)

# 2nd way: Extending the 360-degree sinogram (by weighting and padding).
(sino_ext, center2) = conv.extend_sinogram(sino_360, center0)
losa.save_image(output_base + "/reconstruction/sino_360_extened.tif", sino_ext)
# Denoising
sino_ext = filt.fresnel_filter(sino_ext, 250, 1, apply_log=False)
# Perform reconstruction
# img_rec = reco.dfi_reconstruction(sino_ext, center2, angles=angles*np.pi/180.0,apply_log=False)
## Using fbp with GPU for faster reconstruction
img_rec = reco.fbp_reconstruction(sino_ext,
                                  center2,
                                  angles=angles * np.pi / 180.0,
                                  apply_log=False,
                                  gpu=True)
losa.save_image(output_base + "/reconstruction/recon_image_2.tif", img_rec)
print("!!! Done !!!")