Skip to content

Commit 0fa255e

Browse files
committed
CAT12SANLMDenoising_1st_commit
1 parent 0289137 commit 0fa255e

File tree

2 files changed

+140
-1
lines changed

2 files changed

+140
-1
lines changed

nipype/interfaces/cat12/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
from .preprocess import CAT12Segment
1+
from .preprocess import (
2+
CAT12Segment,
3+
CAT12SANLMDenoising
4+
)
25
from .surface import (
36
ExtractAdditionalSurfaceParameters,
47
ExtractROIBasedSurfaceMeasures,

nipype/interfaces/cat12/preprocess.py

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,142 @@ def _list_outputs(self):
593593
return outputs
594594

595595

596+
class CAT12SANLMDenoisingInputSpec(SPMCommandInputSpec):
597+
598+
in_files = InputMultiPath(
599+
ImageFileSPM(exists=True),
600+
field="data",
601+
desc="Images for filtering.",
602+
mandatory=True,
603+
copyfile=False,
604+
)
605+
606+
spm_type = traits.Enum(
607+
16,
608+
0,
609+
2,
610+
512,
611+
field='spm_type',
612+
usedefault=True,
613+
desc='Data type of the output images. 0 = same, 2 = uint8, 512 = uint16, 16 = single (32 bit)'
614+
615+
)
616+
617+
intlim = traits.Int(
618+
field='intlim',
619+
default_value=100,
620+
usedefault=True,
621+
)
622+
623+
filename_prefix = traits.Str(
624+
field='prefix',
625+
default_value='sanlm_',
626+
usedefault=True,
627+
desc='Filename prefix. Specify the string to be prepended to the filenames of the filtered image file(s). Default prefix is "samlm_".',
628+
)
629+
630+
filename_suffix= traits.Str(
631+
field='suffix',
632+
default_value='',
633+
usedefault=True,
634+
desc='Filename suffix. Specify the string to be appended to the filenames of the filtered image file(s). Default suffix is "".'
635+
)
636+
637+
addnoise = traits.Float(default_value=0.5,
638+
usedefault=True,
639+
field='addnoise',
640+
desc='Strength of additional noise in noise-free regions. Add minimal amount of noise in regions without any noise to avoid image segmentation problems. This parameter defines the strength of additional noise as percentage of the average signal intensity.')
641+
642+
rician = traits.Enum(
643+
0,
644+
1,
645+
field='rician',
646+
usedefault=True,
647+
desc='''Rician noise
648+
MRIs can have Gaussian or Rician distributed noise with uniform or nonuniform variance across the image. If SNR is high enough
649+
(>3) noise can be well approximated by Gaussian noise in the foreground. However, for SENSE reconstruction or DTI data a Rician
650+
distribution is expected. Please note that the Rician noise estimation is sensitive for large signals in the neighbourhood and can lead to
651+
artefacts, e.g. cortex can be affected by very high values in the scalp or in blood vessels.''')
652+
653+
replaceNANandINF = traits.Enum(
654+
1,
655+
0,
656+
field='replaceNANandINF',
657+
usedefault=True,
658+
desc='Replace NAN by 0, -INF by the minimum and INF by the maximum of the image.'
659+
)
660+
661+
NCstr = traits.Enum(
662+
'-Inf',
663+
2,
664+
4,
665+
field='nlmfilter.optimized.NCstr',
666+
usedefault=True,
667+
desc='''Strength of Noise Corrections
668+
Strength of the (sub-resolution) spatial adaptive non local means (SANLM) noise correction. Please note that the filter strength is
669+
automatically estimated. Change this parameter only for specific conditions. The "light" option applies half of the filter strength of the
670+
adaptive "medium" cases, whereas the "strong" option uses the full filter strength, force sub-resolution filtering and applies an
671+
additional iteration. Sub-resolution filtering is only used in case of high image resolution below 0.8 mm or in case of the "strong"
672+
option. light = 2, medium = -Inf, strong = 4'''
673+
)
674+
675+
676+
class CAT12SANLMDenoisingOutputSpec(TraitedSpec):
677+
678+
out_file = File(desc='out file')
679+
680+
681+
class CAT12SANLMDenoising(SPMCommand):
682+
"""
683+
Spatially adaptive non-local means (SANLM) denoising filter
684+
685+
This function applies an spatial adaptive (sub-resolution) non-local means denoising filter
686+
to the data. This filter will remove noise while preserving edges. The filter strength is
687+
automatically estimated based on the standard deviation of the noise.
688+
689+
This filter is internally used in the segmentation procedure anyway. Thus, it is not
690+
necessary (and not recommended) to apply the filter before segmentation.
691+
692+
693+
Example:
694+
=======
695+
from nipype.interfaces import cat12
696+
c = cat12.CAT12SANLMDenoising()
697+
c.inputs.in_files='sub-test_FLAIR.nii'
698+
c.run()
699+
"""
700+
701+
input_spec = CAT12SANLMDenoisingInputSpec
702+
output_spec = CAT12SANLMDenoisingOutputSpec
703+
704+
def __init__(self, **inputs):
705+
_local_version = SPMCommand().version
706+
if _local_version and "12." in _local_version:
707+
self._jobtype = "tools"
708+
self._jobname = "cat.tools.sanlm"
709+
710+
SPMCommand.__init__(self, **inputs)
711+
712+
def _format_arg(self, opt, spec, val):
713+
"""Convert input to appropriate format for spm"""
714+
if opt == "in_files":
715+
if isinstance(val, list):
716+
return scans_for_fnames(val)
717+
else:
718+
return scans_for_fname(val)
719+
720+
return super(CAT12SANLMDenoising, self)._format_arg(opt, spec, val)
721+
722+
def _list_outputs(self):
723+
outputs = self._outputs().get()
724+
pth, base, ext = split_filename(self.inputs.in_files[0])
725+
outputs['out_file'] = os.path.join(os.getcwd(), self.inputs.filename_prefix +
726+
base +
727+
self.inputs.filename_suffix +
728+
ext)
729+
return outputs
730+
731+
596732
class Cell2Str(Cell):
597733
def __str__(self):
598734
"""Convert input to appropriate format for cat12"""

0 commit comments

Comments
 (0)