Skip to content

Instantly share code, notes, and snippets.

@simrit1
Forked from MaxvanHaastrecht/colouring_book.py
Created January 24, 2022 05:39
Show Gist options
  • Save simrit1/27cb6e5e8353cda945c09fc63d157f64 to your computer and use it in GitHub Desktop.
Save simrit1/27cb6e5e8353cda945c09fc63d157f64 to your computer and use it in GitHub Desktop.
Creating a personalised colouring book from your own photos
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