Last active
December 18, 2015 01:09
-
-
Save iskandr/5701759 to your computer and use it in GitHub Desktop.
Naive image dilation in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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