Created
August 24, 2013 21:43
-
-
Save DanBrink91/6330571 to your computer and use it in GitHub Desktop.
Blur
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/python | |
import Image | |
def average_pixel(x, y, img): | |
sum_ = [0, 0, 0] | |
count_ = 0 | |
for y_ in xrange(y-1, y+1): | |
if y_ >= 0 and y_ <= height: | |
for x_ in xrange(x-1, x+1): | |
if x_ >= 0 and x_ <= width: | |
count_ += 1 | |
sum_[0] += img[x_, y_][0] | |
sum_[1] += img[x_, y_][1] | |
sum_[2] += img[x_, y_][2] | |
return (sum_[0]/count_, sum_[1]/count_, sum_[2]/count_) | |
source = Image.open("test.jpg") | |
img = source.load() | |
width = source.size[0] | |
height = source.size[1] | |
blur_factor = 5 # How many times you want to blur it together | |
for y in xrange(0, height): | |
for x in xrange(0, width): | |
for i in range(blur_factor): | |
img[x, y] = average_pixel(x, y, img) | |
source.save("blurify.png") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment