Created
November 10, 2016 10:08
-
-
Save MartinThoma/f51a1044c4abc6c7b81915ef96b7cfbd to your computer and use it in GitHub Desktop.
Playing with image filters.
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
#!/usr/bin/env python | |
"""Playing with image filters.""" | |
import scipy.misc | |
import scipy.ndimage | |
import numpy as np | |
# Load an example image | |
# Use scipy.ndimage.imread(file_name, mode='L') if you have your own | |
img = scipy.misc.face() | |
# Convert to grayscale | |
R = img[:, :, 0] | |
G = img[:, :, 1] | |
B = img[:, :, 2] | |
img_gray = R * 299. / 1000 + G * 587. / 1000 + B * 114. / 1000 | |
img = img_gray | |
# Show and save original image | |
scipy.misc.imshow(img) | |
scipy.misc.imsave("original.png", img) | |
# Convolve | |
k = np.array([[-1, 0, 1], [-1, 0, 1], [-1, 0, 1]]) | |
new1 = scipy.ndimage.convolve(img, k, mode='constant', cval=0.0) | |
# Show and save convolved image | |
scipy.misc.imshow(new1) | |
scipy.misc.imsave("new1.png", new1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment