Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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')
ax2.imshow(outside, interpolation='nearest')
ax2.set(title='"Outside" Outline')
ax3.imshow(inside, interpolation='nearest')
ax3.set(title='"Inside" Outline')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.