from cil.framework import DataProcessor, ImageData import numpy as np import gi gi.require_version('Ufo','0.0') from gi.repository import Ufo class FBP_Standard(DataProcessor): def __init__(self, volume_geometry, sinogram_geometry, z_dim = None): kwargs = { 'volume_geometry': volume_geometry, 'sinogram_geometry': sinogram_geometry, 'z_dim': z_dim} super(FBP_Standard, self).__init__(**kwargs) self.z_dim = 0 self.set_ImageGeometry(volume_geometry) self.set_AcquisitionGeometry(sinogram_geometry) def check_input(self, dataset): if self.sinogram_geometry.dimension == '2D': self.z_dim = 1 elif self.sinogram_geometry.dimension == '3D': self.z_dim = self.sinogram_geometry.shape[2] return True def set_ImageGeometry(self, volume_geometry): self.volume_geometry = volume_geometry def set_AcquisitionGeometry(self, sinogram_geometry): self.sinogram_geometry = sinogram_geometry def process(self, **kwargs): # Get DATA DATA = self.get_input() DATA = DATA.as_array() pm = Ufo.PluginManager() graph = Ufo.TaskGraph() scheduler = Ufo.Scheduler() read = pm.get_task('memory-in') read.props.pointer = DATA.__array_interface__['data'][0] read.props.width = DATA.shape[1] read.props.height = DATA.shape[0] read.props.number = self.z_dim read.props.bitdepth = 32 fft = pm.get_task('fft') fft.props.dimensions = 1 filter = pm.get_task('filter') ifft = pm.get_task('ifft') ifft.props.dimensions = 1 bp = pm.get_task('backproject') bp.props.axis_pos = DATA.shape[1] / 2 vol_arr = np.zeros(self.volume_geometry.shape, dtype=np.float32) write = pm.get_task('memory-out') write.props.pointer = vol_arr.__array_interface__['data'][0] write.props.max_size = vol_arr.nbytes graph.connect_nodes(read, fft) graph.connect_nodes(fft, filter) graph.connect_nodes(filter, ifft) graph.connect_nodes(ifft, bp) graph.connect_nodes(bp, write) scheduler.run(graph) vol_arr = ImageData(vol_arr, deep_copy=False, geometry=self.volume_geometry.copy(), suppress_warning=True) return vol_arr