Skip to content

Instantly share code, notes, and snippets.

@ZGainsforth
Created July 24, 2014 22:09
Show Gist options
  • Select an option

  • Save ZGainsforth/ab7347f6cd5e967eec45 to your computer and use it in GitHub Desktop.

Select an option

Save ZGainsforth/ab7347f6cd5e967eec45 to your computer and use it in GitHub Desktop.
Apply a Sobel filter to an image.
import numpy as np
import Image
import scipy.ndimage as ndimage
def sobel(img):
gx = ndimage.filters.convolve(img, np.array([[-1, 0, +1], [-2, 0, +2], [-1, 0, +1]]))
gy = ndimage.filters.convolve(img, np.array([[+1, +2, +1], [0, 0, 0], [-1, -2, -1]]))
imgout = np.sqrt(gx**2+gy**2)
return imgout
img = np.array(Image.open('BW with PSF.tif'))
i = Image.fromarray(sobel(img))
i.save('BW with PSF sobel.tif')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment