本文整理汇总了Python中cube.Cube.getCube方法的典型用法代码示例。如果您正苦于以下问题:Python Cube.getCube方法的具体用法?Python Cube.getCube怎么用?Python Cube.getCube使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cube.Cube
的用法示例。
在下文中一共展示了Cube.getCube方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ingest
# 需要导入模块: from cube import Cube [as 别名]
# 或者: from cube.Cube import getCube [as 别名]
def ingest ( self ):
"""Read the stack and ingest"""
with closing (ocpcaproj.OCPCAProjectsDB()) as projdb:
proj = projdb.loadToken(self.token)
with closing (ocpcadb.OCPCADB(proj)) as db:
ch = proj.getChannelObj(self.channel)
# get the dataset configuration
[[ximagesz, yimagesz, zimagesz],(starttime,endtime)] = proj.datasetcfg.imageSize(self.resolution)
[xcubedim, ycubedim, zcubedim] = cubedim = proj.datasetcfg.getCubeDims()[self.resolution]
[xoffset, yoffset, zoffset] = proj.datasetcfg.getOffset()[self.resolution]
# for all specified resolutions
for resolution in range(0,1,1):
# extract parameters for iteration
numxtiles = ximagesz/self.tilesz[0]
numytiles = yimagesz/self.tilesz[1]
# Ingest in database aligned slabs in the z dimension
for slice_number in range(0, zimagesz, zcubedim):
slab = np.zeros ( [zcubedim,yimagesz,ximagesz], dtype=np.uint32 )
# over all tiles in that slice
for b in range(zcubedim):
for ytile in range(numytiles):
for xtile in range(numxtiles):
# if we are at the end of the space, quit
if slice_number+b <= zimagesz:
try:
filename = '{}{}/{}/{}/{}.png'.format(self.tilepath, resolution, slice_number+b+zoffset, ytile+17, xtile+16)
print "Opening filename {}".format(filename)
# add tile to stack
imgdata = np.asarray ( Image.open(filename, 'r').convert('RGBA') )
imgdata = np.left_shift(imgdata[:,:,3], 24, dtype=np.uint32) | np.left_shift(imgdata[:,:,2], 16, dtype=np.uint32) | np.left_shift(imgdata[:,:,1], 8, dtype=np.uint32) | np.uint32(imgdata[:,:,0])
slab [b,ytile*self.tilesz[1]:(ytile+1)*self.tilesz[1],xtile*self.tilesz[0]:(xtile+1)*self.tilesz[0]] = imgdata
except IOError, e:
print "Failed to open file {}".format(filename)
slab [b,ytile*self.tilesz[1]:(ytile+1)*self.tilesz[1],xtile*self.tilesz[0]:(xtile+1)*self.tilesz[0]] = np.zeros([self.tilesz[1], self.tilesz[0]], dtype=np.uint32)
for y in range (0, yimagesz+1, ycubedim):
for x in range (0, ximagesz+1, xcubedim):
# getting the cube id and ingesting the data one cube at a time
zidx = ocplib.XYZMorton ([x/xcubedim, y/ycubedim, (slice_number)/zcubedim])
cube = Cube.getCube(cubedim, ch.getChannelType(), ch.getDataType())
cube.zeros()
xmin, ymin = x, y
xmax = min (ximagesz, x+xcubedim)
ymax = min (yimagesz, y+ycubedim)
zmin = 0
zmax = min(slice_number+zcubedim, zimagesz+1)
cube.data[0:zmax-zmin,0:ymax-ymin,0:xmax-xmin] = slab[zmin:zmax, ymin:ymax, xmin:xmax]
if cube.isNotZeros():
db.putCube(ch, zidx, self.resolution, cube, update=True)
示例2: main
# 需要导入模块: from cube import Cube [as 别名]
# 或者: from cube.Cube import getCube [as 别名]
def main():
parser = argparse.ArgumentParser(description='Ingest the TIFF data')
parser.add_argument('token', action="store", type=str, help='Token for the project')
parser.add_argument('channel', action="store", type=str, help='Channel for the project')
parser.add_argument('path', action="store", type=str, help='Directory with the image files')
parser.add_argument('resolution', action="store", type=int, help='Resolution of data')
parser.add_argument('--offset', action="store", type=int, default=0, help='Offset on disk')
result = parser.parse_args()
# Load a database
with closing (ocpcaproj.OCPCAProjectsDB()) as projdb:
proj = projdb.loadToken(result.token)
with closing (ocpcadb.OCPCADB(proj)) as db:
ch = proj.getChannelObj(result.channel)
# get the dataset configuration
[[ximagesz, yimagesz, zimagesz],(starttime,endtime)] = proj.datasetcfg.imageSize(result.resolution)
[xcubedim,ycubedim,zcubedim] = cubedim = proj.datasetcfg.getCubeDims()[result.resolution]
[xoffset, yoffset, zoffset] = proj.datasetcfg.getOffset()[result.resolution]
# Get a list of the files in the directories
for slice_number in range (zoffset, zimagesz+1, zcubedim):
slab = np.zeros([zcubedim, yimagesz, ximagesz ], dtype=np.uint8)
for b in range(zcubedim):
if (slice_number + b <= zimagesz):
try:
# reading the raw data
file_name = "{}{:0>5}.tif".format(result.path, (slice_number + b))
# silvestri15
#file_name = "{}full_{:0>6}.tif".format(result.path, slice_number + b + result.offset)
print "Open filename {}".format(file_name)
slab[b,:,:] = np.asarray(Image.open(file_name, 'r'))
except IOError, e:
print e
slab[b,:,:] = np.zeros((yimagesz, ximagesz), dtype=np.uint8)
for y in range ( 0, yimagesz+1, ycubedim ):
for x in range ( 0, ximagesz+1, xcubedim ):
# Getting a Cube id and ingesting the data one cube at a time
zidx = ocplib.XYZMorton ( [x/xcubedim, y/ycubedim, (slice_number-zoffset)/zcubedim] )
cube = Cube.getCube(cubedim, ch.getChannelType(), ch.getDataType())
cube.zeros()
xmin,ymin = x,y
xmax = min ( ximagesz, x+xcubedim )
ymax = min ( yimagesz, y+ycubedim )
zmin = 0
zmax = min(slice_number+zcubedim, zimagesz+1)
cube.data[0:zmax-zmin,0:ymax-ymin,0:xmax-xmin] = slab[zmin:zmax, ymin:ymax, xmin:xmax]
if cube.isNotZeros():
db.putCube(ch, zidx, result.resolution, cube, update=True)
slab = None
示例3: main
# 需要导入模块: from cube import Cube [as 别名]
# 或者: from cube.Cube import getCube [as 别名]
def main():
parser = argparse.ArgumentParser(description='Ingest the TIFF data')
parser.add_argument('token', action="store", type=str, help='Token for the project')
parser.add_argument('channel', action="store", type=str, help='Channel for the project')
parser.add_argument('path', action="store", type=str, help='Directory with the image files')
parser.add_argument('resolution', action="store", type=int, help='Resolution of data')
result = parser.parse_args()
# Load a database
with closing (ndproj.NDProjectsDB()) as projdb:
proj = projdb.loadToken(result.token)
with closing (SpatialDB(proj)) as db:
ch = proj.getChannelObj(result.channel)
# get the dataset configuration
[[ximagesz, yimagesz, zimagesz],(starttime,endtime)] = proj.datasetcfg.imageSize(result.resolution)
[xcubedim,ycubedim,zcubedim] = cubedim = proj.datasetcfg.getCubeDims()[result.resolution]
[xoffset, yoffset, zoffset] = proj.datasetcfg.getOffset()[result.resolution]
# Get a list of the files in the directories
for slice_number in range (zoffset, zimagesz+1, zcubedim):
slab = np.zeros([zcubedim, yimagesz, ximagesz ], dtype=np.uint32)
for b in range(zcubedim):
if (slice_number + b <= zimagesz):
try:
# reading the raw data
file_name = "{}/{:0>4}.tif".format(result.path, slice_number+b)
print "Open filename {}".format(file_name)
img = Image.open(file_name, 'r').convert("RGBA")
imgdata = np.asarray(img)
slab[b,:,:] = np.left_shift(imgdata[:,:,3], 24, dtype=np.uint32) | np.left_shift(imgdata[:,:,2], 16, dtype=np.uint32) | np.left_shift(imgdata[:,:,1], 8, dtype=np.uint32) | np.uint32(imgdata[:,:,0])
except IOError, e:
print e
imgdata = np.zeros((yimagesz, ximagesz), dtype=np.uint32)
slab[b,:,:] = imgdata
for y in range ( 0, yimagesz+1, ycubedim ):
for x in range ( 0, ximagesz+1, xcubedim ):
# Getting a Cube id and ingesting the data one cube at a time
zidx = ndlib.XYZMorton ( [x/xcubedim, y/ycubedim, (slice_number-zoffset)/zcubedim] )
cube = Cube.getCube(cubedim, ch.getChannelType(), ch.getDataType())
cube.zeros()
xmin = x
ymin = y
xmax = min ( ximagesz, x+xcubedim )
ymax = min ( yimagesz, y+ycubedim )
zmin = 0
zmax = min(slice_number+zcubedim, zimagesz+1)
cube.data[0:zmax-zmin,0:ymax-ymin,0:xmax-xmin] = slab[zmin:zmax, ymin:ymax, xmin:xmax]
db.putCube(ch, zidx, result.resolution, cube, update=True)
示例4: ingest
# 需要导入模块: from cube import Cube [as 别名]
# 或者: from cube.Cube import getCube [as 别名]
def ingest(self):
""" Read image stack and ingest """
# Load a database
with closing(ocpcaproj.OCPCAProjectsDB()) as projdb:
proj = projdb.loadToken(self.token)
with closing(ocpcadb.OCPCADB(proj)) as db:
ch = proj.getChannelObj(self.channel_name)
# get the dataset configuration
[[ximagesz, yimagesz, zimagesz], (starttime, endtime)] = proj.datasetcfg.imageSize(self.resolution)
[xcubedim, ycubedim, zcubedim] = cubedim = proj.datasetcfg.getCubeDims()[self.resolution]
[xoffset, yoffset, zoffset] = proj.datasetcfg.getOffset()[self.resolution]
# Get a list of the files in the directories
for slice_number in range(zoffset, zimagesz, zcubedim):
slab = np.zeros([zcubedim, yimagesz, ximagesz], dtype=np.uint32)
for b in range(zcubedim):
if (slice_number + b <= zimagesz):
file_name = "{}{}{:0>4}.tif".format(self.path, self.token, slice_number+b)
print "Open filename {}".format(file_name)
try:
img = Image.open(file_name,'r')
slab [b,:,:] = np.asarray(img)
except IOError, e:
print "Failed to open file %s" % (e)
img = np.zeros((yimagesz,ximagesz), dtype=np.uint8)
slab [b,:,:] = img
for y in range(0, yimagesz + 1, ycubedim):
for x in range(0, ximagesz + 1, xcubedim):
# Getting a Cube id and ingesting the data one cube at a time
zidx = ocplib.XYZMorton([x / xcubedim, y / ycubedim, (slice_number - zoffset) / zcubedim])
cube = Cube.getCube(cubedim, ch.getChannelType(), ch.getDataType())
cube.zeros()
xmin = x
ymin = y
xmax = min(ximagesz, x + xcubedim)
ymax = min(yimagesz, y + ycubedim)
zmin = 0
zmax = min(slice_number + zcubedim, zimagesz + 1)
cube.data[0:zmax - zmin, 0:ymax - ymin, 0:xmax - xmin] = slab[zmin:zmax, ymin:ymax, xmin:xmax]
from operator import sub
corner = map(sub, [x,y,slice_number], [xoffset,yoffset,zoffset])
if cube.data.any():
db.annotateDense ( ch, corner, self.resolution, cube.data, 'O' )
示例5: buildStack
# 需要导入模块: from cube import Cube [as 别名]
# 或者: from cube.Cube import getCube [as 别名]
def buildStack(token, channel, res):
"""Build the hierarchy of images"""
with closing (ocpcaproj.OCPCAProjectsDB()) as projdb:
proj = projdb.loadToken(token)
with closing (ocpcadb.OCPCADB(proj)) as db:
ch = proj.getChannelObj(channel)
high_res = proj.datasetcfg.scalinglevels
for cur_res in range(res, high_res+1):
# Get the source database sizes
[[ximagesz, yimagesz, zimagesz], timerange] = proj.datasetcfg.imageSize(cur_res)
[xcubedim, ycubedim, zcubedim] = cubedim = proj.datasetcfg.getCubeDims()[cur_res]
[xoffset, yoffset, zoffset] = proj.datasetcfg.getOffset()[cur_res]
biggercubedim = [xcubedim*2,ycubedim*2,zcubedim]
# Set the limits for iteration on the number of cubes in each dimension
xlimit = (ximagesz-1) / xcubedim + 1
ylimit = (yimagesz-1) / ycubedim + 1
zlimit = (zimagesz-1) / zcubedim + 1
for z in range(zlimit):
for y in range(ylimit):
for x in range(xlimit):
# cutout the data at the -1 resolution
olddata = db.cutout(ch, [ x*2*xcubedim, y*2*ycubedim, z*zcubedim], biggercubedim, cur_res-1 ).data
# target array for the new data (z,y,x) order
newdata = np.zeros([zcubedim,ycubedim,xcubedim], dtype=np.uint16)
for sl in range(zcubedim):
# Convert each slice to an image
slimage = Image.frombuffer ( 'I;16', (xcubedim*2,ycubedim*2), olddata[sl,:,:].flatten(), 'raw', 'I;16', 0, 1 )
# Resize the image
newimage = slimage.resize ( [xcubedim,ycubedim] )
# Put to a new cube
newdata[sl,:,:] = np.asarray ( newimage )
zidx = ocplib.XYZMorton ( [x,y,z] )
cube = Cube.getCube(cubedim, ch.getChannelType(), ch.getDataType())
cube.zeros()
cube.data = newdata
print "Inserting Cube {} at res {}".format(zidx, cur_res)
db.putCube(ch, zidx, cur_res, cube, update=True)
示例6: main
# 需要导入模块: from cube import Cube [as 别名]
# 或者: from cube.Cube import getCube [as 别名]
def main():
parser = argparse.ArgumentParser(description='Ingest the TIFF data')
parser.add_argument('token', action="store", type=str, help='Token for the project')
parser.add_argument('channel', action="store", type=str, help='Channel for the project')
parser.add_argument('path', action="store", type=str, help='Directory with the image files')
parser.add_argument('resolution', action="store", type=int, help='Resolution of data')
result = parser.parse_args()
# Load a database
with closing (ocpcaproj.OCPCAProjectsDB()) as projdb:
proj = projdb.loadToken(result.token)
with closing (ocpcadb.OCPCADB(proj)) as db:
ch = proj.getChannelObj(result.channel)
# get the dataset configuration
[[ximagesz, yimagesz, zimagesz],(starttime,endtime)] = proj.datasetcfg.imageSize(result.resolution)
[xcubedim,ycubedim,zcubedim] = cubedim = proj.datasetcfg.getCubeDims()[result.resolution]
[xoffset, yoffset, zoffset] = proj.datasetcfg.getOffset()[result.resolution]
file_name = "{}".format(result.path)
tif_file = tifffile.imread(file_name)
slice_number = 0
# Get a list of the files in the directories
for iteration_number in range(starttime, endtime):
slab = np.zeros([zcubedim, yimagesz, ximagesz], dtype=np.uint16)
import pdb; pdb.set_trace()
slab[slice_number,:,:] = tif_file[iteration_number,:,:]
for y in range ( 0, yimagesz+1, ycubedim ):
for x in range ( 0, ximagesz+1, xcubedim ):
# Getting a Cube id and ingesting the data one cube at a time
zidx = ndlib.XYZMorton ( [x/xcubedim, y/ycubedim, (slice_number-zoffset)/zcubedim] )
cube = Cube.getCube(cubedim, ch.getChannelType(), ch.getDataType(), timerange=[0,1])
cube.zeros()
xmin = x
ymin = y
xmax = min ( ximagesz, x+xcubedim )
ymax = min ( yimagesz, y+ycubedim )
zmin = 0
zmax = min(slice_number+zcubedim, zimagesz+1)
cube.data[0:zmax-zmin,0:ymax-ymin,0:xmax-xmin] = slab[zmin:zmax, ymin:ymax, xmin:xmax]
db.putTimeCube(ch, zidx, iteration_number, result.resolution, cube, update=False)
示例7: ingest
# 需要导入模块: from cube import Cube [as 别名]
# 或者: from cube.Cube import getCube [as 别名]
def ingest(self, channel_name):
""" Read image stack and ingest """
# Load a database
with closing(ocpcaproj.OCPCAProjectsDB()) as projdb:
proj = projdb.loadToken(self.token)
with closing(ocpcadb.OCPCADB(proj)) as db:
ch = proj.getChannelObj(channel_name)
# get the dataset configuration
[[ximagesz, yimagesz, zimagesz], (starttime, endtime)] = proj.datasetcfg.imageSize(self.resolution)
[xcubedim, ycubedim, zcubedim] = cubedim = proj.datasetcfg.getCubeDims()[self.resolution]
[xoffset, yoffset, zoffset] = proj.datasetcfg.getOffset()[self.resolution]
# Get a list of the files in the directories
file_name = "{}{}.tif".format(self.path, channel_name)
print "Open filename {}".format(file_name)
imgdata = tifffile.imread(file_name)
for slice_number in range(zoffset, zimagesz + 1, zcubedim):
slab = np.zeros([zcubedim, yimagesz, ximagesz], dtype=np.uint32)
for b in range(zcubedim):
if (slice_number + b <= zimagesz):
if (slice_number + b) < zimagesz:
slab[b, :, :] = imgdata[(slice_number + b), :, :]
else:
imgdata = np.zeros((yimagesz, ximagesz), dtype=np.uint32)
slab[b, :, :] = imgdata
for y in range(0, yimagesz + 1, ycubedim):
for x in range(0, ximagesz + 1, xcubedim):
# Getting a Cube id and ingesting the data one cube at a time
zidx = ocplib.XYZMorton([x / xcubedim, y / ycubedim, (slice_number - zoffset) / zcubedim])
cube = Cube.getCube(cubedim, ch.getChannelType(), ch.getDataType())
cube.zeros()
xmin = x
ymin = y
xmax = min(ximagesz, x + xcubedim)
ymax = min(yimagesz, y + ycubedim)
zmin = 0
zmax = min(slice_number + zcubedim, zimagesz + 1)
cube.data[0:zmax - zmin, 0:ymax - ymin, 0:xmax - xmin] = slab[zmin:zmax, ymin:ymax, xmin:xmax]
db.putCube(ch, zidx, self.resolution, cube, update=True)
示例8: buildStack
# 需要导入模块: from cube import Cube [as 别名]
# 或者: from cube.Cube import getCube [as 别名]
def buildStack(token, channel, res, base_res):
""" build a zoom hierarchy of images """
scaling = 2**(base_res-res)
with closing (ocpcaproj.OCPCAProjectsDB()) as projdb:
proj = projdb.loadToken(token)
with closing(ocpcadb.OCPCADB(proj)) as db:
ch = proj.getChannelObj(channel)
# get db sizes
[[ximagesz, yimagesz, zimagesz], timerange] = proj.datasetcfg.imageSize(base_res)
[xcubedim, ycubedim, zcubedim] = cubedim = proj.datasetcfg.getCubeDims()[base_res]
[xoffset, yoffset, zoffset] = proj.datasetcfg.getOffset()[base_res]
newcubedim = proj.datasetcfg.getCubeDims()[res]
xlimit = (ximagesz-1) / xcubedim + 1
ylimit = (yimagesz-1) / ycubedim + 1
zlimit = (zimagesz-1) / zcubedim + 1
# iterate over the old cube
for z in range(zlimit):
for y in range(ylimit):
for x in range(xlimit):
# cutout data
old_data = db.cutout( ch, [x*xcubedim, y*ycubedim, z*zcubedim], cubedim, base_res ).data
#new_data = zoomIn(old_data, scaling)
new_data = cZoomIn(old_data, base_res-res)
newzsize = new_data.shape[0] / newcubedim[2] #old_data.shape[0]
newysize = new_data.shape[1] / newcubedim[1] #old_data.shape[1]
newxsize = new_data.shape[2] / newcubedim[0] #old_data.shape[2]
#print "sizes: {} {} {}".format(newxsize, newysize, newzsize)
for z2 in range(newzsize):
for y2 in range(newysize):
for x2 in range(newxsize):
#print "{} {} {}".format(x*newxsize+x2,y*newysize+y2,z*newzsize+z2)
zidx = ndlib.XYZMorton([x*newxsize+x2, y*newysize+y2, z*newzsize+z2])
cube = Cube.getCube(newcubedim, ch.getChannelType(), ch.getDataType())
cube.zeros()
cube.data = new_data[z2*newcubedim[2]:(z2+1)*newcubedim[2], y2*newcubedim[1]:(y2+1)*newcubedim[1], x2*newcubedim[0]:(x2+1)*newcubedim[0]]
#print "Grabbing cube from [{}:{} , {}:{}, {}:{}]".format(z2*newcubedim[2],(z2+1)*newcubedim[2], y2*newcubedim[1],(y2+1)*newcubedim[1], x2*newcubedim[0],(x2+1)*newcubedim[0])
print "Inserting Cube {} at res {}".format(zidx, res)
db.putCube(ch, zidx, res, cube, update=True)
示例9: buildImageStack
# 需要导入模块: from cube import Cube [as 别名]
# 或者: from cube.Cube import getCube [as 别名]
def buildImageStack(proj, ch, res=None):
"""Build the hierarchy of images"""
with closing(ocpcadb.OCPCADB(proj)) as db:
# pick a resolution
if res is None:
res = 1
high_res = proj.datasetcfg.scalinglevels
scaling = proj.datasetcfg.scalingoption
for cur_res in range (res, high_res+1):
# Get the source database sizes
[[ximagesz, yimagesz, zimagesz], timerange] = proj.datasetcfg.imageSize(cur_res)
[xcubedim, ycubedim, zcubedim] = cubedim = proj.datasetcfg.getCubeDims()[cur_res]
if scaling == ZSLICES:
(xscale, yscale, zscale) = (2, 2, 1)
elif scaling == ISOTROPIC:
(xscale, yscale, zscale) = (2, 2, 2)
else:
logger.error("Invalid scaling option in project = {}".format(scaling))
raise OCPCAError("Invalid scaling option in project = {}".format(scaling))
biggercubedim = [xcubedim*xscale,ycubedim*yscale,zcubedim*zscale]
# Set the limits for iteration on the number of cubes in each dimension
xlimit = (ximagesz-1) / xcubedim + 1
ylimit = (yimagesz-1) / ycubedim + 1
zlimit = (zimagesz-1) / zcubedim + 1
# Iterating over time
for ts in range(timerange[0], timerange[1]+1, 1):
# Iterating over zslice
for z in range(zlimit):
# Iterating over y
for y in range(ylimit):
# Iterating over x
for x in range(xlimit):
# cutout the data at the resolution
if ch.getChannelType() not in TIMESERIES_CHANNELS:
olddata = db.cutout(ch, [x*xscale*xcubedim, y*yscale*ycubedim, z*zscale*zcubedim ], biggercubedim, cur_res-1).data
else:
olddata = db.timecutout(ch, [x*xscale*xcubedim, y*yscale*ycubedim, z*zscale*zcubedim ], biggercubedim, cur_res-1, [ts,ts+1]).data
olddata = olddata[0,:,:,:]
#olddata target array for the new data (z,y,x) order
newdata = np.zeros([zcubedim,ycubedim,xcubedim], dtype=OCP_dtypetonp.get(ch.getDataType()))
for sl in range(zcubedim):
if scaling == ZSLICES:
data = olddata[sl,:,:]
elif scaling == ISOTROPIC:
data = ocplib.isotropicBuild_ctype(olddata[sl*2,:,:], olddata[sl*2+1,:,:])
# Convert each slice to an image
# 8-bit int option
if olddata.dtype == np.uint8:
slimage = Image.frombuffer('L', (xcubedim*2,ycubedim*2), data.flatten(), 'raw', 'L', 0, 1)
# 16-bit int option
elif olddata.dtype == np.uint16:
slimage = Image.frombuffer('I;16', (xcubedim*2,ycubedim*2), data.flatten(), 'raw', 'I;16', 0, 1)
# 32-bit float option
elif olddata.dtype == np.float32:
slimage = Image.frombuffer ( 'F', (xcubedim*2,ycubedim*2), data.flatten(), 'raw', 'F', 0, 1 )
# 32 bit RGBA data
elif olddata.dtype == np.uint32:
slimage = Image.fromarray( data, "RGBA" )
# KL TODO Add support for 32bit and 64bit RGBA data
# Resize the image and put in the new cube array
if olddata.dtype != np.uint32:
newdata[sl, :, :] = np.asarray(slimage.resize([xcubedim,ycubedim]))
else:
tempdata = np.asarray(slimage.resize([xcubedim, ycubedim]))
newdata[sl,:,:] = np.left_shift(tempdata[:,:,3], 24, dtype=np.uint32) | np.left_shift(tempdata[:,:,2], 16, dtype=np.uint32) | np.left_shift(tempdata[:,:,1], 8, dtype=np.uint32) | np.uint32(tempdata[:,:,0])
zidx = ocplib.XYZMorton ([x,y,z])
cube = Cube.getCube(cubedim, ch.getChannelType(), ch.getDataType())
cube.zeros()
cube.data = newdata
if ch.getChannelType() not in TIMESERIES_CHANNELS:
db.putCube(ch, zidx, cur_res, cube, update=True)
else:
db.putTimeCube(ch, zidx, ts, cur_res, cube, update=False)
示例10: buildAnnoStack
# 需要导入模块: from cube import Cube [as 别名]
# 或者: from cube.Cube import getCube [as 别名]
def buildAnnoStack ( proj, ch, res=None ):
"""Build the hierarchy for annotations"""
with closing(ocpcadb.OCPCADB (proj)) as db:
# pick a resolution
if res is None:
res = 1
high_res = proj.datasetcfg.scalinglevels
scaling = proj.datasetcfg.scalingoption
for cur_res in range(res, high_res+1):
# Get the source database sizes
[[ximagesz, yimagesz, zimagesz], timerange] = proj.datasetcfg.imageSize(cur_res-1)
[xcubedim, ycubedim, zcubedim] = cubedim = proj.datasetcfg.getCubeDims()[cur_res-1]
# Set the limits for iteration on the number of cubes in each dimension
xlimit = (ximagesz-1) / xcubedim + 1
ylimit = (yimagesz-1) / ycubedim + 1
zlimit = (zimagesz-1) / zcubedim + 1
# Choose constants that work for all resolutions. recall that cube size changes from 128x128x16 to 64*64*64
if scaling == ZSLICES:
outdata = np.zeros ( [ zcubedim*4, ycubedim*2, xcubedim*2 ], dtype=OCP_dtypetonp.get(ch.getDataType()))
elif scaling == ISOTROPIC:
outdata = np.zeros ( [ zcubedim*2, ycubedim*2, xcubedim*2 ], dtype=OCP_dtypetonp.get(ch.getDataType()))
else:
logger.error ( "Invalid scaling option in project = {}".format(scaling) )
raise OCPCAError ( "Invalid scaling option in project = {}".format(scaling))
# Round up to the top of the range
lastzindex = (ocplib.XYZMorton([xlimit,ylimit,zlimit])/64+1)*64
# Iterate over the cubes in morton order
for mortonidx in range(0, lastzindex, 64):
# call the range query
cuboids = db.getCubes(ch, range(mortonidx,mortonidx+64), cur_res-1)
cube = Cube.getCube(cubedim, ch.getChannelType(), ch.getDataType())
# get the first cube
for idx, datastring in cuboids:
xyz = ocplib.MortonXYZ(idx)
cube.fromNPZ(datastring)
if scaling == ZSLICES:
# Compute the offset in the output data cube
# we are placing 4x4x4 input blocks into a 2x2x4 cube
offset = [(xyz[0]%4)*(xcubedim/2), (xyz[1]%4)*(ycubedim/2), (xyz[2]%4)*zcubedim]
# add the contribution of the cube in the hierarchy
ocplib.addDataToZSliceStack_ctype(cube, outdata, offset)
elif scaling == ISOTROPIC:
# Compute the offset in the output data cube
# we are placing 4x4x4 input blocks into a 2x2x2 cube
offset = [(xyz[0]%4)*(xcubedim/2), (xyz[1]%4)*(ycubedim/2), (xyz[2]%4)*(zcubedim/2)]
# use python version for debugging
ocplib.addDataToIsotropicStack_ctype(cube, outdata, offset)
# Get the base location of this batch
xyzout = ocplib.MortonXYZ (mortonidx)
# adjust to output corner for scale.
if scaling == ZSLICES:
outcorner = [ xyzout[0]*xcubedim/2, xyzout[1]*ycubedim/2, xyzout[2]*zcubedim ]
elif scaling == ISOTROPIC:
outcorner = [ xyzout[0]*xcubedim/2, xyzout[1]*ycubedim/2, xyzout[2]*zcubedim/2 ]
# Data stored in z,y,x order dims in x,y,z
outdim = outdata.shape[::-1]
# Preserve annotations made at the specified level
# KL check that the P option preserves annotations? RB changed from O
db.annotateDense(ch, outcorner, cur_res, outdata, 'O')
db.conn.commit()
# zero the output buffer
outdata = np.zeros ([zcubedim*4, ycubedim*2, xcubedim*2], dtype=OCP_dtypetonp.get(ch.getDataType()))
示例11: ingestImageStack
# 需要导入模块: from cube import Cube [as 别名]
# 或者: from cube.Cube import getCube [as 别名]
def ingestImageStack(self):
"""Ingest a TIF image stack"""
# Load a database
with closing (ocpcaproj.OCPCAProjectsDB()) as projdb:
proj = projdb.loadToken(self.token)
with closing (ocpcadb.OCPCADB(proj)) as db:
ch = proj.getChannelObj(self.channel)
# get the dataset configuration
[[ximagesz, yimagesz, zimagesz],(starttime,endtime)] = proj.datasetcfg.imageSize(self.resolution)
[xcubedim, ycubedim, zcubedim] = cubedim = proj.datasetcfg.getCubeDims()[self.resolution]
[xoffset, yoffset, zoffset] = proj.datasetcfg.getOffset()[self.resolution]
if ch.getChannelType() in TIMESERIES_CHANNELS and (starttime == 0 and endtime == 0):
logger.error("Timeseries Data cannot have timerange (0,0)")
raise OCPCAError("Timeseries Data cannot have timerange (0,0)")
# Get a list of the files in the directories
for timestamp in range(starttime, endtime+1):
for slice_number in range (zoffset, zimagesz, zcubedim):
slab = np.zeros([zcubedim, yimagesz, ximagesz ], dtype=OCP_dtypetonp.get(ch.getDataType()))
# fetch 16 slices at a time
if ch.getChannelType() in TIMESERIES_CHANNELS:
time_value = timestamp
else:
time_value = None
self.fetchData(range(slice_number,slice_number+zcubedim) if slice_number+zcubedim<=zimagesz else range(slice_number,zimagesz), time_value=time_value)
for b in range(zcubedim):
if (slice_number + b < zimagesz):
try:
# reading the raw data
file_name = "{}{}".format(self.path, self.generateFileName(slice_number+b))
print "Open filename {}".format(file_name)
logger.info("Open filename {}".format(file_name))
if ch.getDataType() in [UINT8, UINT16] and ch.getChannelType() in IMAGE_CHANNELS + TIMESERIES_CHANNELS:
image_data = np.asarray(Image.open(file_name, 'r'))
slab[b,:,:] = image_data
elif ch.getDataType() in [UINT32] and ch.getChannelType() in IMAGE_CHANNELS + TIMESERIES_CHANNELS:
image_data = np.asarray(Image.open(file_name, 'r').convert('RGBA'))
slab[b,:,:] = np.left_shift(image_data[:,:,3], 24, dtype=np.uint32) | np.left_shift(image_data[:,:,2], 16, dtype=np.uint32) | np.left_shift(image_data[:,:,1], 8, dtype=np.uint32) | np.uint32(image_data[:,:,0])
elif ch.getChannelType() in ANNOTATION_CHANNELS:
image_data = np.asarray(Image.open(file_name, 'r'))
slab[b,:,:] = image_data
else:
logger.error("Cannot ingest this data yet")
raise OCPCAError("Cannot ingest this data yet")
except IOError, e:
logger.warning("IOError {}.".format(e))
slab[b,:,:] = np.zeros((yimagesz, ximagesz), dtype=np.uint32)
for y in range ( 0, yimagesz+1, ycubedim ):
for x in range ( 0, ximagesz+1, xcubedim ):
# Getting a Cube id and ingesting the data one cube at a time
zidx = ocplib.XYZMorton ( [x/xcubedim, y/ycubedim, (slice_number-zoffset)/zcubedim] )
cube = Cube.getCube(cubedim, ch.getChannelType(), ch.getDataType())
cube.zeros()
xmin,ymin = x,y
xmax = min ( ximagesz, x+xcubedim )
ymax = min ( yimagesz, y+ycubedim )
zmin = 0
zmax = min(slice_number+zcubedim, zimagesz+1)
cube.data[0:zmax-zmin,0:ymax-ymin,0:xmax-xmin] = slab[zmin:zmax, ymin:ymax, xmin:xmax]
if cube.isNotZeros():
if ch.getChannelType() in IMAGE_CHANNELS:
db.putCube(ch, zidx, self.resolution, cube, update=True)
elif ch.getChannelType() in TIMESERIES_CHANNELS:
db.putTimeCube(ch, zidx, timestamp, self.resolution, cube, update=True)
elif ch.getChannelType() in ANNOTATION_CHANNELS:
corner = map(sub, [x,y,slice_number], [xoffset,yoffset,zoffset])
db.annotateDense(ch, corner, self.resolution, cube.data, 'O')
else:
logger.error("Channel type {} not supported".format(ch.getChannelType()))
raise OCPCAError("Channel type {} not supported".format(ch.getChannelType()))
# clean up the slices fetched
self.cleanData(range(slice_number,slice_number+zcubedim) if slice_number+zcubedim<=zimagesz else range(slice_number,zimagesz))
示例12: ingestCatmaidStack
# 需要导入模块: from cube import Cube [as 别名]
# 或者: from cube.Cube import getCube [as 别名]
def ingestCatmaidStack(self):
"""Ingest a CATMAID tile stack"""
# Load a database
with closing (ocpcaproj.OCPCAProjectsDB()) as projdb:
proj = projdb.loadToken(self.token)
with closing (ocpcadb.OCPCADB(proj)) as db:
ch = proj.getChannelObj(self.channel)
# get the dataset configuration
[[ximagesz, yimagesz, zimagesz],(starttime,endtime)] = proj.datasetcfg.imageSize(self.resolution)
[xcubedim,ycubedim,zcubedim] = cubedim = proj.datasetcfg.getCubeDims()[self.resolution]
[xoffset, yoffset, zoffset] = proj.datasetcfg.getOffset()[self.resolution]
if ch.getChannelType() in TIMESERIES_CHANNELS and (starttime == 0 and endtime == 0):
pass
else:
logger.error("Timeseries Data cannot have timerange (0,0). Error in {}".format(self.token))
raise OCPCAError("Timeseries Data cannot have timerange (0,0)".format(self.token))
num_xtiles = ximagesz / tilesz
num_ytiles = yimagesz / tilesz
# Get a list of the files in the directories
for timestamp in range(starttime, endtime+1):
for slice_number in range (zoffset, zimagesz+1, zcubedim):
# over all the tiles in the slice
for ytile in range(0, num_ytiles):
for xtile in range(o, num_xtiles):
slab = np.zeros([zcubedim, tilesz, tilesz ], dtype=np.uint8)
for b in range(zcubedim):
if (slice_number + b <= zimagesz):
try:
# reading the raw data
file_name = "{}{}{:0>6}.{}".format(self.path, self.regex (slice_number + b), self.file_type )
logger.info("Open filename {}".format(file_name))
print "Open filename {}".format(file_name)
slab[b,:,:] = np.asarray(Image.open(file_name, 'r'))
except IOError, e:
logger.warning("IOError {}.".format(e))
slab[b,:,:] = np.zeros((tilesz, tilesz), dtype=np.uint32)
for y in range (ytile*tilesz, (ytile+1)*tilesz, ycubedim):
for x in range (xtile*tilesz, (xtile+1)*tilesz, xcubedim):
# Getting a Cube id and ingesting the data one cube at a time
zidx = ocplib.XYZMorton ( [x/xcubedim, y/ycubedim, (slice_number-zoffset)/zcubedim] )
cube = Cube.getCube(cubedim, ch.getChannelType(), ch.getDataType())
cube.zeros()
xmin = x % tilesz
ymin = y % tilesz
xmax = min(ximagesz, x+xcubedim)
ymax = min(yimagesz, y+ycubedim)
zmin = 0
zmax = min(slice_number+zcubedim, zimagesz+1)
cube.data[0:zmax-zmin,0:ymax-ymin,0:xmax-xmin] = slab[zmin:zmax, ymin:ymax, xmin:xmax]
if cube.isNotZeros():
db.putCube(ch, zidx, self.resolution, cube, update=True)
else:
db.putTimeCube(ch, zidx, timestamp, self.resolution, cube, update=True)
示例13: ingestImageStack
# 需要导入模块: from cube import Cube [as 别名]
# 或者: from cube.Cube import getCube [as 别名]
def ingestImageStack(self):
"""Ingest a TIF image stack"""
# Load a database
with closing (ocpcaproj.OCPCAProjectsDB()) as projdb:
proj = projdb.loadToken(self.token)
with closing (ocpcadb.OCPCADB(proj)) as db:
ch = proj.getChannelObj(self.channel)
# get the dataset configuration
[[ximagesz, yimagesz, zimagesz],(starttime,endtime)] = proj.datasetcfg.imageSize(self.resolution)
[xcubedim, ycubedim, zcubedim] = cubedim = proj.datasetcfg.getCubeDims()[self.resolution]
[xoffset, yoffset, zoffset] = proj.datasetcfg.getOffset()[self.resolution]
if ch.getChannelType() in TIMESERIES_CHANNELS and (starttime == 0 and endtime == 0):
print "Timeseries Data cannot have timerange (0,0)"
raise
# Get a list of the files in the directories
for timestamp in range(starttime, endtime+1):
for slice_number in range (zoffset, zimagesz+1, zcubedim):
slab = np.zeros([zcubedim, yimagesz, ximagesz ], dtype=OCP_dtypetonp.get(ch.getDataType()))
# fetch 16 slices at a time
if ch.getChannelType() in TIMESERIES_CHANNELS:
time_value = timestamp
else:
time_value = None
self.fetchData(range(slice_number,slice_number+zcubedim) if slice_number+zcubedim<=zimagesz else range(slice_number,zimagesz), time_value=time_value)
for b in range(zcubedim):
if (slice_number + b <= zimagesz):
try:
# reading the raw data
file_name = "{}{}".format(self.path, self.generateFileName(slice_number+b))
print "Open filename {}".format(file_name)
slab[b,:,:] = np.asarray(Image.open(file_name, 'r'))
except IOError, e:
print e
slab[b,:,:] = np.zeros((yimagesz, ximagesz), dtype=np.uint32)
for y in range ( 0, yimagesz+1, ycubedim ):
for x in range ( 0, ximagesz+1, xcubedim ):
# Getting a Cube id and ingesting the data one cube at a time
zidx = ocplib.XYZMorton ( [x/xcubedim, y/ycubedim, (slice_number-zoffset)/zcubedim] )
cube = Cube.getCube(cubedim, ch.getChannelType(), ch.getDataType())
cube.zeros()
xmin,ymin = x,y
xmax = min ( ximagesz, x+xcubedim )
ymax = min ( yimagesz, y+ycubedim )
zmin = 0
zmax = min(slice_number+zcubedim, zimagesz+1)
cube.data[0:zmax-zmin,0:ymax-ymin,0:xmax-xmin] = slab[zmin:zmax, ymin:ymax, xmin:xmax]
if cube.isNotZeros():
if ch.getChannelType() not in TIMESERIES_CHANNELS:
db.putCube(ch, zidx, self.resolution, cube, update=True)
else:
db.putTimeCube(ch, zidx, timestamp, self.resolution, cube, update=True)
# clean up the slices fetched
self.cleanData(range(slice_number,slice_number+zcubedim) if slice_number+zcubedim<=zimagesz else range(slice_number,zimagesz))