def canonize(img_file, depth_file, opts, params): img = preprocess_image(img_file) segmask = segmentation(depth_file, opts["segmentation"]) img, segmask = _canonize(img, segmask, opts) # Determine if image is upside down. diff = np.sum(np.abs(img - params["img_avg"])) diff_upsidedown = np.sum(np.abs(img - params["img_avg_upsidedown"])) upsidedown = diff > diff_upsidedown if dataset.is_upside_down(img_file) != upsidedown: print "Canonization failed!" if upsidedown: img = np.fliplr(np.flipud(img)) segmask = np.fliplr(np.flipud(segmask)) return img, segmask
def canonization_training(opts): print "# Canonization training" params = caching.nul_repr_dict() # Generate average intensity image from a subset of the dataset. img_avg = np.zeros(opts["img_shape"], dtype=int) files = dataset.training_files(opts["num_train_images"]) for img_file, depth_file in print_progress(files): img = preprocess_image(img_file) segmask = segmentation(depth_file, opts["segmentation"]) img, segmask = _canonize(img, segmask, opts) # Orient correctly if image is upside down if dataset.is_upside_down(img_file): img = np.fliplr(np.flipud(img)) img_avg += img img_avg /= len(files) params["img_avg"] = img_avg params["img_avg_upsidedown"] = np.fliplr(np.flipud(img_avg)) return params