Skip to content

Instantly share code, notes, and snippets.

@iskandr
Last active December 18, 2015 01:09
Show Gist options
  • Save iskandr/5701759 to your computer and use it in GitHub Desktop.
Save iskandr/5701759 to your computer and use it in GitHub Desktop.
Naive image dilation in Python
def dilate_naive(x, (k,l)):
m,n = x.shape
y = np.empty_like(x)
for i in xrange(m):
for j in xrange(n):
currmax = x[i,j]
for ii in xrange(max(0, i-k/2), min(m, i+k/2+1)):
for jj in xrange(max(0, j-l/2), min(n, j+l/2+1)):
elt = x[ii,jj]
if elt > currmax:
currmax = elt
y[i,j] = currmax
return y
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment