def hello(self, im): " filename is the classavg image " if self.docfile == "" or self.serfile == "": self.callTemplates() filename = im.info['filename'] #print "hello from " + filename tmp = self.doctemplate.get() fn = Spiderutils.template2filename(tmp, os.path.basename(filename)) if len(fn) < 1: return if not os.path.exists(fn): print "Unable to find " + fn return D = Spiderutils.readdoc(fn, keys='all') plist = [] files = D.keys() for f in files: num = int(D[f][0]) # each element is a list (of column data) imgfilename = Spiderutils.template2filename(self.serfile, num) plist.append(imgfilename) title = "images for class: " + os.path.basename(filename) newtop = Toplevel(self.top) m = montage.montage(newtop, imagelist=plist, title=title, useLabels=0) m.makeMenus() m.createMontage()
def __init__(self, master, classTemplate, max_depth=5, savefilename='outfile.dat', margin_width=3, canvasWidth=1600, labelBorder=3): # store passed values self.master = master self.classTemplate = classTemplate self.max_depth = max_depth self.savefilename = savefilename self.margin_width = margin_width self.canvasWidth = canvasWidth self.labelBorder = labelBorder # initialize self.coords_dictionary = {} self.photo_list = [] self.select_dictionary = {} # get image dimensions: ix,iy = im.size # dimensions classname = Spiderutils.template2filename(self.classTemplate, n=1) classavg = Image.open(classname) self.xdim = classavg.size[0] + 2 * self.labelBorder self.ydim = classavg.size[1] + 2 * self.labelBorder + self.margin_width # colors self.good_color = 'green' self.select_flag = 1 self.bad_color = 'red'
def __init__(self, master, classTemplate, max_depth=5, savefilename='outfile.dat', margin_width=3, canvasWidth=1600, labelBorder=3) : # store passed values self.master = master self.classTemplate = classTemplate self.max_depth = max_depth self.savefilename = savefilename self.margin_width = margin_width self.canvasWidth = canvasWidth self.labelBorder = labelBorder # initialize self.coords_dictionary={} self.photo_list=[] self.select_dictionary = {} # get image dimensions: ix,iy = im.size # dimensions classname = Spiderutils.template2filename(self.classTemplate,n=1) classavg = Image.open(classname) self.xdim = classavg.size[0] + 2*self.labelBorder self.ydim = classavg.size[1] + 2*self.labelBorder + self.margin_width # colors self.good_color = 'green' self.select_flag = 1 self.bad_color = 'red'
def __init__(self, master, classTemplate, max_depth=5, savefilename='outfile.dat', margin_width=3, canvasWidth=1600, labelBorder=3): # store passed values self.master = master self.classTemplate = classTemplate self.max_depth = max_depth self.savefilename = savefilename self.margin_width = margin_width self.canvasWidth = canvasWidth self.labelBorder = labelBorder # initialize self.coords_dictionary = {} self.photo_list = [] self.select_dictionary = {} # get image dimensions: ix,iy = im.size # dimensions classname = Spiderutils.template2filename(self.classTemplate, n=1) classavg = Image.open(classname) # self.xdim,self.ydim = classavg.size self.xdim = classavg.size[0] + 2 * self.labelBorder self.ydim = classavg.size[1] + 2 * self.labelBorder + self.margin_width # calculate canvas dimensions self.canvasx = 2**(self.max_depth - 1) * (self.xdim + self.margin_width) self.canvasy = self.max_depth * self.ydim # define canvas self.tree_canvas = Canvas(self.master, height=self.canvasy) self.tree_canvas.configure(width=self.canvasx) self.tree_canvas.configure(scrollregion=(0, 0, self.canvasx, self.canvasy)) print 'Canvas dimensions:', self.canvasx, self.canvasy # scrollbars self.HscrollBar = Scrollbar(self.master, command=self.tree_canvas.xview, orient=HORIZONTAL) self.tree_canvas.configure(xscrollcommand=self.HscrollBar.set) self.HscrollBar.pack(side=BOTTOM, fill=X) self.VscrollBar = Scrollbar(self.master, command=self.tree_canvas.yview, orient=VERTICAL) self.tree_canvas.configure(yscrollcommand=self.VscrollBar.set) self.VscrollBar.pack(side=RIGHT, fill=Y) # colors self.good_color = 'green' self.select_flag = 1 self.bad_color = 'red'
def drawTree(self): self.class2label = {} # lookup table to find an image # loop through depths, from bottom for depthCounter in range(self.max_depth): # range is 0..max_depth-1 currentDepth = depthCounter + 1 firstNode = 2**(currentDepth - 1) lastNode = 2**(currentDepth) - 1 nodesRow = lastNode - firstNode + 1 bandWidth = self.canvasx / nodesRow nodeCoordy = currentDepth * self.ydim # loop through nodes for rowNode in range(nodesRow): # range is 0..nodesRow-1 current_node = rowNode + firstNode # range is firstNode..lastNode nodeCoordx = (rowNode + 0.5) * bandWidth # write coordinates to dictionary self.coords_dictionary[str(current_node)] = [ nodeCoordx, nodeCoordy ] # if not top row, then draw line to parent node if currentDepth != 1: # calculate node# for daughter nodes parentNode = current_node / 2 # will convert to INT (rightly so) if odd # get coordinates for daughter nodes parentCoordx = self.coords_dictionary[str(parentNode)][0] parentCoordy = self.coords_dictionary[str( parentNode)][1] - self.ydim + self.margin_width # check if image exists classname = Spiderutils.template2filename(self.classTemplate, n=current_node) # if file exists, then draw lines and paste image if os.path.exists(classname): # draw line to parent if currentDepth != 1: self.tree_canvas.create_line(nodeCoordx, nodeCoordy - self.ydim, parentCoordx, parentCoordy, tag='parent_line') self.tree_canvas.lower( 'parent_line' ) # otherwise lines are on top of images # prepare image window and store info classavg = Image.open(classname) Tkimage = ImageTk.PhotoImage(classavg.convert2byte(), palette=256) image_label = Label(self.tree_canvas, image=Tkimage, borderwidth=self.labelBorder) image_label.photo = Tkimage image_label.filenum = current_node self.class2label[current_node] = image_label image_label.bind( '<Button-1>', lambda event, w=image_label: self.selectClass(w)) self.photo_list.append(image_label) # draw image window self.tree_canvas.create_window(nodeCoordx, nodeCoordy, window=image_label, anchor=S) last_node = classname # necessary? # Finish drawing self.tree_canvas.pack() self.master.bind('<Control-t>', self.test) self.master.bind('<Control-s>', self.saveSelections) self.master.bind('<Control-r>', self.readSelections)
NodeTemplate = Spiderutils.name2template(filelist[0]) # print 'file template:', NodeTemplate else: print print "syntax: tree.py node_img001.ext {max_depth margin_width canvas_width}" print sys.exit() if sys.argv[2:]: maxDepth = int(sys.argv[2]) else: maxDepth = 6 print 'max_depth:', maxDepth last_node = 2**(maxDepth) - 1 last_file = Spiderutils.template2filename(NodeTemplate, n=last_node) print 'last_file:', last_file if sys.argv[3:]: marginWidth = int(sys.argv[3]) else: marginWidth = 2 print 'margin_width:', marginWidth if sys.argv[4:]: canvasWidth = int(sys.argv[4]) else: canvasWidth = 1600 print 'canvas_width:', canvasWidth from Tkinter import *
def drawTree(self): # calculate canvas dimensions self.canvasx = 2**(self.max_depth - 1) * (self.xdim + self.margin_width) self.canvasy = self.max_depth * self.ydim if hasattr(self, 'tree_canvas'): self.tree_canvas.destroy() if hasattr(self, 'HscrollBar'): self.HscrollBar.destroy() if hasattr(self, 'VscrollBar'): self.VscrollBar.destroy() # define canvas self.tree_canvas = Canvas(self.master, height=self.canvasy) self.tree_canvas.configure(width=self.canvasx) self.tree_canvas.configure(scrollregion=(0, 0, self.canvasx, self.canvasy)) print 'Canvas dimensions:', self.canvasx, self.canvasy # scrollbars self.HscrollBar = Scrollbar(self.master, command=self.tree_canvas.xview, orient=HORIZONTAL) self.tree_canvas.configure(xscrollcommand=self.HscrollBar.set) self.HscrollBar.pack(side=BOTTOM, fill=X) self.VscrollBar = Scrollbar(self.master, command=self.tree_canvas.yview, orient=VERTICAL) self.tree_canvas.configure(yscrollcommand=self.VscrollBar.set) self.VscrollBar.pack(side=RIGHT, fill=Y) self.class2label = {} # lookup table to find an image # loop through depths, from bottom for depthCounter in range(self.max_depth): # range is 0..max_depth-1 currentDepth = depthCounter + 1 firstNode = 2**(currentDepth - 1) lastNode = 2**(currentDepth) - 1 nodesRow = lastNode - firstNode + 1 bandWidth = self.canvasx / nodesRow nodeCoordy = currentDepth * self.ydim # loop through nodes for rowNode in range(nodesRow): # range is 0..nodesRow-1 current_node = rowNode + firstNode # range is firstNode..lastNode nodeCoordx = (rowNode + 0.5) * bandWidth # write coordinates to dictionary self.coords_dictionary[str(current_node)] = [ nodeCoordx, nodeCoordy ] # if not top row, then draw line to parent node if currentDepth != 1: # calculate node# for daughter nodes parentNode = current_node / 2 # will convert to INT (rightly so) if odd # get coordinates for daughter nodes parentCoordx = self.coords_dictionary[str(parentNode)][0] parentCoordy = self.coords_dictionary[str( parentNode)][1] - self.ydim + self.margin_width # check if image exists classname = Spiderutils.template2filename(self.classTemplate, n=current_node) # if file exists, then draw lines and paste image if os.path.exists(classname): # draw line to parent if currentDepth != 1: self.tree_canvas.create_line(nodeCoordx, nodeCoordy - self.ydim, parentCoordx, parentCoordy, tag='parent_line') self.tree_canvas.lower( 'parent_line' ) # otherwise lines are on top of images # prepare image window and store info classavg = Image.open(classname) Tkimage = ImageTk.PhotoImage(classavg.convert2byte(), palette=256) image_label = Label(self.tree_canvas, image=Tkimage, borderwidth=self.labelBorder) image_label.photo = Tkimage image_label.filenum = current_node self.class2label[current_node] = image_label image_label.bind( '<Button-1>', lambda event, w=image_label: self.selectClass(w)) self.photo_list.append(image_label) # draw image window self.tree_canvas.create_window(nodeCoordx, nodeCoordy, window=image_label, anchor=S) last_node = classname # necessary? # Finish drawing self.tree_canvas.pack() self.master.bind('<Control-t>', self.test) self.master.bind('<Control-s>', self.saveSelections) self.master.bind('<Control-r>', self.readSelections) self.master.bind('<Control-w>', self.closeWindow) self.master.bind('<plus>', self.levelUp) self.master.bind('<minus>', self.levelDown)
def drawTree(self) : # calculate canvas dimensions self.canvasx = 2**(self.max_depth-1)*(self.xdim + self.margin_width) self.canvasy = self.max_depth * self.ydim if hasattr(self,'tree_canvas'): self.tree_canvas.destroy() if hasattr(self,'HscrollBar'): self.HscrollBar.destroy() if hasattr(self,'VscrollBar'): self.VscrollBar.destroy() # define canvas self.tree_canvas = Canvas(self.master,height=self.canvasy) self.tree_canvas.configure(width=self.canvasx) self.tree_canvas.configure(scrollregion=(0,0,self.canvasx,self.canvasy)) print 'Canvas dimensions:',self.canvasx,self.canvasy # scrollbars self.HscrollBar = Scrollbar(self.master, command=self.tree_canvas.xview, orient=HORIZONTAL) self.tree_canvas.configure(xscrollcommand=self.HscrollBar.set) self.HscrollBar.pack(side=BOTTOM, fill=X) self.VscrollBar = Scrollbar(self.master, command=self.tree_canvas.yview, orient=VERTICAL) self.tree_canvas.configure(yscrollcommand=self.VscrollBar.set) self.VscrollBar.pack(side=RIGHT, fill=Y) self.class2label = {} # lookup table to find an image # loop through depths, from bottom for depthCounter in range(self.max_depth): # range is 0..max_depth-1 currentDepth = depthCounter + 1 firstNode = 2**(currentDepth-1) lastNode = 2**(currentDepth) - 1 nodesRow = lastNode-firstNode+1 bandWidth = self.canvasx / nodesRow nodeCoordy = currentDepth * self.ydim # loop through nodes for rowNode in range(nodesRow): # range is 0..nodesRow-1 current_node = rowNode+firstNode # range is firstNode..lastNode nodeCoordx = (rowNode+0.5)*bandWidth # write coordinates to dictionary self.coords_dictionary[str(current_node)] = [nodeCoordx,nodeCoordy] # if not top row, then draw line to parent node if currentDepth != 1 : # calculate node# for daughter nodes parentNode = current_node/2 # will convert to INT (rightly so) if odd # get coordinates for daughter nodes parentCoordx = self.coords_dictionary[str(parentNode)][0] parentCoordy = self.coords_dictionary[str(parentNode)][1] - self.ydim + self.margin_width # check if image exists classname = Spiderutils.template2filename(self.classTemplate,n=current_node) # if file exists, then draw lines and paste image if os.path.exists(classname): # draw line to parent if currentDepth != 1 : self.tree_canvas.create_line(nodeCoordx,nodeCoordy-self.ydim, parentCoordx,parentCoordy, tag='parent_line') self.tree_canvas.lower('parent_line') # otherwise lines are on top of images # prepare image window and store info classavg = Image.open(classname) Tkimage = ImageTk.PhotoImage(classavg.convert2byte(), palette=256) image_label = Label(self.tree_canvas, image=Tkimage, borderwidth=self.labelBorder) image_label.photo = Tkimage image_label.filenum = current_node self.class2label[current_node] = image_label image_label.bind('<Button-1>', lambda event, w=image_label : self.selectClass(w)) self.photo_list.append(image_label) # draw image window self.tree_canvas.create_window(nodeCoordx,nodeCoordy, window=image_label, anchor=S) last_node = classname # necessary? # Finish drawing self.tree_canvas.pack() self.master.bind('<Control-t>', self.test) self.master.bind('<Control-s>', self.saveSelections) self.master.bind('<Control-r>', self.readSelections) self.master.bind('<Control-w>', self.closeWindow) self.master.bind('<plus>', self.levelUp) self.master.bind('<minus>', self.levelDown)