-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for 3D tomographic projection with astra #427
Merged
Merged
Changes from 15 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
9d598fe
Rough in a 2D/3D astra wrapper
Michael-T-McCann 4b3895e
Fix output_shape
Michael-T-McCann 654b10f
Add test
Michael-T-McCann f58cb60
Free sino memory
Michael-T-McCann 88b7122
Add example and exclude from CPU CI
Michael-T-McCann 1b27e57
Fix mypy problems
Michael-T-McCann cfb4a88
Fix scriptcheck option
Michael-T-McCann 0237326
Make assert less restrictive
Michael-T-McCann 696ad3c
Update submodule with new notebook
Michael-T-McCann b462330
Add example to docs
Michael-T-McCann 74637a0
Handle review comments
Michael-T-McCann 2f6aaad
Update data submodule
Michael-T-McCann f592b24
Update submodule
bwohlberg cec0cd2
Merge branch 'main' into mike/astra_3d
bwohlberg 42f9e97
Add test for new function
bwohlberg 170ac4a
Fix example script, cleanup doc
Michael-T-McCann 8bf2a74
Update submodules
Michael-T-McCann File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule data
updated
2 files
+19 −0 | notebooks/ct_astra_3d_tv_admm.ipynb | |
+7 −1 | notebooks/index.ipynb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
# This file is part of the SCICO package. Details of the copyright | ||
# and user license can be found in the 'LICENSE.txt' file distributed | ||
# with the package. | ||
|
||
r""" | ||
3D TV-Regularized Sparse-View CT Reconstruction | ||
=============================================== | ||
|
||
This example demonstrates solution of a sparse-view, 3D CT | ||
reconstruction problem with isotropic total variation (TV) | ||
regularization | ||
|
||
$$\mathrm{argmin}_{\mathbf{x}} \; (1/2) \| \mathbf{y} - A \mathbf{x} | ||
\|_2^2 + \lambda \| C \mathbf{x} \|_{2,1} \;,$$ | ||
|
||
where $A$ is the Radon transform, $\mathbf{y}$ is the sinogram, $C$ is | ||
a 3D finite difference operator, and $\mathbf{x}$ is the desired | ||
image. | ||
""" | ||
|
||
import numpy as np | ||
|
||
import jax | ||
|
||
from mpl_toolkits.axes_grid1 import make_axes_locatable | ||
|
||
from scico import functional, linop, loss, metric, plot | ||
from scico.examples import create_tangle_phantom | ||
from scico.linop.radon_astra import TomographicProjector | ||
from scico.optimize.admm import ADMM, LinearSubproblemSolver | ||
from scico.util import device_info | ||
|
||
Nx = 128 | ||
Ny = 256 | ||
Nz = 64 | ||
|
||
tangle = create_tangle_phantom(Nx, Ny, Nz) | ||
tangle = jax.device_put(tangle) | ||
|
||
n_projection = 10 # number of projections | ||
angles = np.linspace(0, np.pi, n_projection) # evenly spaced projection angles | ||
A = TomographicProjector( | ||
tangle.shape, [1.0, 1.0], [Nz, max(Nx, Ny)], angles | ||
) # Radon transform operator | ||
y = A @ tangle # sinogram | ||
|
||
|
||
""" | ||
Set up ADMM solver object. | ||
""" | ||
λ = 2e0 # L1 norm regularization parameter | ||
ρ = 5e0 # ADMM penalty parameter | ||
maxiter = 25 # number of ADMM iterations | ||
cg_tol = 1e-4 # CG relative tolerance | ||
cg_maxiter = 25 # maximum CG iterations per ADMM iteration | ||
|
||
# The append=0 option makes the results of horizontal and vertical | ||
# finite differences the same shape, which is required for the L21Norm, | ||
# which is used so that g(Cx) corresponds to isotropic TV. | ||
C = linop.FiniteDifference(input_shape=tangle.shape, append=0) | ||
g = λ * functional.L21Norm() | ||
|
||
f = loss.SquaredL2Loss(y=y, A=A) | ||
|
||
x0 = A.T(y) | ||
|
||
solver = ADMM( | ||
f=f, | ||
g_list=[g], | ||
C_list=[C], | ||
rho_list=[ρ], | ||
x0=x0, | ||
maxiter=maxiter, | ||
subproblem_solver=LinearSubproblemSolver(cg_kwargs={"tol": cg_tol, "maxiter": cg_maxiter}), | ||
itstat_options={"display": True, "period": 5}, | ||
) | ||
|
||
""" | ||
Run the solver. | ||
""" | ||
print(f"Solving on {device_info()}\n") | ||
solver.solve() | ||
hist = solver.itstat_object.history(transpose=True) | ||
tangle_recon = solver.x | ||
|
||
print( | ||
"TV Restruction\nSNR: %.2f (dB), MAE: %.3f" | ||
% (metric.snr(tangle, tangle_recon), metric.mae(tangle, tangle_recon)) | ||
) | ||
|
||
""" | ||
Show the recovered image. | ||
""" | ||
fig, ax = plot.subplots(nrows=1, ncols=2, figsize=(7, 5)) | ||
plot.imview(tangle[32], title="Ground truth (central slice)", cbar=None, fig=fig, ax=ax[0]) | ||
|
||
plot.imview( | ||
tangle_recon[32], | ||
title="TV Reconstruction (central slice)\nSNR: %.2f (dB), MAE: %.3f" | ||
% (metric.snr(tangle, tangle_recon), metric.mae(tangle, tangle_recon)), | ||
fig=fig, | ||
ax=ax[1], | ||
) | ||
divider = make_axes_locatable(ax[1]) | ||
cax = divider.append_axes("right", size="5%", pad=0.2) | ||
fig.colorbar(ax[1].get_images()[0], cax=cax, label="arbitrary units") | ||
fig.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new example has been added to the main index file, but I don't see it in the built docs. Perhaps you still need to run
makeindex.py
and commit the changed secondary index files?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I did this, but it's still not showing up as far as I can tell. Any suggestions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps a problem with the submodule commit attached to this branch. When the submodule changes in a PR, it's usually cleanest to make a corresponding branch and PR for
scico-data
, with the submodule here linked to the head of that branch.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, the generated notebook was blank and sphinx was smart enough to not include it. Working on a fix.