views:

85

answers:

1

Hey guys, Im working on an assignment for my comp sci class, I dont know where Im going wrong here. The function is supposed to take two pictures, pic1 and pic2, and return how different they are.

Heres what I have

def smart_difference(pic1, pic2):
    '''Given two Pictures, pic1 and pic2 of any size and colour, return the 
    difference'''
    red = red_average(pic2)
    blue = blue_average(pic2)
    green = green_average(pic2)

    pic1_height, pic1_width = media.get_height(pic1), media.get_width(pic1)
    pic2_height, pic2_width = media.get_height(pic2), media.get_width(pic2)
    if (pic1_height > pic2_height) and (pic1_width > pic2_width): 
        new_pic1 = media.create_picture(pic2_width, pic2_height)
        new_pic2 = pic2
    elif (pic1_height > pic2_height) and (pic2_width > pic1_width):
        new_pic1 = media.create_picture(pic2_width, pic1_height)
        new_pic2 = media.create_picture(pic2_width, pic1_height)
    elif (pic2_height > pic1_height) and (pic2_width > pic1_width):
        new_pic1 = pic1
        new_pic2 = media.create_picture(pic1_width, pic1_height)
    elif (pic2_height > pic1_height) and (pic1_width > pic2_width):
        new_pic1 = media.create_picture(pic2_width, pic1_height)
        new_pic2 = media.create_picture(pic2_width, pic1_height)

    scale_red(new_pic1, red)
    scale_blue(new_pic1, blue)
    scale_green(new_pic1, green)
    scale_red(new_pic2, red)
    scale_blue(new_pic2, blue)
    scale_green(new_pic2, green)
    return simple_difference(new_pic1, new_pic2)

I run a self_test file (which was given to us for our assignment), but I keep getting an error here, can anyone help?

*Notes:Simple_difference is another function I wrote beforehand that finds the distance between pixels in the two pictures and scales accordingly

A: 

Kay, the error is: "AssertError: result after smart_difference should be between 0 and 1200, not 35000"

Heres what I did for simple difference:

def simple_difference(pic1, pic2): '''Given two Pictures of the same dimensions, pic1 and pic2, return the sum of the distances in color of the two pictures.'''

sum_distance = 0
for pix1, pix2 in zip(pic1, pic2):
    sum_distance += distance(pix1, pix2)
return sum_distance

Im using a media library that we have to use for our class, running python 2.5... which is kind of ridiculous, but that's what we have to use

Victor B