for line in open('unlabeled_patches').readlines(): patch_str = line.strip() if patch_str in already_labeled: continue img_patch = np.array(list(patch_str),int).reshape((35,35)) patch = np.empty((35, 35, 3), np.uint8) patch[:] = np.where(img_patch, 0, 255)[:,:,None] patch[c-5:c+6,c,0] ^= 0xFF patch[c,c-5:c+6,0] ^= 0xFF patch[c-1:c+2, c-1:c+2, 1] ^= 0xFF yield img_patch, patch os.unlink('unlabeled_patches') t=Tk() classes = ["background"] + sorted(COLOR_LABELS.values()) + ['skip','quit'] patches_f = open('patches.csv', 'a') patch = None gen = get_images() label = Label(t) label.grid(row=0, column=0, rowspan=len(classes)) buttons = dict() def button(x): global real_img, patch, img, imgTk if x == 'skip': pass elif x == 'quit': sys.exit(0) elif x is not None: print x vals = map(str, (real_img != 0).ravel().astype(int))