Created
September 24, 2021 13:37
-
-
Save MaxvanHaastrecht/e61cb45cae49656f2908f42b2507070f to your computer and use it in GitHub Desktop.
Creating a personalised colouring book from your own photos
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| from skimage import io | |
| import skimage.color as color | |
| import skimage.segmentation as seg | |
| # Read the image you want to process | |
| image = io.imread('image.png') | |
| # Use simple linear iterative clustering (type of k-means) to construct segmented image | |
| image_slic_result = seg.slic(image, n_segments = 100, | |
| compactness = 40.0, max_iter = 30, start_label = 1) | |
| # Take the average color of the regions | |
| image_avg = color.label2rgb(image_slic_result, image, kind='avg', bg_label = 0) | |
| # Make the inner part of each image segment white | |
| edge_width_in_pixels = 10 | |
| color_book_image = fill_segments_white(image_avg, edge_width_in_pixels) | |
| # Save the image | |
| io.imsave('colorbook.png', color_book_image) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment