Skip to content

Instantly share code, notes, and snippets.

import media
COLOUR_MAX = 255
COLOUR_MIN = 0
def get_picture():
'''Solicit user input to select a file and load it as a Picture.
Return the Picture.
'''
filename= media.choose_file()
import media
COLOUR_MAX = 255
COLOUR_MIN = 0
def get_picture():
'''Solicit user input to select a file and load it as a Picture.
Return the Picture.
'''
filename= media.choose_file()
def ReturnExample():
return 5
x = ReturnExample()
print x # Prints 5
import media
def sum_red(pic):
total = 0
for p in pic:
r = media.get_red(p)
total = r + total
return total
# Note that these are just samples, and may not work unmodified...
# Comparing pictures stored in picture_a and picture_b
# Assumes:
# 1. You've already resized the images to the same size
# 2. The width & height of the images are stored in variables of the same names
# 3. The images have been normalized to the same average intensity
# 4. You've written a function named 'intensity' to calculate the intensity of
# a given pixel
def adjust_colours(target_pic, reference_pic):
'''Takes target pic and adjusts it's average RGB values to reference pic's RGB values...
'''
target_red_avg = red_average(target_picture)
reference_red_avg = red_average(reference_picture)
red_scale_factor = reference_red_avg/target_red_avg
target_blue_avg = blue_average(target_picture)
def smart_difference(pic1, pic2):
'''Take two pictures and tests how similar they are. Excuse the terrible docstrings. They need some work
'''
h1 = get_height(pic1)
h2 = get_height(pic2)
w1 = get_width(pic1)
w2 = get_width(pic2)
if (h1 > h2):
# Line 254
if x < media.get_width(picture2) and y < media.get_height(picture2):
pixel2 = media.get_pixel(picture2, x, y)
else:
pixel2 = media.get_pixel(picture2, media.get_width(picture2)-1, media.get_height(picture2)-1)
sum_of_difference = sum_of_difference + distance(pixel, pixel2)
same = 0
for x in media.get_width(p1):
for y in media.get_height(p1):
p1_pix = media.get_pixel(p1, x, y)
p2_pix = media.get_pixel(p2, x, y)
@jamesnvc
jamesnvc / gist:667229
Created November 8, 2010 00:29
Code lab
# Given dictionaries, d1 and d2, create a new dictionary with the following
# property: for each entry (a, b) in d1, if there is an entry (b, c) in d2, then
# the entry (a, c) should be added to the new dictionary. For example, if d1 is
# {2:3, 8:19, 6:4, 5:12} and d2 is {2:5, 4:3, 3:9}, then the new dictionary
# should be {2:9, 6:3} Associate the new dictionary with the variable d3
d3 = {}
for (k, v) in d1.iteritems():
if v in d2:
d3[k] = d2[v]