Skip to content

Reference for pyronn/ct_reconstruction/layers/backprojection_2d.py


pyronn.ct_reconstruction.layers.backprojection_2d.ParallelBackProjectionFor2D

forward

forward(input, geometry, for_train=False, debug=False)

Reconstruction for the 2D parallel beam CT.

Parameters:

Name Type Description Default
input

(1, number_of_projections, detection_size) numpy array or torch.Tensor.

required
geometry

The projection geometry used for projection.

required
for_train

Set the return value data type if the backend is torch. You can get a numpy.array by setting this

False
return

The reconstruction result of 2D parallel beam CT.

Source code in pyronn/ct_reconstruction/layers/backprojection_2d.py
def forward(self, input, geometry, for_train=False, debug=False):
    # TODO: Document this function on your own. Could not be documented by the model.
    # TODO: Document this function on your own. Could not be documented by the model.
    '''
    Reconstruction for the 2D parallel beam CT.

    args:
        input: (1, number_of_projections, detection_size) numpy array or torch.Tensor.
        geometry: The projection geometry used for projection.
        for_train: Set the return value data type if the backend is torch. You can get a numpy.array by setting this
        value False, otherwise you will get a torch.Tensor.

    return:
        The reconstruction result of 2D parallel beam CT.
    '''
    try:
        import torch
        from pyronn.ct_reconstruction.layers.torch.backprojection_2d import ParallelBackProjection2D

        if not isinstance(input, torch.Tensor):
            sinogram = torch.tensor(input.copy(), dtype=torch.float32)
        else:
            sinogram = torch.clone(input)

        tensor_geometry = {}
        geo_dict = vars(geometry)
        for k in geo_dict:
            param = geo_dict[k]
            try:
                if hasattr(param, '__len__'):
                    tmp_tensor = torch.Tensor(param)

                    sinogram = sinogram.cuda()
                    tensor_geometry[k] = tmp_tensor.cuda()
            except Exception as e:
                if isinstance(e, TypeError):
                    if debug: print('Attribute <' + k + '> could not be transformed to torch.Tensor')
                else:
                    raise e

        reco = ParallelBackProjection2D().forward(sinogram.contiguous(), **tensor_geometry)
        if for_train:
            return reco

        if reco.device.type == 'cuda':
            return reco.detach().cpu().numpy()
        return reco.cpu().numpy()

    except Exception as e:
        if isinstance(e, ModuleNotFoundError):
            from pyronn.ct_reconstruction.layers.tensorflow.backprojection_2d import parallel_backprojection2d
            return parallel_backprojection2d(input, geometry)
        else:
            raise e





pyronn.ct_reconstruction.layers.backprojection_2d.FanBackProjectionFor2D

forward

forward(input, geometry, for_train=False, debug=False)

Reconstruction for the 2D fan beam CT.

Parameters:

Name Type Description Default
input

(1, number_of_projections, detection_size) numpy array or torch.Tensor.

required
geometry

The projection geometry used for projection.

required
for_train

Set the return value data type if the backend is torch. You can get a numpy.array by setting this

False
return

The reconstruction result of 2D fan beam CT.

Source code in pyronn/ct_reconstruction/layers/backprojection_2d.py
def forward(self, input, geometry, for_train=False, debug=False):
    # TODO: Document this function on your own. Could not be documented by the model.
    # TODO: Document this function on your own. Could not be documented by the model.
    '''
    Reconstruction for the 2D fan beam CT.

    args:
        input: (1, number_of_projections, detection_size) numpy array or torch.Tensor.
        geometry: The projection geometry used for projection.
        for_train: Set the return value data type if the backend is torch. You can get a numpy.array by setting this
        value False, otherwise you will get a torch.Tensor.

    return:
        The reconstruction result of 2D fan beam CT.
    '''
    try:
        import torch
        from pyronn.ct_reconstruction.layers.torch.backprojection_2d import FanBackProjection2D

        if not isinstance(input, torch.Tensor):
            sinogram = torch.tensor(input.copy(), dtype=torch.float32).cuda()
        else:
            sinogram = torch.clone(input).cuda()

        tensor_geometry = {}
        geo_dict = vars(geometry)
        for k in geo_dict:
            param = geo_dict[k]
            try:
                if hasattr(param, '__len__'):
                    tmp_tensor = torch.Tensor(param)
                else:
                    tmp_tensor = torch.Tensor([param])

                tensor_geometry[k] = tmp_tensor.cuda()
            except Exception as e:
                if isinstance(e, TypeError):
                    if debug: print('Attribute <' + k + '> could not be transformed to torch.Tensor')
                else:
                    raise e
        reco = FanBackProjection2D().forward(sinogram.contiguous(), **tensor_geometry)
        if for_train:
            return reco

        if reco.device.type == 'cuda':
            return reco.detach().cpu().numpy()
        return reco.cpu().numpy()

    except Exception as e:
        if isinstance(e, ModuleNotFoundError):
            from pyronn.ct_reconstruction.layers.tensorflow.backprojection_2d import fan_backprojection2d
            return fan_backprojection2d(input, geometry)
        else:
            raise e