# Load Preprocessor print("Preprocessing") p = Preprocessor("../images/slum_image.jpg") p.scale_image(scale_factor) p.exposure_equalization(method="equal") p.convert_color("RGB","HSV") p.save_current_as("structure") p.reset() p.scale_image(mask_scale) p.exposure_equalization(method="equal") p.convert_color("RGB","HSV") p.save_current_as("mask") # Load images for mask and structure information img2 = p.get_version("mask")[:,:,0] img = p.get_version("structure")[:,:,2] print("Masking") med_img = median(img2, disk(50*mask_scale)) mask = np.zeros(img2.shape) mask[med_img>np.mean(med_img)] = 1 mask_c = closing(mask, disk(100*mask_scale)) # plot_comparison(mask, mask_c, 'closing') # plot_comparison(mask_c, mean(mask_c, disk(20)), 'mean') masked = np.copy(img) # masked = img * resize(mask_c, img.shape) # plot_comparison(img, masked, "masked")
p.exposure_equalization(method="contrast") p.convert_color("RGB","RGB CIE") p.save_current_as("contrast_rgb_cie") p.reset() p.scale_image(scale_factor) p.exposure_equalization(method="equal") p.convert_color("RGB","HSV") p.save_current_as("structure") # ========== Plot img & patches ========= if plot: plt.figure() ax = plt.gca() img = p.get_version('structure')[:,:,1] plt.imshow(img) # Plot patch centers for name, coords in patches.items(): plt.scatter(coords.T[0], coords.T[1], c=name, s=100*scale_factor) # Plot patch bounding boxes for name, coords in patches.items(): for row in coords: plot_bounding_box(ax, row[0], row[1], box_size, name) plt.xlim((0,img.shape[1])) plt.ylim((img.shape[0],0)) plt.show(block=False)
p.exposure_equalization(method="contrast") p.convert_color("RGB", "RGB CIE") p.save_current_as("contrast_rgb_cie") p.reset() p.scale_image(scale_factor) p.exposure_equalization(method="equal") p.convert_color("RGB", "HSV") p.save_current_as("structure") # ========== Plot img & patches ========= if plot: plt.figure() ax = plt.gca() img = p.get_version('structure')[:, :, 1] plt.imshow(img) # Plot patch centers for name, coords in patches.items(): plt.scatter(coords.T[0], coords.T[1], c=name, s=100 * scale_factor) # Plot patch bounding boxes for name, coords in patches.items(): for row in coords: plot_bounding_box(ax, row[0], row[1], box_size, name) plt.xlim((0, img.shape[1])) plt.ylim((img.shape[0], 0)) plt.show(block=False)
# Load Preprocessor print("Preprocessing") p = Preprocessor("../images/slum_image.jpg") p.scale_image(scale_factor) p.exposure_equalization(method="equal") p.convert_color("RGB", "HSV") p.save_current_as("structure") p.reset() p.scale_image(mask_scale) p.exposure_equalization(method="equal") p.convert_color("RGB", "HSV") p.save_current_as("mask") # Load images for mask and structure information img2 = p.get_version("mask")[:, :, 0] img = p.get_version("structure")[:, :, 2] print("Masking") med_img = median(img2, disk(50 * mask_scale)) mask = np.zeros(img2.shape) mask[med_img > np.mean(med_img)] = 1 mask_c = closing(mask, disk(100 * mask_scale)) # plot_comparison(mask, mask_c, 'closing') # plot_comparison(mask_c, mean(mask_c, disk(20)), 'mean') masked = np.copy(img) # masked = img * resize(mask_c, img.shape) # plot_comparison(img, masked, "masked")