Пример #1
0
def test_decrease_brightness():
    '''Test the function decrase_brightness in img_manip.'''
    
    new_pic = create_pic(4, 4)
    new_pic_decrease_bright = img_manip.decrease_brightness(new_pic)
    
    #The average brightness of new_pic_increased_brightness will likely not be 
    #exactly 10 less than that of new_pic because some RGB values may already be
    #0 and cannot decrease, so the function tests for a difference of 10 with
    #an error of 2 rather than for strict difference of 10.
    old_avg_brightness = avg_bright.average_brightness(new_pic)
    new_avg_brightness = avg_bright.average_brightness(new_pic_decrease_bright)
    assert  old_avg_brightness - new_avg_brightness- 10 < 2, \
           "decrease_brightness failed to decrease the picture's average \
Пример #2
0
def test_white_pic():
    """Test if average_brightness calculates the correct value for a 5x5 picture
    consisting of only white pixels."""

    new_pic = media.create_picture(5, 5, media.white)
    assert (
        average_brightness.average_brightness(new_pic) == 255
    ), "The expected average brightness for a white picture was not obtained."
Пример #3
0
def test_3_white_pixels_1_black_pixel():
    """Test if average_brightness calculates the correct value for a 2x2 picture
    consisting of 3 white pixels and 1 black pixel."""

    new_pic = media.create_picture(2, 2, media.white)
    media.set_color(media.get_pixel(new_pic, 0, 0), media.black)
    assert (
        average_brightness.average_brightness(new_pic) == 255 * 3 / 4.0
    ), "The expected average brightness for a picture with 3 white pixels \
Пример #4
0
def normalize_brightness (pic):
    '''Create a copy of the picture pic, multiply the RGB value of each pixel in 
    the copy so that the average brightness is 128, and return the copy.'''
    
    new_pic = pic.copy()
    orig_avg_brightness = average_brightness.average_brightness (new_pic)
    factor = orig_avg_brightness / 128
    for pix in new_pic:
        pix.set_red(min(255, int(pix.get_red() / factor)))
        pix.set_green(min(255, int(pix.get_green() / factor)))
        pix.set_blue(min(255, int(pix.get_blue() / factor)))
        
    return new_pic
Пример #5
0
def test_normalize_brightness():
    '''Test the function normalize_brightness in img_manip.'''
    
    new_pic = create_pic(4, 4)
    new_pic_normalized= img_manip.normalize_brightness(new_pic)
    
    #The average brightness of new_pic_normalized will likely not be exactly 128 
    #because the RBG values are rounded to integer values after being multipled 
    #by the normalization factor, so the function tests for a difference of less 
    #than 2 rather than for equality.
    new_avg_brightness = avg_bright.average_brightness(new_pic_normalized)
    assert abs(new_avg_brightness - 128) < 2, \
           "normalize_brightness failed to normalize the picture's average \
Пример #6
0
def pic_info_GUI (label):
    #Assign the picture's information to the variable pic_info
    pic_info.set("Picture's width: " + str(label.picture.get_width()) + '\n' + \
                 "Picture's height: " + str(label.picture.get_height()) + \
                 '\n' + "Average brightness of the picture: " + \
                 str(int(avg_br.average_brightness(label.picture))))