Skip to content

Instantly share code, notes, and snippets.

@mango314
Last active December 31, 2015 04:59
Show Gist options
  • Save mango314/7938217 to your computer and use it in GitHub Desktop.
Save mango314/7938217 to your computer and use it in GitHub Desktop.
script for my dog

Before

# After

# http://cs.stackexchange.com/questions/12925/circle-packing-algorithm-used-by-percolator
from skimage import io, draw
import numpy as np
import matplotlib.pyplot as plt
image = io.imread('Pictures/PR03/DSCI1234.JPG') # or any NumPy array!
def polyclip(image):
# http://scikit-image.org/docs/dev/auto_examples/plot_shapes.html
a,b,c = len(image), len(image[0]), len(image[0][0])
img2 = image
dz = 200
ctr = [(i,j) for i in range(0,a,dz) for j in range(0,b,dz)]
for w in ctr:
z = (w[0] + 1j*w[1]) + 0.5*dz*np.exp(2.0j*np.pi*np.arange(4)/4)
rr,cc = draw.polygon(z.real, z.imag, img2.shape)
for k in range(3):
img2[rr,cc,k] = 0*img2[rr,cc,k] + 1*np.average(img2[rr,cc,k])
return img2[ :dz*(a/dz), :dz*(b/dz), :]
image = polyclip(image)
plt.imshow(image)
plt.axis("off")
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment