Skip to content

Instantly share code, notes, and snippets.

@joferkington
Created May 21, 2014 22:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joferkington/bd452a15248f22cb24a2 to your computer and use it in GitHub Desktop.
Save joferkington/bd452a15248f22cb24a2 to your computer and use it in GitHub Desktop.
Outlines
import scipy.ndimage as ndimage
import numpy as np
import matplotlib.pyplot as plt
data = np.zeros((40,40), dtype=bool)
data[5:20, 5:20] = True
data[15:35, 15:35] = True
footprint = np.ones((3,3))
outside = ndimage.binary_dilation(data, structure=footprint) - data
inside = data - ndimage.binary_erosion(data, structure=footprint)
fig, (ax1, ax2, ax3) = plt.subplots(ncols=3, figsize=(12,6))
ax1.imshow(data, interpolation='nearest')
ax1.set(title='Original')
ax2.imshow(outside, interpolation='nearest')
ax2.set(title='"Outside" Outline')
ax3.imshow(inside, interpolation='nearest')
ax3.set(title='"Inside" Outline')
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment