def setup(self): """Setup the scene. """ scene = getScene() # Set up direction scene.up = (0,1,0) # Camera self.cam = TargetCamera( name = "SlideShow_Cam", pos = (0,0,5.6), fov = 30 ) # Set background... gradient = Image.new("RGB", (2,128)) draw = ImageDraw.Draw(gradient) colbottom = vec3(0.1, 0.1, 0.3) colmid = vec3(0.95,0.95,1) coltop = vec3(0.2, 0.2, 0.4) colormap = [colbottom, colbottom, colmid, coltop, coltop] for y in range(128): t = float(y)/128 c = spline(t, colormap) draw.line([0,y, 1,y], fill=(int(c.x*255), int(c.y*255), int(c.z*255))) back = Plane( lx=4, ly=3, pos=(0,0,-5), scale=2.4, material = GLMaterial( diffuse = (0,1,1), texture = GLTexture(image = gradient, mode = GL_REPLACE)) ) # Create plate materials... initial = Image.new("RGB", (4,4)) invY = mat4(1).translate(vec3(0,1,0)).scale(vec3(1,-1,1)) self.mat1 = GLMaterial( diffuse = (1,1,1,1), texture = GLTexture( image = initial, mode = GL_REPLACE, # size = (512,512), transform = invY, wrap_s = GL_CLAMP, wrap_t = GL_CLAMP ) ) self.backmaterial = self.mat1 self.setBackImage(self.images[0][0]) self.mat2 = GLMaterial( diffuse = (1,1,1,1), texture = GLTexture( image = initial, mode = GL_REPLACE, # size = (512,512), transform = invY, wrap_s = GL_CLAMP, wrap_t = GL_CLAMP ) ) self.backmaterial = self.mat2 self.setBackImage(self.images[1][0]) self.frontmaterial = self.mat1 self.backmaterial = self.mat2 # Create plates... self.frontplate = Plane(lx = 4, ly = 3, material = self.frontmaterial) self.backplate = Plane(lx = 4, ly = 3, pos = (0,0,-0.1), material = self.backmaterial ) self.helper = Sphere(radius=0.1, pos=(0,0,-1))
def stitch(filename, removetiles=False, infostream=None): """Stitch several image tiles together. filename is the base name of the image that determines the file names of the tiles. filename is also the name of the output image. If removetiles is True, the individual image files will be deleted after the image has been stitched. If infostream is set to a file like object it is used to output status information about the stitching process. The name of an image tile must contain the crop information that was used to create the image. For example, the name of a tile for an image "out.tif" could look like this: "out_0.0_0.5_0.75_1.0.tif". The four values are the x1,x2,y1,y2 values of the crop window. Those values together with the resolution of the tile determine the resolution of the entire image. The position of the tile within that image is given by x1,y1. """ inname,inext = os.path.splitext(filename) tilenames = glob.glob("%s*%s"%(inname,inext)) # A list of tuples (tilename, coords, img) tiles = [] mode = None # Filter tiles and fill the tiles list... for tilename in tilenames: # No tile at all? if not isTile(tilename): continue name,ext,coords = splitTileName(tilename) # A tile of another image? if name!=inname or ext!=inext: continue # Open the tile image... img = Image.open(tilename) # Set required mode if mode==None: mode = img.mode if img.mode!=mode: raise ValueError, "%s: Mode mismatch, %s instead of %s"%(tilename, img.mode, mode) tiles.append((tilename, coords, img)) # No tiles? then exit if len(tiles)==0: if infostream!=None: print >>infostream, 'No image tiles found for image "%s"'%filename return # Create the output image... width, height, xposs, yposs = outputSpecs(tiles) mode = tiles[0][2].mode if infostream!=None: print >>infostream, "Final resolution: %dx%d, mode: %s"%(width, height, mode) outimg = Image.new(mode, (width, height)) # Paste the tiles into the output image... for tilename, coords, img in tiles: x = xposs[coords[0]] y = yposs[coords[2]] outimg.paste(img, (x, y)) # Delete the reference to the image img = None # Save the output image if infostream!=None: print >>infostream, "Stitched %d tiles"%len(tiles) print >>infostream, 'Saving "%s"...'%filename outimg.save(filename) # Remove tiles (if desired) if removetiles: if infostream!=None: print >>infostream, "Removing tiles..." # Get the tile names and delete the tiles list # so that the images are no longer referenced # (otherwise they couldn't be deleted) tilenames = map(lambda x: x[0], tiles) tiles = None for tilename in tilenames: os.remove(tilename)
def stitch(filename, removetiles=False, infostream=None): """Stitch several image tiles together. filename is the base name of the image that determines the file names of the tiles. filename is also the name of the output image. If removetiles is True, the individual image files will be deleted after the image has been stitched. If infostream is set to a file like object it is used to output status information about the stitching process. The name of an image tile must contain the crop information that was used to create the image. For example, the name of a tile for an image "out.tif" could look like this: "out_0.0_0.5_0.75_1.0.tif". The four values are the x1,x2,y1,y2 values of the crop window. Those values together with the resolution of the tile determine the resolution of the entire image. The position of the tile within that image is given by x1,y1. """ inname, inext = os.path.splitext(filename) tilenames = glob.glob("%s*%s" % (inname, inext)) # A list of tuples (tilename, coords, img) tiles = [] mode = None # Filter tiles and fill the tiles list... for tilename in tilenames: # No tile at all? if not isTile(tilename): continue name, ext, coords = splitTileName(tilename) # A tile of another image? if name != inname or ext != inext: continue # Open the tile image... img = Image.open(tilename) # Set required mode if mode == None: mode = img.mode if img.mode != mode: raise ValueError("%s: Mode mismatch, %s instead of %s" % (tilename, img.mode, mode)) tiles.append((tilename, coords, img)) # No tiles? then exit if len(tiles) == 0: if infostream != None: print >> infostream, 'No image tiles found for image "%s"' % filename return # Create the output image... width, height, xposs, yposs = outputSpecs(tiles) mode = tiles[0][2].mode if infostream != None: print >> infostream, "Final resolution: %dx%d, mode: %s" % ( width, height, mode) outimg = Image.new(mode, (width, height)) # Paste the tiles into the output image... for tilename, coords, img in tiles: x = xposs[coords[0]] y = yposs[coords[2]] outimg.paste(img, (x, y)) # Delete the reference to the image img = None # Save the output image if infostream != None: print >> infostream, "Stitched %d tiles" % len(tiles) print >> infostream, 'Saving "%s"...' % filename outimg.save(filename) # Remove tiles (if desired) if removetiles: if infostream != None: print >> infostream, "Removing tiles..." # Get the tile names and delete the tiles list # so that the images are no longer referenced # (otherwise they couldn't be deleted) tilenames = map(lambda x: x[0], tiles) tiles = None for tilename in tilenames: os.remove(tilename)