Skip to content

Commit

Permalink
Add ability to mask with threshold
Browse files Browse the repository at this point in the history
  • Loading branch information
po09i committed Nov 3, 2020
1 parent ea1e7d1 commit b0eba3d
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions test/cli/test_cli_realtime_zshim.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from click.testing import CliRunner
from shimmingtoolbox.cli.realtime_zshim import realtime_zshim
from shimmingtoolbox.masking.shapes import shapes
from shimmingtoolbox.masking.threshold import threshold
from shimmingtoolbox.coils.coordinates import generate_meshgrid
from shimmingtoolbox.coils.siemens_basis import siemens_basis
from shimmingtoolbox import __dir_testing__
Expand All @@ -26,13 +27,19 @@ def test_cli_realtime_zshim():
affine = nii_fmap.affine

# Set up mask
nx, ny, nz, nt = fmap.shape
mask = shapes(fmap[:, :, :, 0], 'cube',
center_dim1=int(fmap.shape[0] / 2 - 8),
center_dim2=int(fmap.shape[1] / 2 - 5),
len_dim1=15, len_dim2=25, len_dim3=nz)
# Cube
# nx, ny, nz, nt = fmap.shape
# mask = shapes(fmap[:, :, :, 0], 'cube',
# center_dim1=int(fmap.shape[0] / 2 - 8),
# center_dim2=int(fmap.shape[1] / 2 - 5),
# len_dim1=15, len_dim2=25, len_dim3=nz)
# Threshold
fname_mag = os.path.join(__dir_testing__, 'realtime_zshimming_data', 'nifti', 'sub-example', 'fmap',
'sub-example_magnitude1.nii.gz')
mag = nib.load(fname_mag).get_fdata()
mask = threshold(mag, thr=50)

nii_mask = nib.Nifti1Image(mask.astype(int), affine)
nii_mask = nib.Nifti1Image(mask.astype(int)[:, :, :, 0], affine)
fname_mask = os.path.join(tmp, 'mask.nii.gz')
nib.save(nii_mask, fname_mask)

Expand Down

0 comments on commit b0eba3d

Please sign in to comment.