Created
July 24, 2014 22:09
-
-
Save ZGainsforth/ab7347f6cd5e967eec45 to your computer and use it in GitHub Desktop.
Apply a Sobel filter to an image.
This file contains hidden or 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
| 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