Skip to content
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 Reconstructors and API for easier MR reconstruction #57

Merged
merged 32 commits into from
Dec 17, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
c2e34bf
Add Reconstructors for easier MRI reconstruction
chaithyagr Nov 14, 2019
cebed14
Fix PEP8
chaithyagr Nov 14, 2019
7bb2c37
Fix by mistake deleted commit
chaithyagr Nov 15, 2019
98dbd8e
Fix PEP8 Errors
chaithyagr Nov 15, 2019
4f23c8e
Take in majority of review comments
chaithyagr Nov 18, 2019
110000a
WIP, update single channel recontruction based on new flow
chaithyagr Nov 18, 2019
360858b
Move kspace_data to reconstruct function
chaithyagr Nov 18, 2019
548bd66
WIP
chaithyagr Nov 18, 2019
68af0f5
Move to new flow for reconstruction
chaithyagr Nov 20, 2019
6679ee0
Move examples, fix tests, WIP as GPU test is broken
chaithyagr Nov 20, 2019
05bae94
Move non_cartesian_test to cpu
chaithyagr Nov 20, 2019
66b8017
Update to CI config to point mr_transform
chaithyagr Nov 20, 2019
4e367cf
Update docs
chaithyagr Nov 20, 2019
458e331
Update circleCI config
chaithyagr Nov 20, 2019
511894f
Update circleCI config
chaithyagr Nov 20, 2019
45fd9a5
Update circleCI config
chaithyagr Nov 20, 2019
6763d5d
Fixes and some refactoring
chaithyagr Nov 22, 2019
72e31aa
Changing examples to adapt to new flow
chaithyagr Nov 22, 2019
bf0c849
Taking Loubnas comments
chaithyagr Nov 25, 2019
cf48a97
Remove mu, change to regularizer_op
chaithyagr Nov 25, 2019
b3570eb
Update to nomenclature and docs
chaithyagr Nov 25, 2019
ec6b2ab
Add test checks for multiple channel tests
chaithyagr Nov 25, 2019
18168bd
Remove TODO
chaithyagr Nov 25, 2019
254943e
Change prox_op to dual regularizer
chaithyagr Nov 26, 2019
4a4f8bd
Final smaller doc changes and PEP
chaithyagr Nov 26, 2019
0ffcaca
Doc updates
chaithyagr Nov 26, 2019
df2cf21
Add tests
chaithyagr Nov 26, 2019
a5c8fa7
Remove extra args and add them to kwargs
chaithyagr Dec 5, 2019
ebe7f5d
Remove extra args and add them to kwargs. Update documentation
chaithyagr Dec 9, 2019
d7c9c07
Move regularizer op to kwargs and update documentation
chaithyagr Dec 9, 2019
a764142
Final doc changes
chaithyagr Dec 9, 2019
1322c15
Final doc changes
chaithyagr Dec 9, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 14 additions & 23 deletions examples/cartesian_reconstruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@
# Package import
from modopt.math.metrics import ssim
from mri.operators import FFT
from mri.optimizers import fista
from mri.reconstruct.utils import generate_operators
from mri.operators.utils import convert_mask_to_locations
from pysap.data import get_sample_data
from mri.reconstructors import SingleChannelReconstructor
import pysap
from pysap.data import get_sample_data
chaithyagr marked this conversation as resolved.
Show resolved Hide resolved

# Third party import
import numpy as np
Expand Down Expand Up @@ -67,29 +66,21 @@
# We now want to refine the zero order solution using a FISTA optimization.
# The cost function is set to Proximity Cost + Gradient Cost

# Generate operators
gradient_op, linear_op, prox_op, cost_op = generate_operators(
data=kspace_data,
# Setup the reconstructor
reconstructor = SingleChannelReconstructor(
kspace_data=kspace_data,
kspace_loc=kspace_loc,
uniform_data_shape=fourier_op.shape,
wavelet_name="sym8",
samples=kspace_loc,
nb_scales=4,
mu=2 * 1e-7,
nb_scale=4,
fourier_type='cartesian',
uniform_data_shape=None,
gradient_space="synthesis",
padding_mode="periodization")

# Start the FISTA reconstruction
max_iter = 200
x_final, costs, metrics = fista(
gradient_op,
linear_op,
prox_op,
cost_op,
lambda_init=1,
max_nb_of_iter=max_iter,
atol=1e-4,
verbose=1)
gradient_method='synthesis',
optimization_alg='fista',
verbose=1
)
# Start Reconstruction
x_final, costs, metrics = reconstructor.reconstruct(num_iterations=200)
image_rec = pysap.Image(data=np.abs(x_final))
# image_rec.show()
# Calculate SSIM
Expand Down
38 changes: 15 additions & 23 deletions examples/cartesian_reconstruction_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@
# Package import
from modopt.math.metrics import ssim
from mri.operators import FFT
from mri.optimizers import fista
from mri.reconstruct.utils import generate_operators
from mri.operators.utils import convert_mask_to_locations
from mri.reconstructors import SingleChannelReconstructor
from pysap.data import get_sample_data
import pysap

Expand Down Expand Up @@ -70,29 +69,22 @@
# We now want to refine the zero order solution using a FISTA optimization.
# The cost function is set to Proximity Cost + Gradient Cost

# Generate operators
gradient_op, linear_op, prox_op, cost_op = generate_operators(
data=kspace_data,
# Setup the reconstructor
reconstructor = SingleChannelReconstructor(
kspace_data=kspace_data,
kspace_loc=kspace_loc,
uniform_data_shape=fourier_op.shape,
wavelet_name="sym8",
samples=kspace_loc,
nb_scales=2,
mu=2*1e-11,
mu=2 * 1e-11,
nb_scale=4,
fourier_type='cartesian',
uniform_data_shape=None,
gradient_space="synthesis",
padding_mode="periodization")

# Start the FISTA reconstruction
max_iter = 200
x_final, costs, metrics = fista(
gradient_op,
linear_op,
prox_op,
cost_op,
lambda_init=1,
max_nb_of_iter=max_iter,
atol=1e-4,
verbose=1)
gradient_method='synthesis',
optimization_alg='fista',
padding_mode='periodization',
verbose=1
chaithyagr marked this conversation as resolved.
Show resolved Hide resolved
)
# Start Reconstruction
x_final, costs, metrics = reconstructor.reconstruct(num_iterations=200)
image_rec = pysap.Image(data=np.abs(x_final))
# image_rec.show()
# Calculate SSIM
Expand Down
37 changes: 14 additions & 23 deletions examples/non_cartesian_reconstruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@

# Package import
from mri.operators import NonCartesianFFT
from mri.optimizers import fista
from mri.reconstruct.utils import generate_operators
from mri.operators.utils import convert_locations_to_mask
from mri.parallel_mri.extract_sensitivity_maps import \
from mri.operators.utils import convert_locations_to_mask, \
gridded_inverse_fourier_transform_nd
from mri.reconstructors import SingleChannelReconstructor
import pysap
from pysap.data import get_sample_data

Expand Down Expand Up @@ -70,29 +68,22 @@
# We now want to refine the zero order solution using a FISTA optimization.
# The cost function is set to Proximity Cost + Gradient Cost

# Generate operators
gradient_op, linear_op, prox_op, cost_op = generate_operators(
data=kspace_obs,
# Setup the reconstructor
reconstructor = SingleChannelReconstructor(
kspace_data=kspace_obs,
kspace_loc=kspace_loc,
uniform_data_shape=image.shape,
wavelet_name="sym8",
samples=kspace_loc,
mu=6 * 1e-7,
nb_scales=4,
nb_scale=4,
fourier_type='non-cartesian',
nfft_implementation='cpu',
uniform_data_shape=image.shape,
gradient_space="synthesis")

# Start the FISTA reconstruction
max_iter = 200
x_final, costs, metrics = fista(
gradient_op=gradient_op,
linear_op=linear_op,
prox_op=prox_op,
cost_op=cost_op,
lambda_init=1.0,
max_nb_of_iter=max_iter,
atol=1e-4,
verbose=1)
gradient_method='synthesis',
optimization_alg='fista',
verbose=1
)
# Start Reconstruction
x_final, costs, metrics = reconstructor.reconstruct(num_iterations=200)
image_rec = pysap.Image(data=np.abs(x_final))
# image_rec.show()
recon_ssim = ssim(image_rec, image)
Expand Down
38 changes: 14 additions & 24 deletions examples/non_cartesian_reconstruction_stack_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@

# Package import
from mri.operators import Stacked3DNFFT
from mri.optimizers import fista
from mri.reconstruct.utils import generate_operators
from mri.operators.utils import convert_locations_to_mask, get_stacks_fourier
from mri.parallel_mri.extract_sensitivity_maps import \
gridded_inverse_fourier_transform_stack
from mri.operators.utils import convert_locations_to_mask, \
gridded_inverse_fourier_transform_stack, get_stacks_fourier
from mri.reconstructors import SingleChannelReconstructor
import pysap
from pysap.data import get_sample_data

Expand Down Expand Up @@ -82,29 +80,21 @@
# The cost function is set to Proximity Cost + Gradient Cost

# TODO get the right mu operator
# Generate operators
gradient_op, linear_op, prox_op, cost_op = generate_operators(
data=kspace_obs,
# Setup the reconstructor
reconstructor = SingleChannelReconstructor(
kspace_data=kspace_obs,
kspace_loc=kspace_loc,
uniform_data_shape=image.shape,
wavelet_name="sym8",
samples=kspace_loc,
mu=6 * 1e-9,
nb_scales=4,
nb_scale=4,
fourier_type='stack',
nfft_implementation='cpu',
uniform_data_shape=image.shape,
gradient_space="synthesis")

# Start the FISTA reconstruction
max_iter = 10
x_final, costs, metrics = fista(
gradient_op=gradient_op,
linear_op=linear_op,
prox_op=prox_op,
cost_op=cost_op,
lambda_init=1.0,
max_nb_of_iter=max_iter,
atol=1e-4,
verbose=1)
gradient_method='synthesis',
optimization_alg='fista',
verbose=1
)
x_final, costs, metrics = reconstructor.reconstruct(num_iterations=200)
image_rec = pysap.Image(data=np.abs(x_final))
# image_rec.show()
recon_ssim = ssim(image_rec, image)
Expand Down
Loading