def reduce_width(pic, reducing_factor):
    ''' Take Picture pic and return a duplicate of it that is horizontally 
        compressed by an Integer reducing_factor''' 
      
    # Create a new Picture with the appropriate old height and new width, and
    # initialize the colour to black (all colour components are zero).
    new_width = (pic.get_width() - 1) / reducing_factor + 1
    new_height = pic.get_height()
    newpic = media.create_picture(new_width, new_height, media.black)
    
    # Iterate through all the Pixels in the large image, and copy
    # a portion of that Pixel's colour components into the correct 
    # Pixel position in the smaller image.
    for pixel in pic:
        # Find the corresponding Pixel in the new Picture.
        x_coordinate = media.get_x(pixel)/reducing_factor;
        y_coordinate = media.get_y(pixel);
        newpixel = media.get_pixel(newpic, x_coordinate, y_coordinate)
        
        # Add the appropriate fraction of this Pixel's colour components
        # to the components of the corresponding Pixel in the new Picture.
        new_red = newpixel.get_red() + pixel.get_red()/reducing_factor
        new_blue = newpixel.get_blue() + pixel.get_blue()/reducing_factor
        new_green = newpixel.get_green() + pixel.get_green()/reducing_factor
        media.set_red(newpixel, int(new_red))
        media.set_blue(newpixel, int(new_blue))
        media.set_green(newpixel, int(new_green))
        
    return newpic
示例#2
0
def maximize_red(pic):

    new_pic = media.copy(pic)
	
    for pix in new_pic:
        media.set_red(pix, 255)

    return new_pic
示例#3
0
def maximize_red(pic):

    new_pic = media.copy(pic)

    for pix in new_pic:
        media.set_red(pix, 255)

    return new_pic
示例#4
0
    def test_pixel_set_get_RGB(self):
        """Test setting and getting the red, green, and blue of a pixel."""

        pic = media.create_picture(WIDTH, HEIGHT)
        p = media.get_pixel(pic, WIDTH - 1, HEIGHT - 1)
        media.set_red(p, 1)
        self.assert_(media.get_red(p) == 1)
        media.set_green(p, 2)
        self.assert_(media.get_green(p) == 2)
        media.set_blue(p, 3)
        self.assert_(media.get_blue(p) == 3)
示例#5
0
    def test_pixel_set_get_RGB(self):
        """Test setting and getting the red, green, and blue of a pixel."""

        pic = media.create_picture(WIDTH, HEIGHT)
        p = media.get_pixel(pic, WIDTH - 1, HEIGHT - 1)
        media.set_red(p, 1)
        self.assert_(media.get_red(p) == 1)
        media.set_green(p, 2)
        self.assert_(media.get_green(p) == 2)
        media.set_blue(p, 3)
        self.assert_(media.get_blue(p) == 3)
def scale_red(pic, new_red_average):
    ''' Take the Picture pic and set the average value of all red pixels in    
        the picture to the Integer new_average. Return scaled picture.
        Assume that the picture will have some colour component in it'''  
    
    old_average = float(red_average(pic))
    
    for pixel in pic:        
        new_red = (new_red_average / old_average) * media.get_red(pixel)
        if new_red > 255:
            new_red = 255
        media.set_red(pixel, int(new_red))
    
    return pic
示例#7
0
def reduce_width(pic, factor):
    '''Create a new picture newpic that has a reduced width of pic by a 
    factor of factor.'''
      
    new_height = pic.get_height()
    new_width = (pic.get_width() + factor - 1) / factor
    newpic = media.create_picture(new_width, new_height, media.black)
    
    for pixel in pic:
        x = media.get_x(pixel)
        y = media.get_y(pixel)
        newpixel = media.get_pixel(newpic, x/factor, y)
        new_red = newpixel.get_red() + pixel.get_red()/factor
        new_blue = newpixel.get_blue() + pixel.get_blue()/factor
        new_green = newpixel.get_green() + pixel.get_green()/factor
        media.set_red(newpixel, new_red)
        media.set_blue(newpixel, new_blue)
        media.set_green(newpixel, new_green)
        
    return newpic
示例#8
0
def expand_width(pic, expand_factor):
    '''Create a new picture new_pic that has an expanded width of pic by a 
     factor of expand_factor.'''
     
    height = media.get_height(pic)
    width = expand_factor * media.get_width(pic)
    new_pic = media.create_picture(width, height, media.black) 
    
    for pixel in new_pic:
        x = media.get_x(pixel)
        y = media.get_y(pixel)
        new_pixel = media.get_pixel(pic, x / expand_factor, y )
        new_red = new_pixel.get_red() + pixel.get_red() 
        new_blue = new_pixel.get_blue() + pixel.get_blue() 
        new_green = new_pixel.get_green() + pixel.get_green() 
        media.set_red(pixel, new_red)
        media.set_blue(pixel, new_blue)
        media.set_green(pixel, new_green)
        
    return new_pic
示例#9
0
def scale_red(pic, new_red):
    '''Set the average red of a Picture pic to a new average new_red'''
    
    average_red = red_average(pic)
    pixel_ratio = float(new_red)/ average_red
    
    for pixel in pic:
        red = media.get_red(pixel)
        target_red = pixel_ratio * red
        if target_red > 255.0:
            target_red = 255
        change_red = media.set_red(pixel, int(target_red))
示例#10
0
import media
f = media.choose_file()
pic = media.load_picture(f)
for p in media.get_pixels(pic):
    media.set_red(p,0)

media.show(pic)
# -*- coding: utf-8 -*-

import media

pic = media.load_picture(media.choose_file())

for p in media.get_pixels(pic):
    new_red = int(2 * media.get_red(p))
    media.set_red(p, new_red)

media.show(pic)
示例#12
0
import media
f = media.choose_file()
pic = media.load_picture(f)
for p in media.get_pixels(pic):
    r = media.get_red(p)
    g = media.get_green(p)
    b = media.get_blue(p)
    gray = (g + b + r ) / 3
    media.set_green(gray)
    media.set_blue(gray)
    media.set_red(gray)
示例#13
0
import media
f = media.choose_file()
pic = media.load_picture(f)
for p in media.get_pixels(pic):
    r = media.get_red(p)
    media.set_red(2*r)

media.show(pic)