#!/bin/env python

#Copyright Ryan McGuire
#www.enigmacurry.com
#I grant this code to the public domain

#Randomize an image's pixel values within a small delta

image = "test.jpg"
delta = 2

import random
import Image
im1 = Image.open(image)
im2 = Image.new(im1.mode, im1.size)

for x in range(0,im1.size[0]):
    for y in range(0,im1.size[1]):
        #Grab the pixel
        pixel = im1.getpixel( (x,y) )
        #modify the pixel a bit
        randDiffs = [random.randint(delta*-1,delta) for j in range(0,3)]
        new_pixel = [pixel[j] + randDiffs[j] for j in range(0,3) ]
        #copy the modified pixel to the new image
        im2.putpixel( (x,y), tuple(new_pixel))
    print "%s of %s lines processed" % (x, im1.size[0])
im2.save("test_modified.jpg", "JPEG")
        
