当前位置: 首页>>代码示例>>Python>>正文


Python IO.convertData方法代码示例

本文整理汇总了Python中ClearMap.IO.convertData方法的典型用法代码示例。如果您正苦于以下问题:Python IO.convertData方法的具体用法?Python IO.convertData怎么用?Python IO.convertData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ClearMap.IO的用法示例。


在下文中一共展示了IO.convertData方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: deformationField

# 需要导入模块: from ClearMap import IO [as 别名]
# 或者: from ClearMap.IO import convertData [as 别名]
def deformationField(sink = [], transformParameterFile = None, transformDirectory = None, resultDirectory = None):
    """Create the deformation field T(x) - x
    
    The map determined by elastix is 
    :math:`T \\mathrm{fixed} \\rightarrow \\mathrm{moving}`
        
    Arguments:
        sink (str, [] or None): image sink to save the transformation field; if [] return the default name of the data file generated by transformix.
        transformParameterFile (str or None): parameter file for the primary transformation, if None, the file is determined from the transformDirectory.
        transformDirectory (str or None): result directory of elastix alignment, if None the transformParameterFile has to be given.
        resultDirectory (str or None): the directorty for the transformix results
        
    Returns:
        array or str: array or file name of the transformed data
    """
    
    global TransformixBinary;    
    
    if resultDirectory == None:
        resultdirname = os.path.join(tempfile.tempdir, 'elastix_output');
    else:
        resultdirname = resultDirectory;
        
    if not os.path.exists(resultdirname):
        os.makedirs(resultdirname);
        
    if transformParameterFile == None:
        if transformDirectory == None:
            raise RuntimeError('neither alignment directory and transformation parameter file specified!'); 
        transformparameterdir = transformDirectory
        transformParameterFile = getTransformParameterFile(transformparameterdir);
    else:
        transformparameterdir = os.path.split(transformParameterFile);
        transformparameterdir = transformparameterdir[0];
    
    #transform
    #make path in parameterfiles absolute
    setPathTransformParameterFiles(transformparameterdir);
   
    #transformix -in inputImage.ext -out outputDirectory -tp TransformParameters.txt
    cmd = TransformixBinary + ' -def all -out ' + resultdirname + ' -tp ' + transformParameterFile;
    
    res = os.system(cmd);
    
    if res != 0:
        raise RuntimeError('deformationField: failed executing: ' + cmd);
    
    
    if sink == []:
        return getResultDataFile(resultdirname);
    elif sink is None:
        resultfile = getResultDataFile(resultdirname);
        data = io.readData(resultfile);
        if resultDirectory is None:
            shutil.rmtree(resultdirname);
        return data;
    elif isinstance(sink, basestring):
        resultfile = getResultDataFile(resultdirname);
        data = io.convertData(resultfile, sink);
        if resultDirectory is None:
            shutil.rmtree(resultdirname);
        return data;
    else:
        raise RuntimeError('deformationField: sink not valid!');
开发者ID:audrocks17,项目名称:ClearMap,代码行数:66,代码来源:Elastix.py

示例2: transformData

# 需要导入模块: from ClearMap import IO [as 别名]
# 或者: from ClearMap.IO import convertData [as 别名]
def transformData(source, sink = [], transformParameterFile = None, transformDirectory = None, resultDirectory = None):
    """Transform a raw data set to reference using the elastix alignment results
    
    If the map determined by elastix is 
    :math:`T \\mathrm{fixed} \\rightarrow \\mathrm{moving}`, 
    transformix on data works as :math:`T^{-1}(\\mathrm{data})`.
        
    Arguments:
        source (str or array): image source to be transformed
        sink (str, [] or None): image sink to save transformed image to. if [] return the default name of the data file generated by transformix.
        transformParameterFile (str or None): parameter file for the primary transformation, if None, the file is determined from the transformDirectory.
        transformDirectory (str or None): result directory of elastix alignment, if None the transformParameterFile has to be given.
        resultDirectory (str or None): the directorty for the transformix results
        
    Returns:
        array or str: array or file name of the transformed data
    """
    
    global TransformixBinary;    
    
    if isinstance(source, numpy.ndarray):
        imgname = os.path.join(tempfile.gettempdir(), 'elastix_input.tif');
        io.writeData(source, imgname);
    elif isinstance(source, basestring):
        if io.dataFileNameToType(source) == "TIF":
            imgname = source;
        else:
            imgname = os.path.join(tempfile.gettempdir(), 'elastix_input.tif');
            io.transformData(source, imgname);
    else:
        raise RuntimeError('transformData: source not a string or array');

    if resultDirectory == None:
        resultdirname = os.path.join(tempfile.tempdir, 'elastix_output');
    else:
        resultdirname = resultDirectory;
        
    if not os.path.exists(resultdirname):
        os.makedirs(resultdirname);
        
    
    if transformParameterFile == None:
        if transformDirectory == None:
            raise RuntimeError('neither alignment directory and transformation parameter file specified!'); 
        transformparameterdir = transformDirectory
        transformParameterFile = getTransformParameterFile(transformparameterdir);
    else:
        transformparameterdir = os.path.split(transformParameterFile);
        transformparameterdir = transformparameterdir[0];
    
    #transform
    #make path in parameterfiles absolute
    setPathTransformParameterFiles(transformparameterdir);
   
    #transformix -in inputImage.ext -out outputDirectory -tp TransformParameters.txt
    cmd = TransformixBinary + ' -in ' + imgname + ' -out ' + resultdirname + ' -tp ' + transformParameterFile;
    
    res = os.system(cmd);
    
    if res != 0:
        raise RuntimeError('transformData: failed executing: ' + cmd);
    
    
    if not isinstance(source, basestring):
        os.remove(imgname);

    if sink == []:
        return getResultDataFile(resultdirname);
    elif sink is None:
        resultfile = getResultDataFile(resultdirname);
        return io.readData(resultfile);
    elif isinstance(sink, basestring):
        resultfile = getResultDataFile(resultdirname);
        return io.convertData(resultfile, sink);
    else:
        raise RuntimeError('transformData: sink not valid!');
开发者ID:audrocks17,项目名称:ClearMap,代码行数:78,代码来源:Elastix.py


注:本文中的ClearMap.IO.convertData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。