Skip to content

Commit

Permalink
FBP: removed duplicated and deprecated code
Browse files Browse the repository at this point in the history
Signed-off-by: Nicola VIGANÒ <nicola.vigano@cea.fr>
  • Loading branch information
Obi-Wan committed Jan 30, 2024
1 parent 1dd7fae commit cd8f84b
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 120 deletions.
89 changes: 0 additions & 89 deletions corrct/_projector_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,22 +245,6 @@ def bp(self, prj: NDArray, angle_ind: Optional[int] = None) -> NDArray:
The angle index to foward project. The default is None.
"""

@abstractmethod
def fbp(self, prj: NDArray, fbp_filter: Union[str, NDArray], pad_mode: str) -> NDArray:
"""Apply FBP.
Filtered back-projection interface. Derived backends need to implement this method.
Parameters
----------
prj : NDArray
The sinogram or stack of sinograms.
fbp_filter : str | NDArray, optional
The filter to use in the filtered back-projection.
pad_mode: str, optional
The padding mode to use for the linear convolution.
"""


class ProjectorBackendSKimage(ProjectorBackend):
"""Projector backend based on scikit-image."""
Expand Down Expand Up @@ -372,40 +356,6 @@ def bp(self, prj: NDArray, angle_ind: Optional[int] = None) -> NDArray:
vol = skt.iradon(prj[:, np.newaxis], self.angles_w_deg[angle_ind : angle_ind + 1 :], **bpj_size, **filter_name)
return vol * 2 / np.pi

def fbp(self, prj: NDArray, fbp_filter: Union[str, ArrayLike], pad_mode: str) -> NDArray:
"""Apply filtered back-projection of a sinogram or stack of sinograms.
Parameters
----------
prj : NDArray
The sinogram or stack of sinograms.
fbp_filter : str | ArrayLike, optional
The filter to use in the filtered back-projection.
pad_mode: str, optional
The padding mode to use for the linear convolution.
Returns
-------
vol : NDArray
The reconstructed volume.
"""
if pad_mode.lower() != "constant":
raise ValueError(f"Argument 'pad_mode' only supports 'constant', while {pad_mode.lower()} was given.")
if not isinstance(fbp_filter, str):
raise ValueError(f"Custom filters not supported in the scikit-image backend.")

filter_name = self._set_filter_name(fbp_filter.lower())
bpj_size = self._set_bpj_size(self.vol_shape_zxy[-1])
if len(prj.shape) > 2:
num_lines = prj.shape[1]
vol = np.empty([num_lines, *self.vol_shape_zxy], dtype=prj.dtype)

for ii_v in range(num_lines):
vol[ii_v, ...] = skt.iradon(prj[ii_v, ...].transpose(), self.angles_w_deg, **bpj_size, **filter_name)
return vol
else:
return skt.iradon(prj.transpose(), self.angles_w_deg, **bpj_size, **filter_name)


class ProjectorBackendASTRA(ProjectorBackend):
"""Projector backend based on astra-toolbox."""
Expand Down Expand Up @@ -699,45 +649,6 @@ def bp(self, prj: NDArray, angle_ind: Optional[int] = None) -> NDArray:

return vol

def fbp(self, prj: NDArray, fbp_filter: Union[str, NDArray, filters.Filter], pad_mode: str) -> NDArray:
"""Apply filtered back-projection of a sinogram or stack of sinograms.
Parameters
----------
prj : NDArray
The sinogram or stack of sinograms.
fbp_filter : str | NDArray | filtering.Filter, optional
The filter to use in the filtered back-projection.
pad_mode: str, optional
The padding mode to use for the linear convolution.
Returns
-------
vol : NDArray
The reconstructed volume.
"""
if isinstance(fbp_filter, str):
local_filter = filters.FilterFBP(filter_name=fbp_filter)
elif isinstance(fbp_filter, np.ndarray):
local_filter = filters.FilterCustom(fbp_filter)
else:
local_filter = fbp_filter
local_filter.pad_mode = pad_mode

prj_f = local_filter(prj)

if self.vol_geom.is_3D() or len(prj.shape) == 2:
return self.bp(prj_f)
else:
num_lines = prj.shape[-3]
vols = []

for ii_v in range(num_lines):
prj_v = np.ascontiguousarray(prj_f[ii_v, :, :])
vols.append(self.bp(prj_v))

return np.ascontiguousarray(np.stack(vols, axis=0))


class ProjectorBackendDirectASTRA(ProjectorBackendASTRA):
"""Experimental astra-toolbox functions projector."""
Expand Down
31 changes: 0 additions & 31 deletions corrct/projectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,37 +345,6 @@ def bp(self, prj_vwu: NDArray) -> NDArray:
prj_vwu = self.psf_vwu.T(prj_vwu)
return self.projector_backend.bp(prj_vwu)

def fbp(self, projs: NDArray, fbp_filter: Union[str, Callable] = "ramp", pad_mode: str = "constant") -> NDArray:
"""
Compute the filtered back-projection of the projection data to the volume.
The data could either be a sinogram, or a stack of sinograms.
Parameters
----------
projs : NDArray
The projection data to back-project.
fbp_filter : str | Callable, optional
The FBP filter to use. The default is "ramp".
pad_mode: str, optional
The padding mode to use for the linear convolution. The default is "constant".
Raises
------
ValueError
When trying to use fbp with a 3D projection geometry.
Returns
-------
NDArray
The FBP reconstructed volume.
"""
if isinstance(fbp_filter, str):
return self.projector_backend.fbp(projs, fbp_filter=fbp_filter, pad_mode=pad_mode)
else:
projs = fbp_filter(projs, self)
return self.bp(projs) / self.angles_rot_rad.size


class ProjectorAttenuationXRF(ProjectorUncorrected):
"""
Expand Down

0 comments on commit cd8f84b

Please sign in to comment.