コード例 #1
0
# The capability of building a subset of vertical slices out of 3D phantom (faster)
import timeit
from tomophantom import TomoP3D
import matplotlib.pyplot as plt
import tomophantom
import os
import numpy as np

print ("Building a subset of 3D phantom using TomoPhantom software")
tic=timeit.default_timer()
model = 13
N_size = 256 # Define phantom dimensions using a scalar value
DIM_z = (0, 150) # selected vertical (z) subset (a slab) of the phantom
path = os.path.dirname(tomophantom.__file__)
path_library3D = os.path.join(path, "Phantom3DLibrary.dat")
phantom_tm = TomoP3D.ModelSub(model, N_size, DIM_z, path_library3D)
toc=timeit.default_timer()
Run_time = toc - tic
print("Phantom has been built in {} seconds".format(Run_time))

sliceSel = 130
#plt.gray()
plt.figure(2) 
plt.subplot(131)
plt.imshow(phantom_tm[sliceSel,:,:],vmin=0, vmax=1)
plt.title('3D Phantom, axial view')

plt.subplot(132)
plt.imshow(phantom_tm[:,128,:],vmin=0, vmax=1)
plt.title('3D Phantom, coronal view')
コード例 #2
0
    def process_frames(self, data):
        # print "The input data shape is", data[0].shape
        if (self.out_shape_sino[1] == 1):
            # create a 2D phantom
            model = TomoP2D.Model(self.model, self.dims, self.path_library2D)
            # create a 2D sinogram
            projdata_clean = TomoP2D.ModelSino(self.model, self.dims,
                                               self.detectors_num, self.angles,
                                               self.path_library2D)
            # Adding artifacts and noise
            # forming dictionaries with artifact types
            _noise_ = {
                'type': self.parameters['artifacts_noise_type'],
                'sigma': self.parameters['artifacts_noise_sigma'],
                'seed': 0,
                'prelog': False
            }

            # misalignment dictionary
            _sinoshifts_ = {}
            if self.parameters[
                    'artifacts_misalignment_maxamplitude'] is not None:
                _sinoshifts_ = {
                    'maxamplitude':
                    self.parameters['artifacts_misalignment_maxamplitude']
                }

            # adding zingers and stripes
            _zingers_ = {}
            if self.parameters['artifacts_zingers_percentage'] is not None:
                _zingers_ = {
                    'percentage':
                    self.parameters['artifacts_zingers_percentage'],
                    'modulus': 10
                }

            _stripes_ = {}
            if self.parameters['artifacts_stripes_percentage'] is not None:
                _stripes_ = {
                    'percentage':
                    self.parameters['artifacts_stripes_percentage'],
                    'maxthickness':
                    self.parameters['artifacts_stripes_maxthickness'],
                    'intensity':
                    self.parameters['artifacts_stripes_intensity'],
                    'type':
                    self.parameters['artifacts_stripes_type'],
                    'variability':
                    self.parameters['artifacts_stripes_variability']
                }

            if self.parameters[
                    'artifacts_misalignment_maxamplitude'] is not None:
                [projdata,
                 shifts] = _Artifacts_(projdata_clean, _noise_, _zingers_,
                                       _stripes_, _sinoshifts_)
            else:
                projdata = _Artifacts_(projdata_clean, _noise_, _zingers_,
                                       _stripes_, _sinoshifts_)
        else:
            # create a 3D phantom
            frame_idx = self.out_pData[0].get_current_frame_idx()[0]
            model = TomoP3D.ModelSub(self.model, self.dims,
                                     (frame_idx, frame_idx + 1),
                                     self.path_library3D)
            model = np.swapaxes(model, 0, 1)
            model = np.flipud(model[:, 0, :])
            # create a 3D projection data
            projdata_clean = TomoP3D.ModelSinoSub(
                self.model, self.dims, self.detectors_num, self.dims,
                (frame_idx, frame_idx + 1), self.angles, self.path_library3D)
            # Adding artifacts and noise
            # forming dictionaries with artifact types
            _noise_ = {
                'type': self.parameters['artifacts_noise_type'],
                'sigma': self.parameters['artifacts_noise_sigma'],
                'seed': 0,
                'prelog': False
            }

            # misalignment dictionary
            _sinoshifts_ = {}
            if self.parameters[
                    'artifacts_misalignment_maxamplitude'] is not None:
                _sinoshifts_ = {
                    'maxamplitude':
                    self.parameters['artifacts_misalignment_maxamplitude']
                }

            # adding zingers and stripes
            _zingers_ = {}
            if self.parameters['artifacts_zingers_percentage'] is not None:
                _zingers_ = {
                    'percentage':
                    self.parameters['artifacts_zingers_percentage'],
                    'modulus': 10
                }

            _stripes_ = {}
            if self.parameters['artifacts_stripes_percentage'] is not None:
                _stripes_ = {
                    'percentage':
                    self.parameters['artifacts_stripes_percentage'],
                    'maxthickness':
                    self.parameters['artifacts_stripes_maxthickness'],
                    'intensity':
                    self.parameters['artifacts_stripes_intensity'],
                    'type':
                    self.parameters['artifacts_stripes_type'],
                    'variability':
                    self.parameters['artifacts_stripes_variability']
                }

            if self.parameters[
                    'artifacts_misalignment_maxamplitude'] is not None:
                [projdata,
                 shifts] = _Artifacts_(projdata_clean, _noise_, _zingers_,
                                       _stripes_, _sinoshifts_)
            else:
                projdata = _Artifacts_(projdata_clean, _noise_, _zingers_,
                                       _stripes_, _sinoshifts_)
            projdata = np.swapaxes(projdata, 0, 1)
        return [projdata, model]