Esempio n. 1
0
    def _call(self, x, out=None):
        """Apply the operator to ``x`` and store the result in ``out``.

        Parameters
        ----------
        x : `DiscreteLpVector`
           Element in the domain of the operator which is back-projected
        out : `DiscreteLpVector`, optional
            Element in the reconstruction space to which the result is
            written. If `None` an element in the range of the operator is
            created.

        Returns
        -------
        out : `DiscreteLpVector`
            Returns an element in the projection space
        """

        if self.impl.startswith('astra'):
            backend, data_impl = self.impl.split('_')
            if data_impl == 'cpu':
                return astra_cpu_back_projector(x, self.geometry,
                                                self.range, out)
            elif data_impl == 'cuda':
                return astra_cuda_back_projector(x, self.geometry,
                                                 self.range, out)
            else:
                # Should never happen
                raise RuntimeError('implementation info is inconsistent')
        elif self.impl == 'scikit':
            return scikit_radon_back_projector(x, self.geometry,
                                               self.range, out)
        else:  # Should never happen
            raise RuntimeError('implementation info is inconsistent')
Esempio n. 2
0
    def _call_real(self, x_real, out_real):
        """Real-space back-projection for the current set-up.

        This method also sets ``self._astra_backprojector`` for
        ``impl='astra_cuda'`` and enabled cache.
        """
        if self.impl.startswith('astra'):
            backend, data_impl = self.impl.split('_')
            if data_impl == 'cpu':
                return astra_cpu_back_projector(x_real, self.geometry,
                                                self.range.real_space,
                                                out_real)
            elif data_impl == 'cuda':
                if self._astra_wrapper is None:
                    astra_wrapper = AstraCudaBackProjectorImpl(
                        self.geometry, self.range.real_space,
                        self.domain.real_space)
                    if self.use_cache:
                        self._astra_wrapper = astra_wrapper
                else:
                    astra_wrapper = self._astra_wrapper

                return astra_wrapper.call_backward(x_real, out_real)
            else:
                # Should never happen
                raise RuntimeError('bad `impl` {!r}'.format(self.impl))

        elif self.impl == 'skimage':
            return skimage_radon_back_projector(x_real, self.geometry,
                                                self.range.real_space,
                                                out_real)
        else:
            # Should never happen
            raise RuntimeError('bad `impl` {!r}'.format(self.impl))
Esempio n. 3
0
    def _call(self, x, out=None):
        """Back-project ``x`` and store the result in ``out`` if given."""

        if self.impl.startswith('astra'):
            backend, data_impl = self.impl.split('_')
            if data_impl == 'cpu':
                return astra_cpu_back_projector(x, self.geometry, self.range,
                                                out)
            elif data_impl == 'cuda':
                backproj = getattr(self, 'astra_backprojector', None)
                if backproj is None:
                    self.astra_backprojector = AstraCudaBackProjectorImpl(
                        self.geometry,
                        self.range,
                        self.domain,
                        use_cache=self.use_cache)

                return self.astra_backprojector.call_backward(x, out)
            else:
                # Should never happen
                raise RuntimeError('implementation info is inconsistent')
        elif self.impl == 'scikit':
            return scikit_radon_back_projector(x, self.geometry, self.range,
                                               out)
        else:  # Should never happen
            raise RuntimeError('implementation info is inconsistent')
    def _call_real(self, x_real, angle_array, out_real):

        geometry = self.spacegeometry(angle_array)
        partialrange = self.range(geometry)
        partialdomain = self.domain(geometry)

        if self.impl.startswith('astra'):
            backend, data_impl = self.impl.split('_')
            if data_impl == 'cpu':
                return astra_cpu_back_projector(x_real, geometry,
                                                partialrange.real_space,
                                                out_real)
            elif data_impl == 'cuda':
                # if self._astra_wrapper is None:
                #     astra_wrapper = AstraCudaBackProjectorImpl(
                #         geometry, partialrange.real_space,
                #         partialdomain.real_space)
                #     if self.use_cache:
                #         self._astra_wrapper = astra_wrapper
                #
                # else:
                #     print("ever here?")
                #     astra_wrapper = self._astra_wrapper

                astra_wrapper = AstraCudaBackProjectorImpl(
                    geometry, partialrange.real_space,
                    partialdomain.real_space)
                return astra_wrapper.call_backward(x_real, out_real)
            else:
                # Should never happen
                raise RuntimeError('bad `impl` {!r}'.format(self.impl))

        else:
            # Should never happen
            raise RuntimeError('bad `impl` {!r}'.format(self.impl))
Esempio n. 5
0
    def _call(self, x, out=None):
        """Back-project ``x`` and store the result in ``out`` if given."""

        if self.impl.startswith('astra'):
            backend, data_impl = self.impl.split('_')
            if data_impl == 'cpu':
                return astra_cpu_back_projector(x, self.geometry,
                                                self.range, out)
            elif data_impl == 'cuda':
                return astra_cuda_back_projector(x, self.geometry,
                                                 self.range, out)
            else:
                # Should never happen
                raise RuntimeError('implementation info is inconsistent')
        elif self.impl == 'scikit':
            return scikit_radon_back_projector(x, self.geometry,
                                               self.range, out)
        else:  # Should never happen
            raise RuntimeError('implementation info is inconsistent')
Esempio n. 6
0
    def _call(self, x, out=None):
        """Back-project ``x`` and store the result in ``out`` if given."""

        if self.impl.startswith('astra'):
            backend, data_impl = self.impl.split('_')
            if data_impl == 'cpu':
                return astra_cpu_back_projector(x, self.geometry,
                                                self.range, out)
            elif data_impl == 'cuda':
                backproj = getattr(self, 'astra_backprojector', None)
                if backproj is None:
                    self.astra_backprojector = AstraCudaBackProjectorImpl(
                        self.geometry, self.range, self.domain,
                        use_cache=self.use_cache)

                return self.astra_backprojector.call_backward(x, out)
            else:
                # Should never happen
                raise RuntimeError('implementation info is inconsistent')
        elif self.impl == 'scikit':
            return scikit_radon_back_projector(x, self.geometry,
                                               self.range, out)
        else:  # Should never happen
            raise RuntimeError('implementation info is inconsistent')