Created
April 26, 2013 04:29
-
-
Save cleure/5465042 to your computer and use it in GitHub Desktop.
Fun little demo of Convolution Kernels in image processing
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
from imagekit import * | |
i = ImageBuffer.fromJPEG('seattle.jpg') | |
# Darken, and pallete swap (emerald) | |
darken = [ | |
0.00, 0.00, 0.00, | |
0.16, 0.16, 0.16, | |
0.16, 0.16, 0.16] | |
# Pre blur matrix | |
bl_matrix = [1.0/25.0 for a in range(25)] | |
# Post blur matrix | |
vb_matrix = [ | |
0.3, 0.4, 0.3, | |
0.3, 0.2, 0.3, | |
0.3, 0.4, 0.3] | |
# Outline matrix | |
ot_matrix = [ | |
1, 1, 1, | |
1, -7, 1, | |
1, 1, 1] | |
# Edge Detect | |
ed_matrix = [ | |
0, 0, -1, 0, 0, | |
-1, -1, -1, -1, -1, | |
0, 0, 12, 0, 0, | |
-1, -1, -1, -1, -1, | |
0, 0, -1, 0, 0] | |
# Apply Filters | |
i.apply_matrix(darken) | |
i.apply_cvkernel(bl_matrix) | |
i.apply_cvkernel(ot_matrix) | |
i.apply_cvkernel(ed_matrix) | |
i.apply_cvkernel(vb_matrix) | |
i.savePNG('output.png') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment