def detection_error_example(): big_crat = np.asarray(tiles['3_25'].crop((800, 725, 1450, 1350))) fig, ax = plt.subplots(1, 3, figsize=(12, 4)) fig.suptitle('Erroneous Detection Criterion') ax[0].imshow(big_crat, cmap='Greys_r') ax[0].set_title('Diameter Error') circle = plt.Circle((322, 329), 144, fill=False, color='green', linewidth=2); ax[0].add_artist(circle); circle = plt.Circle((322, 329), 201, fill=False, color='red', linewidth=2); ax[0].add_artist(circle); circle = plt.Circle((322, 329), 87, fill=False, color='red', linewidth=2); ax[0].add_artist(circle); ax[1].imshow(big_crat, cmap='Greys_r') ax[1].set_title('Location Error') circle = plt.Circle((322, 329), 144, fill=False, color='green', linewidth=2); ax[1].add_artist(circle); circle = plt.Circle((322, 444), 144, fill=False, color='red', linewidth=2); ax[1].add_artist(circle); ax[2].imshow(big_crat, cmap='Greys_r') ax[2].set_title('Combination of Error Types') circle = plt.Circle((322, 329), 144, fill=False, color='green', linewidth=2); ax[2].add_artist(circle); circle = plt.Circle((256, 395), 111, fill=False, color='red', linewidth=2); ax[2].add_artist(circle); circle = plt.Circle((388, 263), 177, fill=False, color='red', linewidth=2); ax[2].add_artist(circle); ax[0], ax[1], ax[2] = remove_ticks(ax[0]), remove_ticks(ax[1]), remove_ticks(ax[2]) handles = [] handles.append(mpatches.Patch(color='green', label='Perfect Detection')) handles.append(mpatches.Patch(color='red', label='Rejected by Criteria')) plt.legend(handles=handles);
def plot_mask(): fig, ax = plt.subplots(ncols=2, figsize=(6, 3)) fig.suptitle('Sample Image and Target Mask'); ax[0].imshow(samp_img, cmap='Greys_r') ax[0] = test_human.remove_ticks(ax[0]) ax[1].imshow(samp_mask, cmap='CMRmap') ax[1] = test_human.remove_ticks(ax[1]) plt.show()
def plot_filters(): fig, ax = plt.subplots(ncols=2, figsize=(9, 5)) fig.suptitle('Automatically-learned Image Filters'); ax[0].imshow(samp_img, cmap='Greys_r') ax[0] = test_human.remove_ticks(ax[0]) ax[1].imshow(filt_img, cmap='CMRmap') ax[1] = test_human.remove_ticks(ax[1]) plt.tight_layout(); plt.show()
def inspect_circle_output(id_no): """Displays a previously-saved prediction for inspection by loading it from hard drive. """ base_path = './tiles/keras_folders/test' prediction = np.load('./tiles/predictions/{}.npy'.format(id_no)) source_image = crop_square(Image.open(base_path+'/{}.png'.format(id_no)), 172, orgn=(42, 42)) ground_truth = Image.open(base_path+'_mask/{}_mask.png'.format(id_no)) circles = FastCircles() craters = circles(prediction) extraction = build_target(craters) fig, ax = plt.subplots(ncols=4, figsize=(12, 3)) fig.suptitle('Desirable Behavior from Circle Procedure') ax = [remove_ticks(x) for x in ax] ax[0].imshow(np.array(source_image), cmap='Greys_r'); ax[0].set_title('Input image'); ax[1].imshow(np.array(ground_truth), cmap='CMRmap'); ax[1].set_title('"Ground Truth"'); ax[2].imshow(prediction, cmap='CMRmap'); ax[2].set_title('Model Prediction'); ax[3].imshow(extraction, cmap='CMRmap'); ax[3].set_title('Extracted Circles'); plt.show() return
def plot_tiles(tiles, tile_names, regions): """Plots the tiles for demonstration purposes.""" fig, axes = plt.subplots(nrows=2, ncols=3, figsize=(9,6)) axes = axes.reshape(6,) for i, ax in enumerate(axes): ax = test_human.remove_ticks(ax) tile = tile_names[i][4:] ax.set_title(tile + ', ' + regions[i]) img = tiles[tile] ax.imshow(np.array(img), cmap='Greys_r')
def display_proposals(proposals=tp, title='title', num_imgs=5): fig, ax = plt.subplots(1, num_imgs, figsize=(num_imgs, 2)); fig.suptitle(title); num = 0 for axis in ax: img = test_human.get_image(human_performance[proposals]['id'].iloc[num]) axis.imshow(img, cmap='Greys') axis = test_human.remove_ticks(axis) plt.tight_layout() num += 1
def show_dbscan(): pixels = np.argwhere(blob_image) #indices = [i for i in range(len(pixels))] #idx = np.random.choice(indices, round(len(pixels)/10)) #pixels = pixels[idx] dbscan = DBSCAN(eps=1) pred = dbscan.fit_predict(pixels) cs = ['r', 'b', 'green', 'yellow', 'cyan', 'violet', 'black', 'orange'] cs = cs * 100 print('number of clusters: {}'.format(len(np.unique(pred)))) fig, ax = plt.subplots() for cluster in np.unique(pred): indices = np.argwhere(np.where(pred == cluster, 1, 0)); ax.scatter(x=pixels[indices, 1], y = (-pixels[indices,0]+150), color=cs[cluster]); ax = remove_ticks(ax) plt.show()
def overlay_mask(id_no, train=True): """Fetches image and accompanying mask and overlays them. Confirms mask is properly generated. """ path = './tiles/keras_folders/' if train: path += 'train/' else: path += 'test/' img = np.array(Image.open(path + '{}.png'.format(id_no))) mask = np.array(Image.open(path[:-1] + '_mask/{}_mask.png'.format(id_no))) mask = pad_mask(mask) fig, ax = plt.subplots() ax.imshow(img, cmap='Greys', alpha=1) ax.imshow(mask, cmap='viridis', alpha=.15) ax = remove_ticks(ax) ax.set_title('Target "ground truth" overlaid on input image')
def inspect_detection(id_no): """Displays a previously-saved prediction for inspection by loading it from hard drive. """ base_path = './tiles/keras_folders/test' prediction = np.load('./tiles/predictions/{}.npy'.format(id_no)) source_image = crop_square(Image.open(base_path+'/{}.png'.format(id_no)), 172, orgn=(42, 42)) ground_truth = Image.open(base_path+'_mask/{}_mask.png'.format(id_no)) fig, ax = plt.subplots(ncols=3, figsize=(8, 4)) fig.suptitle('Results for Tile {}'.format(id_no)) ax = [remove_ticks(x) for x in ax] ax[0].imshow(np.array(source_image), cmap='Greys_r'); ax[0].set_title('Input image'); ax[1].imshow(np.array(ground_truth), cmap='CMRmap'); ax[1].set_title('"Ground Truth"'); ax[2].imshow(prediction, cmap='CMRmap'); ax[2].set_title('Model Prediction'); plt.tight_layout() plt.show() return
rr, cc = circle(y, x, r) try: image[rr, cc] = 255 except: pass return image if __name__ == '__main__': path = './tiles/mask/' for tile in tiles: mask = build_target(all_craters[all_craters.tile == tile]) fig, ax = plt.subplots(ncols=2, figsize=(10, 5)) ax[0].set_title(tile) ax[0].imshow(mask, cmap='Greys') ax[0] = remove_ticks(ax[0]) ax[1].set_title(tile) ax[1].imshow(np.where(mask == 255, tiles[tile], 0), cmap='Greys') ax[1] = remove_ticks(ax[1]) image = Image.fromarray(mask) image.save(path + '{}_mask.bmp'.format(tile)) # In[3]: tf_dir = './tiles/t_tiles/' # In[4]: def random_id(K=5): """Returns a string of random characters (numeric and upper alpha)