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
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
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
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
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)
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
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)
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
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
def set_up(self, image): handle = pystir.cSTIR_setupReconstruction(self.handle, image.handle) _check_status(handle) pyiutil.deleteDataHandle(handle)
def reconstruct(self, image): handle = pystir.cSTIR_runReconstruction(self.handle, image.handle) _check_status(handle) pyiutil.deleteDataHandle(handle)
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)
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)
def apply(self, image): handle = pystir.cSTIR_applyDataProcessor\ (self.handle, image.handle) _check_status(handle) pyiutil.deleteDataHandle(handle)
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
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
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
def __del__(self): pyiutil.deleteDataHandle(self.handle)
def clone(self): image = Image() pyiutil.deleteDataHandle(image.handle) image.handle = pystir.cSTIR_imageFromImage(self.handle) _check_status(image.handle) return image
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)
def _setParameter(hs, set, par, hv): h = pystir.cSTIR_setParameter(hs, set, par, hv) _check_status(h) pyiutil.deleteDataHandle(h)
def _set_char_par(handle, set, par, value): h = pyiutil.charDataHandle(value) _setParameter(handle, set, par, h) pyiutil.deleteDataHandle(h)
def __del__(self): if self.handle is not None: pyiutil.deleteDataHandle(self.handle)
def _set_float_par(handle, set, par, value): h = pyiutil.floatDataHandle(value) _setParameter(handle, set, par, h) pyiutil.deleteDataHandle(h)