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 26 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
11 changes: 8 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,25 @@ jobs:
command: |
python3 -m venv venv
. venv/bin/activate
pushd ../
zaccharieramzi marked this conversation as resolved.
Show resolved Hide resolved
git clone https://github.com/CEA-COSMIC/pysap
cd pysap
python setup.py install
echo "export PATH=$PATH:$PWD/build/temp.linux-x86_64-3.6/extern/bin" >> $BASH_ENV
popd
pip install -r doc/requirements.txt
pip list > doc/state.txt
- save_cache:
paths:
- ./venv
key: v1-dependencies-{{ checksum "doc/requirements.txt" }}
key: v1-dependencies-{{ checksum "doc/state.txt" }}
- run:
name: Running CircleCI tests
command: |
. venv/bin/activate
pip install Cython
pip install git+https://github.com/CEA-COSMIC/pysap.git
pip install -e .
python .circleci/test_script.py
- store_artifacts:
path: test-reports
destination: test-reports

51 changes: 23 additions & 28 deletions examples/cartesian_reconstruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@
"""

# 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 import FFT, WaveletN
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
from modopt.opt.proximity import SparseThreshold
from modopt.opt.linear import Identity
from modopt.math.metrics import ssim
import numpy as np

# Loading input data
Expand Down Expand Up @@ -67,29 +68,23 @@
# 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,
wavelet_name="sym8",
samples=kspace_loc,
nb_scales=4,
mu=2 * 1e-7,
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)
# Setup the operators
linear_op = WaveletN(wavelet_name="sym8", nb_scales=4)
regularizer_op = SparseThreshold(Identity(), 2 * 1e-7, thresh_type="soft")
# Setup Reconstructor
reconstructor = SingleChannelReconstructor(
fourier_op=fourier_op,
linear_op=linear_op,
regularizer_op=regularizer_op,
gradient_formulation='synthesis',
verbose=1,
)
# Start Reconstruction
x_final, costs, metrics = reconstructor.reconstruct(
kspace_data=kspace_data,
optimization_alg='fista',
num_iterations=200,
)
image_rec = pysap.Image(data=np.abs(x_final))
# image_rec.show()
# Calculate SSIM
Expand Down
50 changes: 25 additions & 25 deletions examples/cartesian_reconstruction_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@

# 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 import FFT, WaveletN
from mri.operators.utils import convert_mask_to_locations
from mri.reconstructors import SingleChannelReconstructor
from pysap.data import get_sample_data
import pysap

# Third party import
from modopt.opt.linear import Identity
from modopt.opt.proximity import SparseThreshold
import numpy as np

# Loading input data and convert it into a single channel using Sum-Of-Squares
Expand Down Expand Up @@ -70,29 +71,28 @@
# 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 operators
linear_op = WaveletN(
wavelet_name="sym8",
samples=kspace_loc,
nb_scales=2,
mu=2*1e-11,
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)
nb_scales=4,
dim=3,
padding_mode="periodization",
)
regularizer_op = SparseThreshold(Identity(), 2 * 1e-11, thresh_type="soft")
# Setup Reconstructor
reconstructor = SingleChannelReconstructor(
fourier_op=fourier_op,
linear_op=linear_op,
regularizer_op=regularizer_op,
gradient_formulation='synthesis',
verbose=1,
)
# Start Reconstruction
x_final, costs, metrics = reconstructor.reconstruct(
kspace_data=kspace_data,
optimization_alg='fista',
LElgueddari marked this conversation as resolved.
Show resolved Hide resolved
num_iterations=200,
)
image_rec = pysap.Image(data=np.abs(x_final))
# image_rec.show()
# Calculate SSIM
Expand Down
50 changes: 23 additions & 27 deletions examples/non_cartesian_reconstruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@
"""

# 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 import NonCartesianFFT, WaveletUD2
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

# Third party import
from modopt.math.metrics import ssim
from modopt.opt.linear import Identity
from modopt.opt.proximity import SparseThreshold
import numpy as np

# Loading input data
Expand Down Expand Up @@ -70,29 +70,25 @@
# 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,
wavelet_name="sym8",
samples=kspace_loc,
mu=6 * 1e-7,
nb_scales=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,
# Setup the operators
linear_op = WaveletUD2(
wavelet_id=24,
nb_scale=4,
)
regularizer_op = SparseThreshold(Identity(), 6 * 1e-7, thresh_type="soft")
# Setup Reconstructor
reconstructor = SingleChannelReconstructor(
fourier_op=fourier_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)
regularizer_op=regularizer_op,
gradient_formulation='synthesis',
verbose=1,
)
x_final, costs, metrics = reconstructor.reconstruct(
kspace_data=kspace_obs,
optimization_alg='fista',
num_iterations=200,
)
image_rec = pysap.Image(data=np.abs(x_final))
# image_rec.show()
recon_ssim = ssim(image_rec, image)
Expand Down
50 changes: 22 additions & 28 deletions examples/non_cartesian_reconstruction_stack_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@
"""

# 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 import Stacked3DNFFT, WaveletN
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

# Third party import
from modopt.math.metrics import ssim
from modopt.opt.linear import Identity
from modopt.opt.proximity import SparseThreshold
chaithyagr marked this conversation as resolved.
Show resolved Hide resolved
import numpy as np

# Loading input data
Expand Down Expand Up @@ -82,29 +82,23 @@
# 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,
wavelet_name="sym8",
samples=kspace_loc,
mu=6 * 1e-9,
nb_scales=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,
# Setup the operators
linear_op = WaveletN(wavelet_name="sym8", nb_scales=4)
regularizer_op = SparseThreshold(Identity(), 6 * 1e-9, thresh_type="soft")
# Setup Reconstructor
reconstructor = SingleChannelReconstructor(
fourier_op=fourier_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)
regularizer_op=regularizer_op,
gradient_formulation='synthesis',
verbose=1,
)
# Start Reconstruction
x_final, costs, metrics = reconstructor.reconstruct(
kspace_data=kspace_obs,
optimization_alg='fista',
num_iterations=10,
)
image_rec = pysap.Image(data=np.abs(x_final))
# image_rec.show()
recon_ssim = ssim(image_rec, image)
Expand Down
Loading