Skip to content

Instantly share code, notes, and snippets.

@automata
Created May 26, 2014 11:45
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 automata/09050f23ac3e1e63e7d1 to your computer and use it in GitHub Desktop.
Save automata/09050f23ac3e1e63e7d1 to your computer and use it in GitHub Desktop.
grey dilation
# coding: utf-8
from scipy import ndimage
import numpy as np
a = np.array([[0, 0, 0, 0, 0],
[0, 10, 150, 2, 0],
[0, 0, 0, 200, 0],
[0, 0, 0, 0, 0],
[0, 20, 300, 0, 0],
[0, 0, 0, 0, 0]])
k = np.array([[True, True, True],
[True, False, True],
[True, True, True]])
k2 = np.array([[False, True, False],
[True, True, True],
[False, True, False]])
d = ndimage.grey_dilation(a, footprint=k).astype(a.dtype)
r = (a > d).astype(a.dtype)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment