Exemplo n.º 1
0
 def diff_from(self, image):
     handle = pystir.cSTIR_imagesDifference\
              (self.handle, image.handle, self.rimsize)
     _check_status(handle)
     diff = pyiutil.doubleDataFromHandle(handle)
     pyiutil.deleteDataHandle(handle)
     return diff
Exemplo n.º 2
0
 def gradient(self, image, subset):
     grad = Image()
     pyiutil.deleteDataHandle(grad.handle)
     grad.handle = pystir.cSTIR_objectiveFunctionGradient\
         (self.handle, image.handle, subset)
     _check_status(grad.handle)
     return grad
Exemplo n.º 3
0
 def get_gradient_plus_sensitivity_no_penalty(self, image, subset):
     grad = Image()
     pyiutil.deleteDataHandle(grad.handle)
     grad.handle = pystir.cSTIR_objectiveFunctionGradientNotDivided\
         (self.handle, image.handle, subset)
     _check_status(grad.handle)
     return grad
Exemplo n.º 4
0
 def get_empty_copy(self, value = 1.0):
     image = Image()
     pyiutil.deleteDataHandle(image.handle)
     image.handle = pystir.cSTIR_imageFromImage(self.handle)
     _check_status(image.handle)
     image.fill(value)
     return image
Exemplo n.º 5
0
 def initialise\
     (self, arg1, arg2 = 0, arg3 = 0, arg4 = 1, arg5 = 1, arg6 = 1, \
      arg7 = 0, arg8 = 0, arg9 = 0):
     if type(arg1) == type((0,0,0)):
         dim = arg1
         if arg2 == 0:
             vsize = (1, 1, 1)
             origin = (0, 0, 0)
         else:
             vsize = arg2
             if arg3 == 0:
                 origin = (0, 0, 0)
             else:
                 origin = arg3
     else:
         dim = (arg1, arg2, arg3)
         vsize = (arg4, arg5, arg6)
         origin = (arg7, arg8, arg9)
     if self.handle is not None:
         pyiutil.deleteDataHandle(self.handle)
     self.handle = None
     voxels = pystir.cSTIR_voxels3DF\
                   (dim[0], dim[1], dim[2], \
                    vsize[0], vsize[1], vsize[2], \
                    origin[0], origin[1], origin[2])
     _check_status(voxels)
     self.handle = pystir.cSTIR_imageFromVoxels(voxels)
     _check_status(self.handle)
     pyiutil.deleteDataHandle(voxels)
Exemplo n.º 6
0
 def get_acquisition_model(self):
     am = AcquisitionModelUsingMatrix()
     if am.handle is not None:
         pyiutil.deleteDataHandle(am.handle)
     am.handle = pystir.cSTIR_parameter\
         (self.handle, self.name, 'acquisition_model')
     _check_status(am.handle)
     return am
Exemplo n.º 7
0
 def set_up(self, acq_templ, img_templ):
     ''' Prepares this object for performing forward and backward
         projections;
         acq_templ:  an AcquisitionData object used as a template for
                     creating an AcquisitionData object to store forward
                     projection;
         img_templ:  an Image object used as a template for creating an
                     Image object to store backward projection.
     '''
     handle = pystir.cSTIR_setupAcquisitionModel\
         (self.handle, acq_templ.handle, img_templ.handle)
     _check_status(handle)
     pyiutil.deleteDataHandle(handle)
Exemplo n.º 8
0
 def create_empty_image(self, value = 0):
     ''' Creates Image object containing PET image of dimensions
         and voxel sizes compatible with the scanner geometry stored
         in this AcquisitionData object and assigns a given value
         to all voxels;
         value:  a Python float.
     '''
     image = Image()
     pyiutil.deleteDataHandle(image.handle)
     image.handle = pystir.cSTIR_imageFromAcquisitionData(self.handle)
     _check_status(image.handle)
     image.fill(value)
     return image
Exemplo n.º 9
0
 def as_array(self):
     ''' Returns a copy of acquisition data stored in this object as a
         NumPy ndarray of 3 dimensions (in default C ordering of data):
         - number of sinograms
         - number of views
         - number of tangential positions.
     '''
     dim = numpy.ndarray((3,), dtype = numpy.int32)
     handle = pystir.cSTIR_getAcquisitionsDimensions\
         (self.handle, dim.ctypes.data)
     _check_status(handle)
     pyiutil.deleteDataHandle(handle)
     nx = dim[0]
     ny = dim[1]
     nz = dim[2]
     if nx == 0 or ny == 0 or nz == 0:
         raise error('density data not available')
     array = numpy.ndarray((nz, ny, nx), dtype = numpy.float64)
     handle = pystir.cSTIR_getAcquisitionsData\
         (self.handle, array.ctypes.data)
     _check_status(handle)
     pyiutil.deleteDataHandle(handle)
     return array
Exemplo n.º 10
0
 def set_up(self, image):
     handle = pystir.cSTIR_setupReconstruction(self.handle, image.handle)
     _check_status(handle)
     pyiutil.deleteDataHandle(handle)
Exemplo n.º 11
0
 def reconstruct(self, image):
     handle = pystir.cSTIR_runReconstruction(self.handle, image.handle)
     _check_status(handle)
     pyiutil.deleteDataHandle(handle)
Exemplo n.º 12
0
 def read_from_file(self, filename):
     if self.handle is not None:
         pyiutil.deleteDataHandle(self.handle)
     self.handle = pystir.cSTIR_objectFromFile('Image', filename)
     _check_status(self.handle)
Exemplo n.º 13
0
 def add_shape(self, shape, scale):
     if self.handle is None:
         raise error('cannot add shapes to uninitialised image')
     handle = pystir.cSTIR_addShape(self.handle, shape.handle, scale)
     _check_status(handle)
     pyiutil.deleteDataHandle(handle)
Exemplo n.º 14
0
 def apply(self, image):
     handle = pystir.cSTIR_applyDataProcessor\
              (self.handle, image.handle)
     _check_status(handle)
     pyiutil.deleteDataHandle(handle)
Exemplo n.º 15
0
 def get_subset_sensitivity(self, subset):
     ss = Image()
     pyiutil.deleteDataHandle(ss.handle)
     ss.handle = pystir.cSTIR_subsetSensitivity(self.handle, subset)
     _check_status(ss.handle)
     return ss
Exemplo n.º 16
0
 def get_gradient(self, image):
     grad = Image()
     pyiutil.deleteDataHandle(grad.handle)
     grad.handle = pystir.cSTIR_priorGradient(self.handle, image.handle)
     _check_status(grad.handle)
     return grad
Exemplo n.º 17
0
def _float_par(handle, set, par):
    h = pystir.cSTIR_parameter(handle, set, par)
    _check_status(h)
    value = pyiutil.floatDataFromHandle(h)
    pyiutil.deleteDataHandle(h)
    return value
Exemplo n.º 18
0
 def __del__(self):
     pyiutil.deleteDataHandle(self.handle)
Exemplo n.º 19
0
 def clone(self):
     image = Image()
     pyiutil.deleteDataHandle(image.handle)
     image.handle = pystir.cSTIR_imageFromImage(self.handle)
     _check_status(image.handle)
     return image
Exemplo n.º 20
0
 def process(self):
     if self.image is None:
         raise error('current estimate not set')
     handle = pystir.cSTIR_runReconstruction(self.handle, self.image.handle)
     _check_status(handle)
     pyiutil.deleteDataHandle(handle)
Exemplo n.º 21
0
def _setParameter(hs, set, par, hv):
    h = pystir.cSTIR_setParameter(hs, set, par, hv)
    _check_status(h)
    pyiutil.deleteDataHandle(h)
Exemplo n.º 22
0
def _set_char_par(handle, set, par, value):
    h = pyiutil.charDataHandle(value)
    _setParameter(handle, set, par, h)
    pyiutil.deleteDataHandle(h)
Exemplo n.º 23
0
 def __del__(self):
     if self.handle is not None:
         pyiutil.deleteDataHandle(self.handle)
Exemplo n.º 24
0
def _set_float_par(handle, set, par, value):
    h = pyiutil.floatDataHandle(value)
    _setParameter(handle, set, par, h)
    pyiutil.deleteDataHandle(h)