projdata_info, 1,
    stir.FloatCartesianCoordinate3D(stir.make_FloatCoordinate(0, 0, 0)),
    stir.IntCartesianCoordinate3D(
        stir.make_IntCoordinate(
            np.shape(originalImageP)[0],
            np.shape(originalImageP)[1],
            np.shape(originalImageP)[2])))

# Filling the stir data format with the original image
fillStirSpace(originalImageS, originalImageP)

# Initialize the projection matrix (using ray-tracing)
# Het motion model doet nu niets, maar is nodig omdat Stir anders flipt
MotionModel = stir.MotionModel()
MotionModel.setOffset(0.0)
projmatrix = stir.ProjMatrixByBinUsingRayTracing(MotionModel)
projmatrix.set_num_tangential_LORs(nLOR)
projmatrix.set_up(projdata_info, originalImageS)

# Create projectors
forwardprojector = stir.ForwardProjectorByBinUsingProjMatrixByBin(projmatrix)
backprojector = stir.BackProjectorByBinUsingProjMatrixByBin(projmatrix)

# Creating an instance for the sinogram (measurement), it is not yet filled
measurement = stir.ProjDataInMemory(stir.ExamInfo(), projdata_info)

# Forward project originalImageS and store in measurement
forwardprojector.forward_project(measurement, originalImageS)

# Converting the stir sinogram to a numpy sinogram
measurementS = measurement.get_segment_by_sinogram(0)
예제 #2
0
    def __init__(self,
                 domain,
                 range,
                 volume,
                 proj_data,
                 projector=None,
                 adjoint=None):
        """Initialize a new instance.

        Parameters
        ----------
        domain : `DiscreteLp`
            Volume of the projection. Needs to have the same shape as
            ``volume.shape()``.
        range : `DiscreteLp`
            Projection space. Needs to have the same shape as
            ``proj_data.to_array().shape()``.
        volume : ``stir.FloatVoxelsOnCartesianGrid``
            Stir volume to use in the forward projection
        proj_data : ``stir.ProjData``
            Stir description of the projection.
        projector : ``stir.ForwardProjectorByBin``, optional
            A pre-initialized projector.
        adjoint : `BackProjectorByBinWrapper`, optional
            A pre-initialized adjoint.
        """
        # Check data sizes
        if domain.shape != volume.shape():
            raise ValueError('domain.shape {} does not equal volume shape {}'
                             ''.format(domain.shape, volume.shape()))
        # TODO: improve
        proj_shape = proj_data.to_array().shape()
        if range.shape != proj_shape:
            raise ValueError('range.shape {} does not equal proj shape {}'
                             ''.format(range.shape, proj_shape))

        # Set domain, range etc
        super().__init__(domain, range, True)

        # Read template of the projection
        self.proj_data = proj_data
        self.proj_data_info = proj_data.get_proj_data_info()
        self.volume = volume

        # Create forward projection by matrix
        if projector is None:
            proj_matrix = stir.ProjMatrixByBinUsingRayTracing()
            proj_matrix.set_up(self.proj_data_info, self.volume)
            self.projector = stir.ForwardProjectorByBinUsingProjMatrixByBin(
                proj_matrix)
            self.projector.set_up(self.proj_data_info, self.volume)

            # If no adjoint was given, we initialize a projector here to
            # save time.
            if adjoint is None:
                back_projector = stir.BackProjectorByBinUsingProjMatrixByBin(
                    proj_matrix)
                back_projector.set_up(self.proj_data.get_proj_data_info(),
                                      self.volume)
        else:
            # If user wants to provide both a projector and a back-projector,
            # he should wrap the back projector in an Operator
            self.projector = projector
            back_projector = None

        # Pre-create an adjoint to save time
        if adjoint is None:
            self._adjoint = BackProjectorByBinWrapper(self.range, self.domain,
                                                      self.volume,
                                                      self.proj_data,
                                                      back_projector, self)
        else:
            self._adjoint = adjoint
예제 #3
0
# construct the object using ProjDataInfoCTI
# (the naming of this function was related to the scanner manufacturer, but will be changed in the future)
proj_data_info = stir.ProjDataInfo.ProjDataInfoCTI(
    scanner, span, max_ring_diff, num_views,
    scanner.get_default_num_arccorrected_bins())

#%% Create an empty image with suitable dimensions and voxel sizes
# This image will cover the whole FOV and having the "traditional"
# z-spacing of half the scanner ring-distance. (STIR needs this at the moment).
# For illustration, we use smaller voxels than the default (we "zoom in")
zoom = 1.2
image_data = stir.FloatVoxelsOnCartesianGrid(proj_data_info, zoom)
#%% initialise a projection matrix
# Using ray-tracing here
# Note that the default is to restrict the projection to a cylindrical FOV
projmatrix = stir.ProjMatrixByBinUsingRayTracing()
projmatrix.set_up(proj_data_info, image_data)
#%% construct projectors
forwardprojector = stir.ForwardProjectorByBinUsingProjMatrixByBin(projmatrix)
forwardprojector.set_up(proj_data_info, image_data)

backprojector = stir.BackProjectorByBinUsingProjMatrixByBin(projmatrix)
backprojector.set_up(proj_data_info, image_data)
#%% create projection data for output of forward projection
# We'll create the data in memory here
exam_info = stir.ExamInfo()
projdataout = stir.ProjDataInMemory(exam_info, proj_data_info)
# Note: we could write to file, but it is right now a bit complicated to open a
#  projection data file for read/write:
#  inout=stir.ios.trunc|stir.ios.ios_base_in|stir.ios.out;
#  projdataout=stir.ProjDataInterfile(exam_info, proj_data_info, 'my_test_python_projection.hs',inout);
예제 #4
0
    def __init__(self,
                 domain,
                 range,
                 volume,
                 proj_data,
                 back_projector=None,
                 adjoint=None):
        """Initialize a new instance.

        Parameters
        ----------
        domain : `DiscreteLp`
            Projection space. Needs to have the same shape as
            ``proj_data.to_array().shape()``.
        range : `DiscreteLp`
            Volume of the projection. Needs to have the same shape as
            ``volume.shape()``.
        volume : ``stir.FloatVoxelsOnCartesianGrid``
            Stir volume to use in the forward projection
        proj_data : ``stir.ProjData``
            Stir description of the projection.
        back_projector : ``stir.BackProjectorByBin``, optional
            A pre-initialized back-projector.
        adjoint : `ForwardProjectorByBinWrapper`, optional
            A pre-initialized adjoint.

        Notes
        -----
        See `STIR doc`_ for info on the STIR classes.

        References
        ----------
        .. _STIR doc: http://stir.sourceforge.net/documentation/doxy/html/
        """

        # Check data sizes
        if range.shape != volume.shape():
            raise ValueError('`range.shape` {} does not equal volume shape {}'
                             ''.format(range.shape, volume.shape()))
        # TODO: improve
        proj_shape = proj_data.to_array().shape()
        if domain.shape != proj_shape:
            raise ValueError('`domain.shape` {} does not equal proj shape {}'
                             ''.format(range.shape, proj_shape))

        # Set range domain
        super().__init__(domain, range, True)

        # Read template of the projection
        self.proj_data = proj_data
        self.proj_data_info = proj_data.get_proj_data_info()
        self.volume = volume

        # Create forward projection by matrix
        if back_projector is None:
            proj_matrix = stir.ProjMatrixByBinUsingRayTracing()
            proj_matrix.set_up(self.proj_data_info, self.volume)

            self.back_projector = stir.BackProjectorByBinUsingProjMatrixByBin(
                proj_matrix)
            self.back_projector.set_up(self.proj_data.get_proj_data_info(),
                                       self.volume)

            if adjoint is None:
                projector = stir.ForwardProjectorByBinUsingProjMatrixByBin(
                    proj_matrix)
                projector.set_up(self.proj_data_info, self.volume)

        else:
            self.back_projector = back_projector
            projector = None

        # Pre-create an adjoint to save time
        if adjoint is None:
            self._adjoint = ForwardProjectorByBinWrapper(
                self.range, self.domain, self.volume, self.proj_data,
                projector, self)
        else:
            self._adjoint = adjoint