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
Exemplo n.º 2
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)
Exemplo n.º 3
0
Arquivo: e1.py Projeto: Zhaeong/School
def moderate_blue(pic):
    new_pic=media.copy(pic)
    for pix in new_pic:
        red=media.get_red(pix)
        green=media.get_green(pix)
        red1=int(red)
        green1=int(green)
        modblue=(red1+green1)/2
        media.set_blue(pix, modblue)
        media.show(new_pic)
    return new_pic
Exemplo n.º 4
0
Arquivo: e1.py Projeto: Zhaeong/School
def moderate_blue(pic):
    new_pic = media.copy(pic)
    for pix in new_pic:
        red = media.get_red(pix)
        green = media.get_green(pix)
        red1 = int(red)
        green1 = int(green)
        modblue = (red1 + green1) / 2
        media.set_blue(pix, modblue)
        media.show(new_pic)
    return new_pic
Exemplo n.º 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_blue(pic, new_blue_average):
    ''' Take the Picture pic and set the average value of all blue pixels in    
        the picture to the Integer new_blue_average. Return scaled Picture 
        Assume that the picture will have some colour component in it'''
    
    old_average = float(blue_average(pic))
    
    for pixel in pic:        
        new_blue = (new_blue_average * media.get_blue(pixel)) / old_average 
        if new_blue > 255:
            new_blue = 255
        media.set_blue(pixel, int(new_blue))
    
    return pic
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 9
0
def scale_blue(pic, new_blue):
    '''Set the average blue of a Picture pic to a new average new_blue'''
    
    average_blue = blue_average(pic)
    pixel_ratio = float(new_blue) / average_blue
    
    for pixel in pic:
        blue = media.get_blue(pixel)
        target_blue = pixel_ratio * blue
        if target_blue > 255.0:
            target_blue = 255
        change_blue = media.set_blue(pixel, int(target_blue))
#encoding: utf8

import media

pic = media.load_picture('207.jpg')
media.show(pic)

for p in media.get_pixels(pic):
    new_blue = int(0.7 * media.get_blue(p))
    new_green = int(0.7 * media.get_green(p))
    media.set_blue(p, new_blue)
    media.set_green(p, new_green)

media.show(pic)
Exemplo n.º 11
0
    pass # we'll fill this in too

if __name__ == '__main__':
    nose.runmodule()

 

 
import media

pic = media.load_picture('pic207.jpg')
media.show(pic)
for p in media.get_pixels(pic):
    new_blue = int(0.7 * media.get_blue(p))
    new_green = int(0.7 * media.get_green(p))
    media.set_blue(p, new_blue)
    media.set_green(p, new_green)

media.show(pic)

 



 
def to_celsius(t):                        
    return (t - 32.0) * 5.0 / 9.0

def above_freezing(t):
    return t > 0
Exemplo n.º 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)
Exemplo n.º 13
0
import media

if __name__ == '__main__':

    filename = media.choose_file()
    pic = media.load_picture(filename)
    media.show(pic)
  
    # Reduce the blue and green by 30% each to make
    # the red stand out.
    for pixel in pic:
        value = media.get_blue(pixel)
        new_blue = int(value * 0.7)
        media.set_blue(pixel, new_blue)
        
        value = media.get_green(pixel)
        new_green = int(value * 0.7)
        media.set_green(pixel, new_green)
    
    media.show(pic)