Skip to content

Reference for pyronn/ct_reconstruction/layers/projection_3d.py


pyronn.ct_reconstruction.layers.projection_3d.Projection3D

Projection3D()
Source code in pyronn/ct_reconstruction/layers/projection_3d.py
def __init__(self):
    # 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.
    self.backend = pyronn.read_backend()





pyronn.ct_reconstruction.layers.projection_3d.ConeProjectionFor3D

ConeProjectionFor3D()

Bases: Projection3D

Source code in pyronn/ct_reconstruction/layers/projection_3d.py
def __init__(self):
    # 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.
    self.backend = pyronn.read_backend()

forward

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

Projection for the 3D cone 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 3D cone beam CT.

Source code in pyronn/ct_reconstruction/layers/projection_3d.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.
    '''
    Projection for the 3D cone 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 3D cone beam CT.
    '''
    try:
        import torch
        from pyronn.ct_reconstruction.layers.torch.projection_3d import ConeProjection3D

        if not isinstance(input, torch.Tensor):
            phantom = torch.tensor(input.copy(), dtype=torch.float32).cuda()
        else:
            phantom = 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

        sinogram = ConeProjection3D().forward(phantom, **tensor_geometry)
        if for_train:
            return sinogram

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

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