Skip to content

ENH: Wrapper for DenoiseImage #1291

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

Merged
merged 15 commits into from
Dec 23, 2015
Merged

ENH: Wrapper for DenoiseImage #1291

merged 15 commits into from
Dec 23, 2015

Conversation

jessicaforbes
Copy link
Contributor

This provides a Nipype wrapper for the DenoiseImage program provided as part of ANTs.

It is a fairly simple interface seen here:

$ ./DenoiseImage
COMMAND:
DenoiseImage
Denoise an image using a spatially adaptive filter originally described in J. V.
Manjon, P. Coupe, Luis Marti-Bonmati, D. L. Collins, and M. Robles. Adaptive
Non-Local Means Denoising of MR Images With Spatially Varying Noise Levels,
Journal of Magnetic Resonance Imaging, 31:192-203, June 2010.
OPTIONS:
-d, --image-dimensionality 2/3/4
This option forces the image to be treated as a specified-dimensional image. If
not specified, the program tries to infer the dimensionality from the input
image.
-i, --input-image inputImageFilename
A scalar image is expected as input for noise correction.
-n, --noise-model Rician/(Gaussian)
Employ a Rician or Gaussian noise model.
-s, --shrink-factor (1)/2/3/...
Running noise correction on large images can be time consuming. To lessen
computation time, the input image can be resampled. The shrink factor, specified
as a single integer, describes this resampling. Shrink factor = 1 is the
default.
-o, --output correctedImage
[correctedImage,]
The output consists of the noise corrected version of the input image.
Optionally, one can also output the estimated noise image.
--version
Get Version Information.
-v, --verbose (0)/1
Verbose output.
-h
Print the help menu (short version).
--help
Print the help menu.

@blakedewey
Copy link
Contributor

This looks like a good addition, but it needs a few changes before we can merge it.

  1. We don't have the need for version, help or short_help options, as nipype is a pipelining tool and a pipeline would not need to see the output if those options are set.
  2. In the ANTs interfaces, we have developed a good way to specify more than one output file. See if you can replicate the style used in N4BiasFieldCorrection.

If you have any questions, just let me know.

This replicates the method from in N4BiasFieldCorrection used to
specify more than one output file (as suggested by blakedewey).
It updates the doctest and test_auto_DenoiseImage.py with new
variables save_noise and noise_image. It alse removes the version,
help, and short_help options since nipype is a pipelining tool
and a pipeline would not need to see the output if those options
are set.
@jessicaforbes
Copy link
Contributor Author

@blakedewey I implemented your suggestions of removing the help/version variables and replicating the output style used in N4BiasFieldCorrection. The tests are currently running.

Thank you for the tips.

@blakedewey
Copy link
Contributor

@satra What is with the codacy failure?

'the input image can be resampled. The shrink '
'factor, specified as a single integer, describes '
'this resampling. Shrink factor = 1 is the default.'))
output_image = traits.Str(argstr="-o %s", genfile=True, hash_files=False,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can skip genfile (and the need to define _gen_filename) if you use name_source and name_template (more info here: http://nipy.org/nipype/devel/cmd_interface_devel.html#creating-outputs-on-the-fly). This will simplify the interface.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same thing applies for noise_image

This removes the genfile and _gen_filename function. It now uses
the name_source and name_template options to simplify the
interface.
@jessicaforbes
Copy link
Contributor Author

For output_image and noise_image I am setting keep_extension=True, but this does not seem to work. The output_image does not have an extension. Can someone please explain if there is an error with keep_extension or if I need to change something?

output_image = File(argstr="-o %s", name_source=['input_image'], hash_files=False,
keep_extension=True, name_template='%s_noise_corrected',
desc='The output consists of the noise corrected '
'version of the input image.')

Error with the Travis CI build is due to missing extensions in the cmdline outputs:

File "/home/travis/build/nipy/nipype/nipype/interfaces/ants/segmentation.py", line 843, in nipype.interfaces.ants.segmentation.DenoiseImage
Failed example:
denoise.cmdline
Expected:
'DenoiseImage -d 3 -i im1.nii -n Gaussian -o im1_noise_corrected.nii -s 1'
Got:
'DenoiseImage -d 3 -i im1.nii -n Gaussian -o im1_noise_corrected -s 1'

File "/home/travis/build/nipy/nipype/nipype/interfaces/ants/segmentation.py", line 856, in nipype.interfaces.ants.segmentation.DenoiseImage
Failed example:
denoise_3.cmdline
Expected:
'DenoiseImage -i im1.nii -n Gaussian -o [ im1_noise_corrected.nii, im1_noise.nii ] -s 1'
Got:
'DenoiseImage -i im1.nii -n Gaussian -o [ im1_noise_corrected, im1_noise ] -s 1'

satra and others added 3 commits December 22, 2015 16:05
* upstream/master:
  fix: fixes issue #1227 when install fails with pypi
  fix: decode bytes output when multiprocessing plugin is used with stdout/err
  fix: from make check
@jessicaforbes
Copy link
Contributor Author

Thank you @satra for fixing the keep_extension metadata behavior.

@jessicaforbes
Copy link
Contributor Author

I am not sure what the codacy issue is or how to fix it.

@chrisgorgo
Copy link
Member

Codacy claims that this PR increased "complexity" of the code, but does not provide much details. Let's ignore this one. Thank you for your contribution!

chrisgorgo added a commit that referenced this pull request Dec 23, 2015
@chrisgorgo chrisgorgo merged commit a4b1867 into nipy:master Dec 23, 2015
@hjmjohnson hjmjohnson deleted the wrapDenoiseImage branch January 19, 2016 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants