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


Python tifffile.TiffFile方法代码示例

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


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

示例1: dataSize

# 需要导入模块: import tifffile [as 别名]
# 或者: from tifffile import TiffFile [as 别名]
def dataSize(filename, **args):
    """Returns size of data in tif file
    
    Arguments:
        filename (str): file name as regular expression
        x,y,z (tuple): data range specifications
    
    Returns:
        tuple: data size
    """
    t = tiff.TiffFile(filename);
    d3 = len(t.pages);
    d2 = t.pages[0].shape;
    #d2 = (d2[0], d2[1]);
    if len(d2) == 3:
      d2 = (d2[2], d2[1], d2[0]);
    else:
      d2 = (d2[1], d2[0]);
    
    if d3 > 1:
        dims = d2 + (d3,);
    else:
        dims =  d2;
    
    return io.dataSizeFromDataRange(dims, **args); 
开发者ID:ChristophKirst,项目名称:ClearMap,代码行数:27,代码来源:TIF.py

示例2: dataZSize

# 需要导入模块: import tifffile [as 别名]
# 或者: from tifffile import TiffFile [as 别名]
def dataZSize(filename, z = all, **args):
    """Returns z size of data in tif file
    
    Arguments:
        filename (str): file name as regular expression
        z (tuple): z data range specification
    
    Returns:
        int: z data size
    """
    
    t = tiff.TiffFile(filename);
    
    d2 = t.pages[0].shape;
    if len(d2) == 3:
      return io.toDataSize(d2[0], r = z);
    
    d3 = len(t.pages);
    if d3 > 1:
        return io.toDataSize(d3, r = z);
    else:
        return None; 
开发者ID:ChristophKirst,项目名称:ClearMap,代码行数:24,代码来源:TIF.py

示例3: _read_immediate

# 需要导入模块: import tifffile [as 别名]
# 或者: from tifffile import TiffFile [as 别名]
def _read_immediate(self) -> np.ndarray:
        # Load Tiff
        with TiffFile(self._file) as tiff:
            # Check each scene has the same shape
            # If scene shape checking fails, use the specified scene and update
            # operating shape
            scenes = tiff.series
            if not self._scene_shape_is_consistent(tiff, S=self.specific_s_index):
                return scenes[self.specific_s_index].asarray()

            # Read each scene and stack if single scene
            if len(scenes) > 1:
                return np.stack([s.asarray() for s in scenes])

            # Else, return single scene
            return tiff.asarray() 
开发者ID:AllenCellModeling,项目名称:aicsimageio,代码行数:18,代码来源:tiff_reader.py

示例4: open_tiff

# 需要导入模块: import tifffile [as 别名]
# 或者: from tifffile import TiffFile [as 别名]
def open_tiff(file, sktiff):
    """ opens tiff with either ScanImageTiffReader or tifffile
    returns tiff and its length

    """
    if sktiff:
        tif = TiffFile(file)
        Ltif = len(tif.pages)
    else:
        tif = ScanImageTiffReader(file)
        tsize = tif.shape()
        if len(tsize) < 3:
            # single page tiffs
            Ltif = 1
        else:
            Ltif = tif.shape()[0]
    return tif, Ltif 
开发者ID:MouseLand,项目名称:suite2p,代码行数:19,代码来源:tiff.py

示例5: _lazy_init_metadata

# 需要导入模块: import tifffile [as 别名]
# 或者: from tifffile import TiffFile [as 别名]
def _lazy_init_metadata(self) -> omexml.OMEXML:
        with TiffFile(self._file) as tiff:
            if self._metadata is None and tiff.is_ome:
                description = tiff.pages[0].description.strip()
                if not (
                    description.startswith("<?xml version=")
                    and description.endswith("</OME>")
                ):
                    raise ValueError(
                        f"Description does not conform to OME specification: "
                        f"{description[:100]}"
                    )
                self._metadata = omexml.OMEXML(description)
        return self._metadata 
开发者ID:AllenCellModeling,项目名称:aicsimageio,代码行数:16,代码来源:ome_tiff_reader.py

示例6: _imread

# 需要导入模块: import tifffile [as 别名]
# 或者: from tifffile import TiffFile [as 别名]
def _imread(img: Path, scene: int, page: int) -> np.ndarray:
        # Load Tiff
        with TiffFile(img) as tiff:
            # Get proper scene
            scene = tiff.series[scene]

            # Get proper page
            page = scene.pages[page]

            # Return numpy
            return page.asarray() 
开发者ID:AllenCellModeling,项目名称:aicsimageio,代码行数:13,代码来源:tiff_reader.py

示例7: _scene_shape_is_consistent

# 需要导入模块: import tifffile [as 别名]
# 或者: from tifffile import TiffFile [as 别名]
def _scene_shape_is_consistent(tiff: TiffFile, S: int) -> bool:
        scenes = tiff.series
        operating_shape = scenes[0].shape
        for scene in scenes:
            if scene.shape != operating_shape:
                log.info(
                    f"File contains variable dimensions per scene, "
                    f"selected scene: {S} for data "
                    f"retrieval."
                )
                return False

        return True 
开发者ID:AllenCellModeling,项目名称:aicsimageio,代码行数:15,代码来源:tiff_reader.py

示例8: dtype

# 需要导入模块: import tifffile [as 别名]
# 或者: from tifffile import TiffFile [as 别名]
def dtype(self):
        if self._dtype is None:
            with TiffFile(self._file) as tiff:
                self._dtype = tiff.pages[0].dtype

        return self._dtype 
开发者ID:AllenCellModeling,项目名称:aicsimageio,代码行数:8,代码来源:tiff_reader.py

示例9: load_tif_lazy

# 需要导入模块: import tifffile [as 别名]
# 或者: from tifffile import TiffFile [as 别名]
def load_tif_lazy(fname):
    with TiffFile(fname) as tif:
        data = tif.asarray()

    f = int(data.shape[0])
    fmread = da.delayed(load_tif_perframe)
    flist = [fmread(fname, i) for i in range(f)]
    sample = flist[0].compute()
    arr = [da.array.from_delayed(
        fm, dtype=sample.dtype, shape=sample.shape) for fm in flist]
    return da.array.stack(arr, axis=0) 
开发者ID:DeniseCaiLab,项目名称:minian,代码行数:13,代码来源:utilities.py

示例10: readData

# 需要导入模块: import tifffile [as 别名]
# 或者: from tifffile import TiffFile [as 别名]
def readData(filename, x = all, y = all, z = all, **args):
    """Read data from a single tif image or stack
    
    Arguments:
        filename (str): file name as regular expression
        x,y,z (tuple): data range specifications
    
    Returns:
        array: image data
    """
    
    dsize = dataSize(filename);
    #print "dsize %s" % str(dsize);    
    
    if len(dsize) == 2:
        data = tiff.imread(filename, key = 0);
        #print "data.shape %s" % str(data.shape);        
        
        return io.dataToRange(data.transpose([1,0]), x = x, y = y);
        #return io.dataToRange(data, x = x, y = y);
        
    else:
        if z is all:
            data = tiff.imread(filename);
            if data.ndim == 2:
                # data = data
                data = data.transpose([1,0]);
            elif data.ndim == 3:
                #data = data.transpose([1,2,0]);
                data = data.transpose([2,1,0]);
            elif data.ndim == 4: # multi channel image
                #data = data.transpose([1,2,0,3]);
                data = data.transpose([2,1,0,3]);
            else:
                raise RuntimeError('readData: dimension %d not supproted!' % data.ndim)
            
            return io.dataToRange(data, x = x, y = y, z = all);
        
        else: #optimize for z ranges
            ds = io.dataSizeFromDataRange(dsize, x = x, y = y, z = z);
            t = tiff.TiffFile(filename);
            p = t.pages[0];
            data = numpy.zeros(ds, dtype = p.dtype);
            rz = io.toDataRange(dsize[2], r = z);
            
            #print "test"
            #print rz;
            #print dsize            
            
            for i in range(rz[0], rz[1]):
                xydata = t.pages[i].asarray();
                #data[:,:,i-rz[0]] = io.dataToRange(xydata, x = x, y = y);
                data[:,:,i-rz[0]] = io.dataToRange(xydata.transpose([1,0]), x = x, y = y);
            
            return data 
开发者ID:ChristophKirst,项目名称:ClearMap,代码行数:57,代码来源:TIF.py

示例11: _read_delayed

# 需要导入模块: import tifffile [as 别名]
# 或者: from tifffile import TiffFile [as 别名]
def _read_delayed(self) -> da.core.Array:
        # Load Tiff
        with TiffFile(self._file) as tiff:
            # Check each scene has the same shape
            # If scene shape checking fails, use the specified scene and update
            # operating shape
            scenes = tiff.series
            operating_shape = scenes[0].shape
            if not self._scene_shape_is_consistent(tiff, S=self.specific_s_index):
                operating_shape = scenes[self.specific_s_index].shape
                scenes = [scenes[self.specific_s_index]]

            # Get sample yx plane
            sample = scenes[0].pages[0].asarray()

            # Combine length of scenes and operating shape
            # Replace YX dims with empty dimensions
            operating_shape = (len(scenes), *operating_shape)
            operating_shape = operating_shape[:-2] + (1, 1)

            # Make ndarray for lazy arrays to fill
            lazy_arrays = np.ndarray(operating_shape, dtype=object)
            for all_page_index, (np_index, _) in enumerate(np.ndenumerate(lazy_arrays)):
                # Scene index is the first index in np_index
                scene_index = np_index[0]

                # This page index is current enumeration divided by scene index + 1
                # For example if the image has 10 Z slices and 5 scenes, there
                # would be 50 total pages
                this_page_index = all_page_index // (scene_index + 1)

                # Fill the numpy array with the delayed arrays
                lazy_arrays[np_index] = da.from_delayed(
                    delayed(TiffReader._imread)(
                        self._file, scene_index, this_page_index
                    ),
                    shape=sample.shape,
                    dtype=sample.dtype,
                )

            # Convert the numpy array of lazy readers into a dask array
            data = da.block(lazy_arrays.tolist())

            # Only return the scene dimension if multiple scenes are present
            if len(scenes) == 1:
                data = data[0, :]

            return data 
开发者ID:AllenCellModeling,项目名称:aicsimageio,代码行数:50,代码来源:tiff_reader.py

示例12: dims

# 需要导入模块: import tifffile [as 别名]
# 或者: from tifffile import TiffFile [as 别名]
def dims(self) -> str:
        if self._dims is None:
            # Get a single scenes dimensions in order
            with TiffFile(self._file) as tiff:
                single_scene_dims = tiff.series[0].pages.axes

                # We can sometimes trust the dimension info in the image
                if all([d in Dimensions.DefaultOrder for d in single_scene_dims]):
                    # Add scene dimension only if there are multiple scenes
                    if len(tiff.series) == 1:
                        self._dims = single_scene_dims
                    else:
                        self._dims = f"{Dimensions.Scene}{single_scene_dims}"
                # Sometimes the dimension info is wrong in certain dimensions, so guess
                # that dimension
                else:
                    guess = self.guess_dim_order(tiff.series[0].pages.shape)
                    best_guess = []
                    for dim_from_meta in single_scene_dims:
                        if dim_from_meta in Dimensions.DefaultOrder:
                            best_guess.append(dim_from_meta)
                        else:
                            appended_dim = False
                            for guessed_dim in guess:
                                if guessed_dim not in best_guess:
                                    best_guess.append(guessed_dim)
                                    appended_dim = True
                                    log.info(
                                        f"Unsure how to handle dimension: "
                                        f"{dim_from_meta}. "
                                        f"Replaced with guess: {guessed_dim}"
                                    )
                                    break

                            # All of our guess dims were already in the dim list,
                            # append the dim read from meta
                            if not appended_dim:
                                best_guess.append(dim_from_meta)

                    best_guess = "".join(best_guess)

                    # Add scene dimension only if there are multiple scenes
                    if len(tiff.series) == 1:
                        self._dims = best_guess
                    else:
                        self._dims = f"{Dimensions.Scene}{best_guess}"

        return self._dims 
开发者ID:AllenCellModeling,项目名称:aicsimageio,代码行数:50,代码来源:tiff_reader.py


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