Skip to content

Commit

Permalink
Merge pull request #23 from samuelstjean/save_original_header
Browse files Browse the repository at this point in the history
Save original header in final nifti file
  • Loading branch information
samuelstjean authored Jul 11, 2016
2 parents 1b70dfe + d630f0c commit 32deec3
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## [0.3.1] - 2016-07-11

- The original header is now saved back as-is to prevent potential conflicts
with other processing tools. Thanks to Derek Pisner for reporting.

## [0.3] - 2016-05-13

- sh_smooth now uses order 8 by default and a regularized pseudo-inverse for the fit.
Expand Down
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
include requirements.txt
include LICENSE
include README.md
include CHANGELOG.md
Expand Down
5 changes: 5 additions & 0 deletions nlsam/tests/test_scripts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ function check_return_code()
exit 1
fi
}

# Crop example dataset
python -c 'import nibabel as nib; import numpy as np; d = nib.load("dwi.nii.gz").get_data(); nib.save(nib.Nifti1Image(d[70:80],np.eye(4)), "dwi.nii.gz")'
python -c 'import nibabel as nib; import numpy as np; d = nib.load("mask.nii.gz").get_data(); nib.save(nib.Nifti1Image(d[70:80],np.eye(4)), "mask.nii.gz")'

# Test on example dataset
stabilizer dwi.nii.gz dwi_stab_localstd.nii.gz 1 sigma_localstd.nii.gz -m mask.nii.gz --bvals bvals --bvecs bvecs --noise_est local_std --smooth no_smoothing
check_return_code $?
Expand Down
4 changes: 3 additions & 1 deletion scripts/nlsam
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ def main():
vol = nib.load(args.input)
data = np.asarray(vol.get_data(caching='unchanged')) # To force ndarray instead of memmaps
affine = vol.get_affine()
header = vol.get_header()
header.set_data_dtype(np.float32)

sigma = nib.load(args.sigma).get_data()**2

Expand Down Expand Up @@ -227,7 +229,7 @@ def main():

data_denoised = data_denoised_insert

nib.save(nib.Nifti1Image(data_denoised.astype(original_dtype), affine), args.output)
nib.save(nib.Nifti1Image(data_denoised.astype(np.float32), affine, header), args.output)


if __name__ == "__main__":
Expand Down
10 changes: 6 additions & 4 deletions scripts/stabilizer
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ def buildArgsParser():
p.add_argument('--noise_map', action='store', dest='noise_maps',
metavar='string', required=False, default=None, type=str,
help='Path of the noise map(s) volume for local piesno.\n'
'Either supply a 3D noise map or a stack of 3D maps as a 4D volume.\n'+
'Either supply a 3D noise map or a stack of 3D maps as a 4D volume.\n' +
'Required for --noise_est noise_map')

p.add_argument('--noise_mask', action='store', dest='save_piesno_mask',
metavar='string', required=False, default=None, type=str,
help='If supplied, output filename for saving the mask of noisy voxels '
+ 'found by PIESNO.')
help='If supplied, output filename for saving the mask of noisy voxels ' +
'found by PIESNO.')

p.add_argument('--smooth', action='store', dest='smooth_method',
metavar='string', required=False, default='sh_smooth', type=str,
Expand Down Expand Up @@ -148,6 +148,8 @@ def main():
vol = nib.load(args.input)
data = np.asarray(vol.get_data(caching='unchanged')) # To force ndarray instead of memmaps
affine = vol.get_affine()
header = vol.get_header()
header.set_data_dtype(np.float32)

if args.mask is None:
mask = np.ones(data.shape[:-1], dtype=np.bool)
Expand Down Expand Up @@ -251,7 +253,7 @@ def main():
for idx in range(len(data_out)):
data_stabilized[..., idx, :] = data_out[idx]

nib.save(nib.Nifti1Image(data_stabilized, affine), args.output)
nib.save(nib.Nifti1Image(data_stabilized, affine, header), args.output)


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
params['author'] = 'Samuel St-Jean'
params['author_email'] = 'samuel@isi.uu.nl'
params['url'] = 'https://github.com/samuelstjean/nlsam'
params['version'] = '0.3'
params['version'] = '0.3.1'
params['requires'] = ['cythongsl>=0.2.1',
'numpy>=1.10.4',
'cython>=0.21']
Expand Down

0 comments on commit 32deec3

Please sign in to comment.