# 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:
# 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: