# patches for this file patches = [] patch_labels = [] label_img = scipy.misc.imread(labels) image_path = os.path.join('samples', os.path.basename(labels)) image, = metaomr.open(image_path) staffsize.staffsize(image) assert image.staff_dist >= 8 image_scale = 8.0 / image.staff_dist image = scipy.misc.imresize( image.byteimg[:image.orig_size[0], :image.orig_size[1]].astype(bool), image_scale, interp='nearest') num_label_patches = 0 for label_type, label_name in COLOR_LABELS.iteritems(): our_patches = [] our_patch_labels = [] is_label = label_img[:, :, :3] == np.array([[label_type]]) # When scaling down, need to ensure each label pixel maps to some # new pixel and isn't overwritten by the background label_y, label_x = np.where(is_label.all(axis=-1)) if len(label_y): label_y = (label_y * image_scale).astype(int) label_x = (label_x * image_scale).astype(int) scale_label = np.zeros_like(image) scale_label[label_y, label_x] = 1 size = LABEL_SIZE if label_name in object_size: size = object_size[label_name] if size > 1:
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))
# patches for this file patches = [] patch_labels = [] label_img = scipy.misc.imread(labels) image_path = os.path.join('samples', os.path.basename(labels)) image, = metaomr.open(image_path) staffsize.staffsize(image) assert image.staff_dist >= 8 image_scale = 8.0 / image.staff_dist image = scipy.misc.imresize(image.byteimg[:image.orig_size[0], :image.orig_size[1]].astype(bool), image_scale, interp='nearest') num_label_patches = 0 for label_type, label_name in COLOR_LABELS.iteritems(): our_patches = [] our_patch_labels = [] is_label = label_img[:, :, :3] == np.array([[label_type]]) # When scaling down, need to ensure each label pixel maps to some # new pixel and isn't overwritten by the background label_y, label_x = np.where(is_label.all(axis=-1)) if len(label_y): label_y = (label_y * image_scale).astype(int) label_x = (label_x * image_scale).astype(int) scale_label = np.zeros_like(image) scale_label[label_y, label_x] = 1 size = LABEL_SIZE if label_name in object_size: size = object_size[label_name] if size > 1: