Skip to content

Commit

Permalink
Small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmaRenauld committed Sep 17, 2024
1 parent 234dd04 commit 5c60070
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
4 changes: 3 additions & 1 deletion scilpy/stats/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@ def estimate_piesno_sigma(data, number_coils=0):
----------
data: np.ndarray
The 4D volume.
number_coils: int
The number of coils in the scanner.
"""
assert len(data.shape) == 4

sigma = np.zeros(data.shape[:3], dtype=np.float32)
mask_noise = np.zeros(data.shape[:3], dtype=np.int16)

for idx in range(data.shape[-2]):
logging.info('Now processing slice {} / {}}'
logging.info('Now processing slice {} / {}'
.format(idx + 1, data.shape[-2]))
sigma[..., idx], mask_noise[..., idx] = \
piesno(data[..., idx, :], N=number_coils, return_mask=True)
Expand Down
11 changes: 6 additions & 5 deletions scripts/scil_denoising_nlmeans.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ def main():
"and piesno options.")

if args.piesno or args.sigma:
if args.noise_from_all_voxels:
parser.error("You selected --noise_from_all_voxels, but this is "
if args.sigma_from_all_voxels:
parser.error("You selected --sigma_from_all_voxels, but this is "
"only available for the --basic_sigma method.")
if args.mask_sigma:
parser.error("You selected --mask_sigma, but this is "
Expand All @@ -163,7 +163,8 @@ def main():
parser.error("Option --save_piesno_mask cannot be used when --pieno "
"is not selected.")

assert_inputs_exist(parser, args.in_image, args.mask)
assert_inputs_exist(parser, args.in_image,
[args.mask_denoise, args.mask_sigma])
assert_outputs_exist(parser, args, args.out_image,
[args.logfile, args.save_piesno_mask])
assert_headers_compatible(parser, args.in_image,
Expand All @@ -173,7 +174,7 @@ def main():
vol = nib.load(args.in_image)
vol_data = vol.get_fdata(dtype=np.float32)

if len(vol_data.shape) != 4 or vol_data.shape[3] == 1:
if args.piesno and (len(vol_data.shape) != 4 or vol_data.shape[3] == 1):
parser.error("The piesno method requires 4D data.")

# Denoising mask
Expand Down Expand Up @@ -224,7 +225,7 @@ def main():
with warnings.catch_warnings():
warnings.simplefilter("ignore", category=DeprecationWarning)
data_denoised = nlmeans(
vol_data, sigma, mask=mask_denoise, rician=args.rician,
vol_data, sigma, mask=mask_denoise, rician=not args.gaussian,
num_threads=args.nbr_processes)

# Saving
Expand Down
5 changes: 3 additions & 2 deletions scripts/tests/test_denoising_nlmeans.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ def test_execution_basic(script_runner, monkeypatch):
in_img = os.path.join(SCILPY_HOME, 'others', 't1_resample.nii.gz')
ret = script_runner.run('scil_denoising_nlmeans.py', in_img,
't1_denoised.nii.gz', '--processes', '1',
'--basic_sigma')
'--basic_sigma', '--number_coils', 0,
'--gaussian')
assert ret.success


Expand All @@ -31,6 +32,6 @@ def test_execution_piesno(script_runner, monkeypatch):
in_img = os.path.join(SCILPY_HOME, 'processing', 'dwi.nii.gz')
ret = script_runner.run('scil_denoising_nlmeans.py', in_img,
'dwi_denoised.nii.gz', '--processes', '1',
'--piesno')
'--piesno', '--number_coils', '4')
assert ret.success

0 comments on commit 5c60070

Please sign in to comment.