Beispiel #1
0
 def test_find_center_360(self):
     mat = np.zeros((self.size, self.size), dtype=np.float32)
     mat[20:30, 35:42] = np.float32(1.0)
     sinogram = np.zeros((73, self.size), dtype=np.float32)
     angles = np.linspace(0.0, 360.0, len(sinogram), dtype=np.float32)
     for i, angle in enumerate(angles):
         sinogram[i] = np.sum(ndi.rotate(mat, angle, reshape=False), axis=0)
     sinogram = sinogram / np.max(sinogram)
     noise = 0.1 * np.random.rand(73, self.size)
     sinogram = np.pad(sinogram[:, 22:], ((0, 0), (0, 22)), mode='constant')
     sinogram = sinogram + noise
     (cor, _, side) = calc.find_center_360(sinogram, 6)[0:3]
     self.assertTrue(np.abs(cor - 9.0) < self.error and side == 0)
print("Index-range of slices is: [0, {0}] using a pixel-size of {1}".format(max_index, pixel_size))

# Generate a blob map used for removing streak artifacts
blob_mask = remo.generate_blob_mask(flat_field, 71, 3)


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