Пример #1
0
 def test_find_center_vo(self):
     center0 = 31.0
     mat = np.zeros((self.size, self.size), dtype=np.float32)
     mat[20:30, 35:42] = np.float32(1.0)
     sinogram = np.zeros((37, self.size), dtype=np.float32)
     angles = np.linspace(0.0, 180.0, len(sinogram), dtype=np.float32)
     for i, angle in enumerate(angles):
         sinogram[i] = np.sum(ndi.rotate(mat, angle, reshape=False), axis=0)
     center = calc.find_center_vo(sinogram)
     self.assertTrue(np.abs(center - center0) < self.error)
else:
    angles = angles[0:depth]

time_start = timeit.default_timer()
# Load flat-field images and dark-field images, average each of them
print("1 -> Load dark-field and flat-field images, average each result")
flat_field = np.mean(losa.load_hdf(flat_path, hdf_key)[:], axis=0)
dark_field = np.mean(losa.load_hdf(dark_path, hdf_key)[:], axis=0)

# Find the center of rotation using the sinogram of the first tomograph
mid_slice = height // 2
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,
Пример #3
0
output_base = "C:/user/processed_data/reconstruction/"

# Provide hdf-keys
phase_hdf = losa.load_hdf(phase_path, "entry/data")
dark_hdf = losa.load_hdf(dark_path, "entry/data")
trans_hdf = losa.load_hdf(trans_path, "entry/data")

(num_proj, height, width) = phase_hdf.shape

start_slice = 50
stop_slice = height - 1
step = 100

# Find the center of rotation using a transmission sinogram.
sino_center = trans_hdf[:, height // 2, :]
center = calc.find_center_vo(sino_center)
print("Center of rotation {}".format(center))

fluct_correct = False  # Using double-wedge filter to correct the
# fluctuation of phase sinograms
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)
Пример #4
0
        sino_trans.append(trans[mid])
        sino_dark.append(dark[mid])
    t1 = timeit.default_timer()
    print("Done projection {0}. Time cost: {1} ".format(i, t1 - t0))
print("Done phase retrieval !!!")
sino_phase = np.asarray(sino_phase)
if get_trans_dark_signal:
    sino_trans = np.asarray(sino_trans)
    sino_dark = np.asarray(sino_dark)
    losa.save_image(output_base + "/sinogram/trans_" + name + ".tif",
                    sino_trans)
    losa.save_image(output_base + "/sinogram/dark_" + name + ".tif", sino_dark)
losa.save_image(output_base + "/sinogram/phase_" + name + ".tif", sino_phase)

if get_trans_dark_signal:
    center = calc.find_center_vo(sino_trans)
else:
    center = calc.find_center_vo(sino_phase)
print("Center of rotation {}".format(center))

# Correct the fluctuation of the phase image.
sino_phase1 = filt.double_wedge_filter(sino_phase, center)
losa.save_image(output_base + "/sinogram/phase_corr.tif", sino_phase1)

# Reconstruction
rec_phase = reco.fbp_reconstruction(sino_phase,
                                    center,
                                    apply_log=False,
                                    filter_name="hann")
rec_phase1 = reco.fbp_reconstruction(sino_phase1,
                                     center,
Пример #5
0
)
xcenter, ycenter, list_fact = losa.load_distortion_coefficient(coef_path)
# Apply distortion correction
flat_discor = corr.unwarp_projection(flat_field, xcenter, ycenter, list_fact)
dark_discor = corr.unwarp_projection(dark_field, xcenter, ycenter, list_fact)

# 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)