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);
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
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
def dataSize(filename, **args): """Read data size from nrrd image Arguments: filename (str): file name as regular expression x,y,z (tuple): data range specifications Returns: tuple: data size """ header = readHeader(filename); dims = header['sizes']; #dims[0:2] = [dims[1], dims[0]]; return io.dataSizeFromDataRange(dims, **args);
def dataSize(filename, **args): """Read data size from nrrd image Arguments: filename (str): file name as regular expression x,y,z (tuple): data range specifications Returns: tuple: data size """ header = readHeader(filename) dims = header['sizes'] #dims[0:2] = [dims[1], dims[0]]; return io.dataSizeFromDataRange(dims, **args)
def dataSize(filename, **args): """Returns size of data stored as a file list Arguments: filename (str): file name as regular expression x,y,z (tuple): data range specifications Returns: tuple: data size """ fp, fl = readFileList(filename) nz = len(fl) d2 = io.dataSize(os.path.join(fp, fl[0])) if not len(d2) == 2: raise RuntimeError("FileList: importing multiple files of dim %d not supported!" % len(d2)) dims = d2 + (nz,) return io.dataSizeFromDataRange(dims, **args)
def dataSize(filename, resolution = 0, channel = 0, timepoint = 0, **args): """Read data size of the imaris image data set Arguments: filename (str): imaris file name resolution (int): resolution level channel (int): color channel timepoint (int): time point Returns: tuple: image data size """ f = openFile(filename); ds = readDataSet(f, resolution = resolution, channel = channel, timepoint = timepoint); dims = list(ds.shape); dims = (dims[2], dims[1], dims[0]); return io.dataSizeFromDataRange(dims, **args);
def dataSize(filename, **args): """Read data size from raw/mhd image Arguments: filename (str): imaris file name x,y,z (tuple or all): range specifications Returns: int: raw image data size """ imr = vtk.vtkMetaImageReader() imr.SetFileName(filename); imr.Update() im = imr.GetOutput() dims = im.GetDimensions(); #dims = list(dims); #dims[0:2] = [dims[1], dims[0]]; #dims = tuple(dims); return io.dataSizeFromDataRange(dims, **args);
def dataSize(filename, **args): """Read data size from raw/mhd image Arguments: filename (str): imaris file name x,y,z (tuple or all): range specifications Returns: int: raw image data size """ imr = vtk.vtkMetaImageReader() imr.SetFileName(filename) imr.Update() im = imr.GetOutput() dims = im.GetDimensions() #dims = list(dims); #dims[0:2] = [dims[1], dims[0]]; #dims = tuple(dims); return io.dataSizeFromDataRange(dims, **args)
def dataSize(filename, **args): """Returns size of data stored as a file list Arguments: filename (str): file name as regular expression x,y,z (tuple): data range specifications Returns: tuple: data size """ fp, fl = readFileList(filename) nz = len(fl) d2 = io.dataSize(os.path.join(fp, fl[0])) if not len(d2) == 2: raise RuntimeError( "FileList: importing multiple files of dim %d not supported!" % len(d2)) dims = d2 + (nz, ) return io.dataSizeFromDataRange(dims, **args)