3
d                 @   sl   d Z ddlmZmZmZmZmZ ddlmZ ddlm	Z	 G dd deZ
G dd	 d	eZG d
d deZdS )z
Nipype interface for seg_EM.

The em module provides higher-level interfaces to some of the operations
that can be performed with the seg_em command-line program.

Examples
--------
See the docstrings of the individual classes for examples.
   )TraitedSpecFiletraitsCommandLineInputSpecInputMultiPath   )NiftySegCommand)get_custom_pathc               @   sN  e Zd ZdZeddddddZedddd	Zejd
ddddgdZ	eddddddgdZ
edddddgdZejdddddZejdddddZejdddddZejdd d!Zd"Zejd#ddedZd$Zejd%ed!Zd&Zejej ej d'ed!Zd(Zejej ej d)ed!Zed*gd+d,d-d.Zed*gd/d0d1d.Zed*gd2d3d4d.Zd5S )6EMInputSpeczInput Spec for EM.z-in %sTzInput image to segment   )argstrexists	mandatorydescpositionz-mask %sz$Filename of the ROI for label fusion)r   r   r   z-nopriors %sz&Number of classes to use without priorprior_4Dpriors)r   r   r   xorz-prior4D %sz4D file containing the priorsno_prior)r   r   r   r   r   z%szList of priors filepaths.z-max_iter %sd   zMaximum number of iterations)r   default_valueZ
usedefaultr   z-min_iter %s    zMinimum number of iterationsz-bc_order %s   z#Polynomial order for the bias fieldz-mrf_beta %sz!Weight of the Markov Random Field)r   r   zeBias field correction will run only if the ratio of improvement is below bc_thresh. (default=0 [OFF])z-bc_thresh %szMAmount of regularization over the diagonal of the covariance matrix [above 1]z-reg %szOutlier detection as in (Van Leemput TMI 2003). <fl1> is the Mahalanobis threshold [recommended between 3 and 7] <fl2> is a convergence ratio below which the outlier detection is going to be done [recommended 0.01]z-outlier %s %szwRelax Priors [relaxation factor: 0<rf<1 (recommended=0.5), gaussian regularization: gstd>0 (recommended=2.0)] /only 3D/z	-rf %s %sin_filez%s_em.nii.gzz-out %szOutput segmentation)Zname_sourceZname_templater   r   z%s_bc_em.nii.gzz
-bc_out %szOutput bias corrected imagez%s_outlier_em.nii.gzz-out_outlier %szOutput outlierness imageN)__name__
__module____qualname____doc__r   r   Z	mask_filer   ZIntr   r   r   r   Zmax_iterZmin_iterZbc_order_valZFloatZmrf_beta_valr   Zbc_thresh_valZreg_valTupleZoutlier_valZrelax_priorsout_fileout_bc_fileout_outlier_file r"   r"   ?/tmp/pip-build-7vycvbft/nipype/nipype/interfaces/niftyseg/em.pyr
      s   
r
   c               @   s.   e Zd ZdZeddZeddZeddZdS )EMOutputSpeczOutput Spec for EM.zOutput segmentation)r   zOutput bias corrected imagezOutput outlierness imageN)r   r   r   r   r   r   r    r!   r"   r"   r"   r#   r$      s   

r$   c                   s8   e Zd ZdZedddZdZeZe	Z
 fddZ  ZS )EMa  Interface for executable seg_EM from NiftySeg platform.

    seg_EM is a general purpose intensity based image segmentation tool. In
    it's simplest form, it takes in one 2D or 3D image and segments it in n
    classes.

    `Source code <http://cmictig.cs.ucl.ac.uk/wiki/index.php/NiftySeg>`_ |
    `Documentation <http://cmictig.cs.ucl.ac.uk/wiki/index.php/NiftySeg_documentation>`_

    Examples
    --------
    >>> from nipype.interfaces import niftyseg
    >>> node = niftyseg.EM()
    >>> node.inputs.in_file = 'im1.nii'
    >>> node.inputs.no_prior = 4
    >>> node.cmdline
    'seg_EM -in im1.nii -bc_order 3 -bc_thresh 0 -max_iter 100 -min_iter 0 -nopriors 4 -bc_out im1_bc_em.nii.gz -out im1_em.nii.gz -out_outlier im1_outlier_em.nii.gz'

    Zseg_EMZNIFTYSEGDIR)Zenv_dirZ_emc                sB   |dkr*t | jj}d|dj| jjf S tt| j|||S dS )z/Convert input to appropriate format for seg_EM.r   z-priors %d %s N)leninputsr   joinsuperr%   _format_arg)selfoptspecvalZ
_nb_priors)	__class__r"   r#   r+      s    zEM._format_arg)r   r   r   r   r	   Z_cmd_suffixr
   Z
input_specr$   Zoutput_specr+   __classcell__r"   r"   )r0   r#   r%      s   r%   N)r   baser   r   r   r   r   r   Zniftyreg.baser	   r
   r$   r%   r"   r"   r"   r#   <module>   s   q