Ejemplo n.º 1
0
def _setup_graph(pm, graph, index, x_region, y_region, region, params, gpu=None):
    backproject = pm.get_task('lamino-backproject')
    slicer = pm.get_task('slice')
    if not params.only_bp:
        from tofu.reco import setup_padding
        pad = pm.get_task('pad')
        crop = pm.get_task('crop')
        fft = pm.get_task('fft')
        ifft = pm.get_task('ifft')
        fltr = pm.get_task('filter')
    if params.dry_run:
        writer = pm.get_task('null')
        writer.props.download = True
    else:
        writer = pm.get_task('write')
        writer.props.filename = '{}-{:>03}-%04i.tif'.format(params.output, index)

    # parameters
    backproject.props.num_projections = params.number
    backproject.props.overall_angle = np.deg2rad(params.overall_angle)
    backproject.props.lamino_angle = np.deg2rad(params.lamino_angle)
    backproject.props.roll_angle = np.deg2rad(params.roll_angle)
    backproject.props.x_region = x_region
    backproject.props.y_region = y_region
    backproject.props.z = params.z
    if params.z_parameter in ['lamino-angle', 'roll-angle']:
        region = [np.deg2rad(reg) for reg in region]
    backproject.props.region = region
    backproject.props.parameter = params.z_parameter
    backproject.props.center = params.axis

    if not params.only_bp:
        setup_padding(pad, crop, params.width, params.height)
        fft.props.dimensions = 1
        ifft.props.dimensions = 1
        fltr.props.scale = np.sin(backproject.props.lamino_angle)

        if gpu:
            pad.set_proc_node(gpu)
            crop.set_proc_node(gpu)
            fft.set_proc_node(gpu)
            ifft.set_proc_node(gpu)
            fltr.set_proc_node(gpu)

    if gpu:
        backproject.set_proc_node(gpu)

    if not params.only_bp:
        graph.connect_nodes(pad, fft)
        graph.connect_nodes(fft, fltr)
        graph.connect_nodes(fltr, ifft)
        graph.connect_nodes(ifft, crop)
        graph.connect_nodes(crop, backproject)
    graph.connect_nodes(backproject, slicer)
    graph.connect_nodes(slicer, writer)

    return backproject if params.only_bp else pad
Ejemplo n.º 2
0
    def __call__(self, consumer):
        """Get a sinogram, do filtered backprojection and send it to *consumer*."""
        sinogram = yield
        setup_padding(self.pad, self.crop, sinogram.shape[1], sinogram.shape[0])

        if not self._started:
            self.start()

        self._process(sinogram, consumer)

        while True:
            sinogram = yield
            self._process(sinogram, consumer)