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


Python IO.readData方法代码示例

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


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

示例1: readDataFiles

# 需要导入模块: from ClearMap import IO [as 别名]
# 或者: from ClearMap.IO import readData [as 别名]
def readDataFiles(filename, x=all, y=all, z=all, **args):
    """Read data from individual images assuming they are the z slices

    Arguments:
        filename (str): file name as regular expression
        x,y,z (tuple): data range specifications
    
    Returns:
        array: image data
    """

    fpath, fl = readFileList(filename)
    nz = len(fl)

    # read first image to get data size and type
    rz = io.toDataRange(nz, r=z)
    sz = io.toDataSize(nz, r=z)
    fn = os.path.join(fpath, fl[rz[0]])
    img = io.readData(fn, x=x, y=y)
    nxy = img.shape
    data = numpy.zeros(nxy + (sz,), dtype=img.dtype)
    data[:, :, 0] = img

    for i in range(rz[0] + 1, rz[1]):
        fn = os.path.join(fpath, fl[i])
        data[:, :, i - rz[0]] = io.readData(fn, x=x, y=y)

    return data
开发者ID:ChristophKirst,项目名称:ClearMapUnstable,代码行数:30,代码来源:FileList.py

示例2: overlayLabel

# 需要导入模块: from ClearMap import IO [as 别名]
# 或者: from ClearMap.IO import readData [as 别名]
def overlayLabel(dataSource, labelSource, sink = None,  alpha = False, labelColorMap = 'jet', x = all, y = all, z = all):
    """Overlay a gray scale image with colored labeled image
    
    Arguments:
        dataSouce (str or array): volumetric image data
        labelSource (str or array): labeled image to be overlayed on the image data
        sink (str or None): destination for the overlayed image
        alpha (float or False): transparency
        labelColorMap (str or object): color map for the labels
        x, y, z (all or tuple): sub-range specification
    
    Returns:
        (array or str): figure handle
        
    See Also:
        :func:`overlayPoints`
    """ 
    
    label = io.readData(labelSource, x= x, y = y, z = z);
    image = io.readData(dataSource, x= x, y = y, z = z);
    
    lmax = label.max();
    
    if lmax <= 1:
        carray = numpy.array([[1,0,0,1]]);
    else:
        cm = mpl.cm.get_cmap(labelColorMap);
        cNorm  = mpl.colors.Normalize(vmin=1, vmax = int(lmax));
        carray = mpl.cm.ScalarMappable(norm=cNorm, cmap=cm);
        carray = carray.to_rgba(numpy.arange(1, int(lmax + 1)));

    if alpha == False:
        carray = numpy.concatenate(([[0,0,0,1]], carray), axis = 0);
    else:
        carray = numpy.concatenate(([[1,1,1,1]], carray), axis = 0);
        
    cm = mpl.colors.ListedColormap(carray);
    carray = cm(label);
    carray = carray.take([0,1,2], axis = -1);

    if alpha == False:
        cimage = (label == 0) * image;
        cimage = numpy.repeat(cimage, 3);
        cimage = cimage.reshape(image.shape + (3,)); 
        cimage = cimage.astype(carray.dtype);
        cimage += carray;
    else:
        cimage = numpy.repeat(image, 3);
        cimage = cimage.reshape(image.shape + (3,));
        cimage = cimage.astype(carray.dtype);
        cimage *= carray;

    return io.writeData(sink, cimage);
开发者ID:ChristophKirst,项目名称:ClearMap,代码行数:55,代码来源:Plot.py

示例3: makeColorAnnotations

# 需要导入模块: from ClearMap import IO [as 别名]
# 或者: from ClearMap.IO import readData [as 别名]
def makeColorAnnotations(filename, labeledImage=None):
    if labeledImage is None:
        labeledImage = DefaultLabeledImageFile

    li = io.readData(labeledImage)
    dsize = li.shape

    lr = numpy.zeros(dsize, dtype=numpy.uint8)
    lg = lr.copy()
    lb = lr.copy()

    global Label
    maxlabel = max(Label.ids)
    colarray = numpy.zeros((maxlabel, 3))
    for i in Label.ids:
        colarray[i - 1, :] = Label.color(i)

    for i in Label.ids:
        ll = li == i
        lr[ll] = colarray[i - 1, 0]
        lg[ll] = colarray[i - 1, 1]
        lb[ll] = colarray[i - 1, 2]

    io.writeData(filename + "_r.tif", lr)
    io.writeData(filename + "_g.tif", lg)
    io.writeData(filename + "_b.tif", lb)

    return (lr, lg, lb)
开发者ID:ChristophKirst,项目名称:ClearMapUnstable,代码行数:30,代码来源:Label.py

示例4: labelPoints

# 需要导入模块: from ClearMap import IO [as 别名]
# 或者: from ClearMap.IO import readData [as 别名]
def labelPoints(points, labeledImage=DefaultLabeledImageFile, level=None, collapse=None):

    # points are (y,x,z) -> which is also the way the labeled image is read in
    # x = points[:,1];
    # y = points[:,0];
    # z = points[:,2];

    x = points[:, 0]
    y = points[:, 1]
    z = points[:, 2]

    nPoint = x.size

    pointLabels = numpy.zeros(nPoint, "int32")

    labelImage = io.readData(labeledImage)
    dsize = labelImage.shape

    for i in range(nPoint):
        # if y[i] >= 0 and y[i] < dsize[0] and x[i] >= 0 and x[i] < dsize[1] and z[i] >= 0 and z[i] < dsize[2]:
        #     pointLabels[i] = labelImage[y[i], x[i], z[i]];
        if x[i] >= 0 and x[i] < dsize[0] and y[i] >= 0 and y[i] < dsize[1] and z[i] >= 0 and z[i] < dsize[2]:
            pointLabels[i] = labelImage[int(x[i]), int(y[i]), int(z[i])]

    if collapse is None:
        pointLabels = labelAtLevel(pointLabels, level)
    else:
        pointLabels = labelAtCollapse(pointLabels)

    return pointLabels
开发者ID:ChristophKirst,项目名称:ClearMapUnstable,代码行数:32,代码来源:Label.py

示例5: _processSubStack

# 需要导入模块: from ClearMap import IO [as 别名]
# 或者: from ClearMap.IO import readData [as 别名]
def _processSubStack(dsr):
    """Helper to process stack in parallel"""

    sf  = dsr[0];
    pp  = dsr[1];
    sub = dsr[2];
    verbose = dsr[3];

    timer = Timer();
    pw = ProcessWriter(sub["stackId"]);
    
    if verbose:
        pw.write("processing substack " + str(sub["stackId"]) + "/" + str(sub["nStacks"]));
        pw.write("file          = " + sub["source"]);
        pw.write("segmentation  = " + str(sf));
        pw.write("ranges: x,y,z = " + str(sub["x"]) +  "," + str(sub["y"]) + "," + str(sub["z"])); 
    
    img = io.readData(sub["source"], x = sub["x"], y = sub["y"], z = sub["z"]);
    
    if verbose:
        pw.write(timer.elapsedTime(head = 'Reading data of size ' + str(img.shape)));
    
    timer.reset();
    seg = sf(img, subStack = sub, out = pw, **pp);    

    if verbose:    
        pw.write(timer.elapsedTime(head = 'Processing substack of size ' + str(img.shape)));
    
    return seg;
开发者ID:ChristophKirst,项目名称:ClearMap,代码行数:31,代码来源:StackProcessing.py

示例6: removeBackground

# 需要导入模块: from ClearMap import IO [as 别名]
# 或者: from ClearMap.IO import readData [as 别名]
def removeBackground(img, removeBackgroundParameter = None, size = None, save = None, verbose = False,
                     subStack = None, out = sys.stdout, **parameter):
    """Remove background via subtracting a morphological opening from the original image 
    
    Background removal is done z-slice by z-slice.
    
    Arguments:
        img (array): image data
        removeBackGroundParameter (dict):
            ========= ==================== ===========================================================
            Name      Type                 Descritption
            ========= ==================== ===========================================================
            *size*    (tuple or None)      size for the structure element of the morphological opening
                                           if None, do not correct for any background
            *save*    (str or None)        file name to save result of this operation
                                           if None dont save to file
            *verbose* (bool or int)        print / plot information about this step                                 
            ========= ==================== ===========================================================
        subStack (dict or None): sub-stack information 
        verbose (bool): print progress info 
        out (object): object to write progress info to
        
    Returns:
        array: background corrected image
    """
    
    size = getParameter(removeBackgroundParameter, "size", size);
    save = getParameter(removeBackgroundParameter, "save", save);    
    verbose = getParameter(removeBackgroundParameter, "verbose", verbose);   
    
    if verbose:
        writeParameter(out = out, head = 'Background Removal:', size = size, save = save);    
    
    if size is None:    
        return img;
        
    img = io.readData(img);
    
    timer = Timer();
    # background subtraction in each slice
    se = structureElement('Disk', size).astype('uint8');
    for z in range(img.shape[2]):
         #img[:,:,z] = img[:,:,z] - grey_opening(img[:,:,z], structure = structureElement('Disk', (30,30)));
         #img[:,:,z] = img[:,:,z] - morph.grey_opening(img[:,:,z], structure = self.structureELement('Disk', (150,150)));
         img[:,:,z] = img[:,:,z] - cv2.morphologyEx(img[:,:,z], cv2.MORPH_OPEN, se)
    
    if not save is None:
        writeSubStack(save, img, subStack = subStack)

    if verbose > 1:
        plotTiling(10*img);

    if verbose:
        out.write(timer.elapsedTime(head = 'Background') + '\n');
    
    return img
开发者ID:ChristophKirst,项目名称:ClearMapUnstable,代码行数:58,代码来源:BackgroundRemoval.py

示例7: readData

# 需要导入模块: from ClearMap import IO [as 别名]
# 或者: from ClearMap.IO import readData [as 别名]
def readData(filename, **args):
    """Read image stack from single or multiple images
    
    Arguments:
        filename (str): file name as regular expression
        x,y,z (tuple): data range specifications
    
    Returns:
        array: image data
    """

    if os.path.exists(filename):
        return io.readData(filename, **args)
    else:
        return readDataFiles(filename, **args)
开发者ID:ChristophKirst,项目名称:ClearMapUnstable,代码行数:17,代码来源:FileList.py

示例8: readImportPreview

# 需要导入模块: from ClearMap import IO [as 别名]
# 或者: from ClearMap.IO import readData [as 别名]
def readImportPreview(importResult):
    """Returns the prestiched preview file to check orientations and coarse alignment
  
  Arguments:
    importResult (str): the base directory of the image data or the import xml file
  
  Returns:
    array: preview image
  """

    baseDirectory = baseDirectoryFromXMLImport(importResult)
    if baseDirectory is None:
        baseDirectory = importResult

    fn = os.path.join(baseDirectory, "test_middle_slice.tif")
    return io.readData(fn)
开发者ID:ChristophKirst,项目名称:ClearMapUnstable,代码行数:18,代码来源:Stitching.py

示例9: _cropParallel

# 需要导入模块: from ClearMap import IO [as 别名]
# 或者: from ClearMap.IO import readData [as 别名]
def _cropParallel(arg):
    """Cropping helper function to use for parallel cropping of image slices"""

    fileSource = arg[0]
    fileSink = arg[1]
    x = arg[2]
    y = arg[3]
    ii = arg[4]
    nn = arg[5]

    if ii is not None:
        pw = ProcessWriter(ii)
        pw.write("cropData: corpping image %d / %d" % (ii, nn))
        # pw.write('%s -> %s' % (fileSource, fileSink));

    data = io.readData(fileSource, x=x, y=y)
    io.writeData(fileSink, data)
开发者ID:ChristophKirst,项目名称:ClearMapUnstable,代码行数:19,代码来源:FileList.py

示例10: test

# 需要导入模块: from ClearMap import IO [as 别名]
# 或者: from ClearMap.IO import readData [as 别名]
def test():
    """Test Elastix module"""
    import ClearMap.Alignment.Elastix as self
    reload(self)
    
    from ClearMap.Settings import ClearMapPath;
    import os, numpy
    
    p = ClearMapPath;
    
    resultdir = os.path.join(p, 'Test/Elastix/Output');
    
    print 'Searching for transformation parameter file in ' + resultdir;
    pf = self.getTransformParameterFile(resultdir)
      
    print 'Found: ' + pf;
    
    
    #replace path in trasform parameter files:
    self.setPathTransformParameterFiles(resultdir)
    
    #initialize
    self.initializeElastix('/home/ckirst/programs/elastix')
    self.printSettings()

    #transform points
    pts = numpy.random.rand(5,3);    
     
    print 'Transforming points: '
    tpts = self.transformPoints(pts, transformParameterFile = pf, indices = False);
    print pts
    print 'Transformed points: '
    print tpts
    
    
    #deformation and distance fields     
    df = self.deformationField(transformParameterFile = pf, resultDirectory = None);
    #df = '/tmp/elastix_output/deformationField.mhd';

    import ClearMap.IO as io
    data = io.readData('/tmp/elastix_output/deformationField.mhd');
    
    ds = self.deformationDistance(data);
    
    io.writeData(os.path.join(p, 'Test/Elastix/Output/distances.raw'), ds);
开发者ID:audrocks17,项目名称:ClearMap,代码行数:47,代码来源:Elastix.py

示例11: readDataGroup

# 需要导入模块: from ClearMap import IO [as 别名]
# 或者: from ClearMap.IO import readData [as 别名]
def readDataGroup(filenames, combine = True, **args):
    """Turn a list of filenames for data into a numpy stack"""
    
    #check if stack already:
    if isinstance(filenames, numpy.ndarray):
        return filenames;
    
    #read the individual files
    group = [];
    for f in filenames:
        data = io.readData(f, **args);
        data = numpy.reshape(data, (1,) + data.shape);
        group.append(data);
    
    if combine:
        return numpy.vstack(group);
    else:
        return group;
开发者ID:ChristophKirst,项目名称:ClearMap,代码行数:20,代码来源:Statistics.py

示例12: overlayPoints

# 需要导入模块: from ClearMap import IO [as 别名]
# 或者: from ClearMap.IO import readData [as 别名]
def overlayPoints(dataSource, pointSource, sink = None, pointColor = [1,0,0], x = all, y = all, z = all):
    """Overlay points on 3D data and return as color image
    
    Arguments:
        dataSouce (str or array): volumetric image data
        pointSource (str or array): point data to be overlayed on the image data
        pointColor (array): RGB color for the overlayed points
        x, y, z (all or tuple): sub-range specification
    
    Returns:
        (str or array): image overlayed with points
        
    See Also:
        :func:`overlayLabel`
    """
    data = io.readData(dataSource, x = x, y = y, z = z);
    points = io.readPoints(pointSource, x = x, y = y, z = z, shift = True);
    #print data.shape
    
    if not pointColor is None:
        dmax = data.max(); dmin = data.min();
        if dmin == dmax:
            dmax = dmin + 1;
        cimage = numpy.repeat( (data - dmin) / (dmax - dmin), 3);
        cimage = cimage.reshape(data.shape + (3,));    
    
        if data.ndim == 2:
            for p in points: # faster version using voxelize ?
                cimage[p[0], p[1], :] = pointColor;
        elif data.ndim == 3:
            for p in points: # faster version using voxelize ?
                cimage[p[0], p[1], p[2], :] = pointColor;
        else:
            raise RuntimeError('overlayPoints: data dimension %d not suported' % data.ndim);
    
    else:
        cimage = vox.voxelize(points, data.shape, method = 'Pixel');
        cimage = cimage.astype(data.dtype) * data.max();
        data.shape = data.shape + (1,);
        cimage.shape =  cimage.shape + (1,);
        cimage = numpy.concatenate((data, cimage), axis  = 3);
    
    #print cimage.shape    
    return io.writeData(sink, cimage);   
开发者ID:ChristophKirst,项目名称:ClearMap,代码行数:46,代码来源:Plot.py

示例13: readData

# 需要导入模块: from ClearMap import IO [as 别名]
# 或者: from ClearMap.IO import readData [as 别名]
def readData(filename, **args):
    """Read nrrd file image data
    
    Arguments:
        filename (str): file name as regular expression
        x,y,z (tuple): data range specifications
    
    Returns:
        array: image data
    """

    with open(filename,'rb') as filehandle:
        header = readHeader(filehandle)
        #print header
        data = _read_data(header, filehandle, filename)
        #return (data, header)
        #return data.transpose([1,0,2]);
        data = io.readData(data, **args);
        return data;
开发者ID:ChristophKirst,项目名称:ClearMap,代码行数:21,代码来源:NRRD.py

示例14: deformationDistance

# 需要导入模块: from ClearMap import IO [as 别名]
# 或者: from ClearMap.IO import readData [as 别名]
def deformationDistance(deformationField, sink = None, scale = None):
    """Compute the distance field from a deformation vector field
    
    Arguments:
        deformationField (str or array): source of the deformation field determined by :func:`deformationField`
        sink (str or None): image sink to save the deformation field to
        scale (tuple or None): scale factor for each dimension, if None = (1,1,1)
        
    Returns:
        array or str: array or file name of the transformed data
    """
    
    deformationField = io.readData(deformationField);
    
    df = numpy.square(deformationField);
    if not scale is None:
        for i in range(3):
            df[:,:,:,i] = df[:,:,:,i] * (scale[i] * scale[i]);
            
    return io.writeData(sink, numpy.sqrt(numpy.sum(df, axis = 3)));
开发者ID:audrocks17,项目名称:ClearMap,代码行数:22,代码来源:Elastix.py

示例15: test

# 需要导入模块: from ClearMap import IO [as 别名]
# 或者: from ClearMap.IO import readData [as 别名]
def test():
    """Test Spot Detection Module"""
    import os
    import ClearMap.ImageProcessing.SpotDetection as self
    reload(self)
    import ClearMap.IO as io  
    import ClearMap.Settings as settings
    
    basedir = settings.ClearMapPath;
    #fn = '/home/ckirst/Science/Projects/BrainActivityMap/Data/iDISCO_2015_06/Adult cfos C row 20HF 150524.ims';
    fn = os.path.join(basedir, 'Test/Data/Synthetic/label_iDISCO_\d{3}.tif');
    fn = os.path.join(basedir, 'Test/Data/OME/16-17-27_0_8X-s3-20HF_UltraII_C00_xyz-Table Z\d{4}.ome.tif');
    #fn = '/run/media/ckirst/ChristophsBackuk4TB/iDISCO_2015_06/Adult cfos C row 20HF 150524.ims';
    #fn = '/home/nicolas/Windows/Nico/cfosRegistrations/Adult cfos C row 20HF 150524 - Copy.ims';
    #fn = '/home/ckirst/Science/Projects/BrainActivityMap/iDISCO_2015_04/test for spots added spot.ims'

    img = io.readData(fn);
    #img = dataset[0:500,0:500,1000:1008];
    #img = dataset[600:1000,1600:1800,800:830];
    #img = dataset[500:1500,500:1500,800:809]; 
    img = img.astype('int16');
    
    #m = sys.modules['iDISCO.ImageProcessing.SpotDetection']
    #c = self.detectCells(img);
    
    c = self.detectCells(img, dogSize = None, cellShapeThreshold = 1, cellShapeFile = '/home/ckirst/Science/Projects/BrainActivityMap/Analysis/iDISCO/Test/Data/CellShape/cellshape_\d{3}.tif');
    
    print 'done, found %d cells !' % c[0].shape[0]


    #test intensities:
    import numpy;
    x = numpy.random.rand(30,30,10);
    centers = numpy.array([[0,0,0], [29,29,9]]);
    i = self.findIntensity(x, centers, boxSize = (1,1,1));
    print i
开发者ID:ChristophKirst,项目名称:ClearMap,代码行数:38,代码来源:SpotDetection.py


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