Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
try:
#imgdata = ocpcarest.cutout( imageurl, outproj, outDB )
imgdata = cv2.imread(filename,-1)
if imgdata != None:
img = Image.frombuffer( 'I;16', (imgdata.shape[::-1]), imgdata.flatten(), 'raw', 'I;16', 0, 1)
slab[b,:,:] = np.asarray(img.resize( [ximagesz,yimagesz]))
img = None
else:
slab[b,:,:] = np.zeros((yimagesz,ximagesz),dtype=np.uint16)
except IOError, e:
print "Failed to get Cutout. {}".format(e)
for y in range ( 0, yimagesz+1, ycubedim ):
for x in range ( 0, ximagesz+1, xcubedim ):
zidx = ndlib.XYZMorton ( [x/xcubedim,y/ycubedim,(sl-startslice)/zcubedim] )
cubedata = np.zeros ( (zcubedim,ycubedim,xcubedim), dtype=np.uint16 )
xmin = x
ymin = y
xmax = ((min(ximagesz-1,x+xcubedim-1)))+1
ymax = ((min(yimagesz-1,y+ycubedim-1)))+1
zmin = 0
zmax = min(sl+zcubedim,endslice+1)
cubedata[0:zmax-zmin,0:ymax-ymin,0:xmax-xmin] = slab[zmin:zmax, ymin:ymax, xmin:xmax]
cube = imagecube.ImageCube16 ( cubedims )
cube.zeros()
cube.data = cubedata
if np.count_nonzero ( cube.data) != 0:
outDB.putChannelCube ( zidx, 1, result.resolution, cube )
def generateSuperZindex(self, zidx, resolution):
"""Generate super zindex from a given zindex"""
[[ximagesz, yimagesz, zimagesz], timerange] = self.db.proj.datasetcfg.imageSize(resolution)
[xcubedim, ycubedim, zcubedim] = cubedim = self.db.proj.datasetcfg.getCubeDims()[resolution]
[xoffset, yoffset, zoffset] = self.db.proj.datasetcfg.getOffset()[resolution]
[xsupercubedim, ysupercubedim, zsupercubedim] = super_cubedim = self.db.proj.datasetcfg.getSuperCubeDims()[resolution]
# super_cubedim = map(mul, cubedim, SUPERCUBESIZE)
[x, y, z] = ndlib.MortonXYZ(zidx)
corner = map(mul, ndlib.MortonXYZ(zidx), cubedim)
[x,y,z] = map(div, corner, super_cubedim)
# print zidx, corner, [x,y,z], ndlib.XYZMorton([x,y,z])
return ndlib.XYZMorton([x,y,z])
# reading the raw data
file_name = "{}BrainBowExM_{: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)
zidx_list = []
cube_list = []
# SuperCube Size
[xnumcubes, ynumcubes, znumcubes] = self.db.datasetcfg.getSuperCubeSize()
# Cube dimensions
cubedim = self.db.datasetcfg.cubedim[resolution]
[x,y,z] = ndlib.MortonXYZ(super_zidx)
# start = map(mul, cubedim, [x,y,z])
start = map(mul, [x,y,z], self.db.datasetcfg.getSuperCubeSize())
for z in range(znumcubes):
for y in range(ynumcubes):
for x in range(xnumcubes):
zidx = ndlib.XYZMorton(map(add, start, [x,y,z]))
# Parameters in the cube slab
index = map(mul, cubedim, [x,y,z])
end = map(add, index, cubedim)
cube_data = super_cube[index[2]:end[2], index[1]:end[1], index[0]:end[0]]
zidx_list.append(zidx)
cube_list.append(blosc.pack_array(cube_data))
return zidx_list, cube_list