@@ -677,3 +677,99 @@ def _list_outputs(self):
677677 outputs = self .output_spec ().get ()
678678 outputs ['out_file' ] = op .abspath (self .inputs .out_file )
679679 return outputs
680+
681+
682+ class MRResizeInputSpec (MRTrix3BaseInputSpec ):
683+ in_file = File (
684+ exists = True ,
685+ argstr = '%s' ,
686+ position = - 2 ,
687+ mandatory = True ,
688+ desc = 'input DWI image'
689+ )
690+ image_size = traits .Tuple (
691+ (traits .Int , traits .Int , traits .Int ),
692+ argstr = '-size %d,%d,%d' ,
693+ mandatory = True ,
694+ desc = 'Number of voxels in each dimension of output image' ,
695+ xor = ['voxel_size' , 'scale_factor' ],
696+ )
697+ voxel_size = traits .Tuple (
698+ (traits .Float , traits .Float , traits .Float ),
699+ argstr = '-voxel %g,%g,%g' ,
700+ mandatory = True ,
701+ desc = 'Desired voxel size in mm for the output image' ,
702+ xor = ['image_size' , 'scale_factor' ],
703+ )
704+ scale_factor = traits .Tuple (
705+ (traits .Float , traits .Float , traits .Float ),
706+ argstr = '-scale %g,%g,%g' ,
707+ mandatory = True ,
708+ desc = 'Scale factors to rescale the image by in each dimension' ,
709+ xor = ['image_size' , 'voxel_size' ],
710+ )
711+ interpolation = traits .Enum (
712+ 'cubic' ,
713+ 'nearest' ,
714+ 'linear' ,
715+ 'sinc' ,
716+ argstr = '-interp %s' ,
717+ usedefault = True ,
718+ desc = 'set the interpolation method to use when resizing (choices: '
719+ 'nearest, linear, cubic, sinc. Default: cubic).' ,
720+ )
721+ out_file = File (
722+ argstr = '%s' ,
723+ name_template = '%s_resized' ,
724+ name_source = ['in_file' ],
725+ keep_extension = True ,
726+ position = - 1 ,
727+ desc = 'the output resized DWI image' ,
728+ )
729+
730+
731+ class MRResizeOutputSpec (TraitedSpec ):
732+ out_file = File (desc = 'the output resized DWI image' , exists = True )
733+
734+
735+ class MRResize (MRTrix3Base ):
736+ """
737+ Resize an image by defining the new image resolution, voxel size or a
738+ scale factor. If the image is 4D, then only the first 3 dimensions can be
739+ resized. Also, if the image is down-sampled, the appropriate smoothing is
740+ automatically applied using Gaussian smoothing.
741+ For more information, see
742+ <https://mrtrix.readthedocs.io/en/latest/reference/commands/mrresize.html>
743+
744+ Example
745+ -------
746+ >>> import nipype.interfaces.mrtrix3 as mrt
747+
748+ Defining the new image resolution:
749+ >>> image_resize = mrt.MRResize()
750+ >>> image_resize.inputs.in_file = 'dwi.mif'
751+ >>> image_resize.inputs.image_size = (256, 256, 144)
752+ >>> image_resize.cmdline # doctest: +ELLIPSIS
753+ 'mrresize -size 256,256,144 -interp cubic dwi.mif dwi_resized.mif'
754+ >>> image_resize.run() # doctest: +SKIP
755+
756+ Defining the new image's voxel size:
757+ >>> voxel_resize = mrt.MRResize()
758+ >>> voxel_resize.inputs.in_file = 'dwi.mif'
759+ >>> voxel_resize.inputs.voxel_size = (1, 1, 1)
760+ >>> voxel_resize.cmdline # doctest: +ELLIPSIS
761+ 'mrresize -interp cubic -voxel 1,1,1 dwi.mif dwi_resized.mif'
762+ >>> voxel_resize.run() # doctest: +SKIP
763+
764+ Defining the scale factor of each image dimension:
765+ >>> scale_resize = mrt.MRResize()
766+ >>> scale_resize.inputs.in_file = 'dwi.mif'
767+ >>> scale_resize.inputs.scale_factor = (0.5,0.5,0.5)
768+ >>> scale_resize.cmdline # doctest: +ELLIPSIS
769+ 'mrresize -interp cubic -scale 0.5,0.5,0.5 dwi.mif dwi_resized.mif'
770+ >>> scale_resize.run() # doctest: +SKIP
771+ """
772+
773+ _cmd = 'mrresize'
774+ input_spec = MRResizeInputSpec
775+ output_spec = MRResizeOutputSpec
0 commit comments