def distance(Pixel_1, Pixel_2):
    ''' Return an integer value indicating the difference between the two 
        pixels Pixel_1 and Pixel_2)'''
    
    #find the difference b/w values of pixel 2 and pixel 1 and sum the 
    #difference of R, G and B, then return the total diff.
    distance_red = abs(media.get_red(Pixel_1) - media.get_red(Pixel_2))
    distance_green = abs(media.get_green(Pixel_1) - media.get_green(Pixel_2))
    distance_blue = abs(media.get_blue(Pixel_1) - media.get_blue(Pixel_2))
     
    distance_total = distance_red + distance_green + distance_blue
    return distance_total
Ejemplo n.º 2
0
def overlay_color(pix1, pix2):
    '''(Pix1, Pix2) -> Color
    Return a new color made up of 80% of the color values of the first pixel 
    and 20% of the color values of the second pixel.'''

    r1 = int(media.get_red(pix1))
    r2 = int(media.get_red(pix2))
    g1 = int(media.get_green(pix1))
    g2 = int(media.get_green(pix2))
    b1 = int(media.get_blue(pix1))
    b2 = int(media.get_blue(pix2))

    red = (r1 * 0.8) + (r2 * 0.2)
    green = (g1 * 0.8) + (g2 * 0.2)
    blue = (b1 * 0.8) + (b2 * 0.2)
    return media.create_color(red, green, blue)
Ejemplo n.º 3
0
Archivo: a1.py Proyecto: Zhaeong/School
def overlay_color(pix1, pix2):
    '''(Pix1, Pix2) -> Color
    Return a new color made up of 80% of the color values of the first pixel 
    and 20% of the color values of the second pixel.'''
    
    r1 = int(media.get_red(pix1))
    r2 = int(media.get_red(pix2))
    g1 = int(media.get_green(pix1))
    g2 = int(media.get_green(pix2))
    b1 = int(media.get_blue(pix1))
    b2 = int(media.get_blue(pix2))

    red   = (r1 * 0.8) + (r2 * 0.2)
    green = (g1 * 0.8) + (g2 * 0.2)
    blue  = (b1 * 0.8) + (b2 * 0.2)
    return media.create_color(red, green, blue)
Ejemplo n.º 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)
Ejemplo 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)
Ejemplo n.º 6
0
Archivo: e1.py Proyecto: 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
Ejemplo n.º 7
0
Archivo: e1.py Proyecto: 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
Ejemplo n.º 8
0
def scale_green(pic, new_green):
    '''Set the average green of a Picture pic to a new average new_green'''
    
    average_green = green_average(pic)
    pixel_ratio = float(new_green) / average_green
    
    for pixel in pic:
        green = media.get_green(pixel)
        target_green = pixel_ratio * green
        if target_green > 255.0:
            target_green = 255
        change_green = media.set_green(pixel, int(target_green))
def scale_green(pic, new_green_average):
    ''' Take the Picture pic and set the average value of all green pixels in    
        the picture to the Integer new_green_average. Return scaled picture
        Assume that the picture will have some colour component in it'''
   
    old_average = float(green_average(pic))
    
    for pixel in pic:        
        new_green = (new_green_average * media.get_green(pixel)) / old_average
        if new_green > 255:
            new_green = 255
        media.set_green(pixel, int(new_green))
    
    return pic
Ejemplo n.º 10
0
def green_average(pic):
    '''Returns the average green value of the entire Picture pic as an int.'''
    
    sum_green = 0
    height = media.get_height(pic)
    width = media.get_width(pic)
    total_pixel = height * width
    
    for pixel in pic:
        green = media.get_green(pixel)
        sum_green += green
    
    average = sum_green / total_pixel
    return int(average)
def chromakey(person, background):
    '''Replace blue pixels in the person picture with the corresponding
    pixels in the background picture. The pictures must have the same
    dimensions.'''

    for pixel in person:

        # If the blue dominates the pixel, replace its colour with the colour of
        # the corresponding pixel from the background picture.
        if media.get_blue(pixel) > media.get_green(pixel) and \
                media.get_blue(pixel) > media.get_red(pixel):
            x = media.get_x(pixel)
            y = media.get_y(pixel)
            background_px = media.get_pixel(background, x, y)
            media.set_color(pixel, media.get_color(background_px))
Ejemplo n.º 12
0
def green_average(pic):
    ''' Return an average green value of all the pixels in the Picture pic as an 
        integer. Truncate the result if the average calculation yields
        a non-integer value.'''
    
    sum_green = 0
    total_pix = 0
    
    for pixel in pic:
        
        sum_green += media.get_green(pixel)
        total_pix += 1
    
    average_green = (sum_green/total_pix)
    return average_green
Ejemplo n.º 13
0
import media
import random

# make a new 100 by 100 picture
pic = media.create_picture(100, 100)

# get 2 random numbers between 0 and 99 to use as coordinates
x = random.randint(0, 99)
y = random.randint(0, 99)

# get the pixel at this x,y coordinate
pix = media.get_pixel(pic, x, y)

# get the red, blue and green values of this pixel   
red = media.get_red(pix)
green = media.get_green(pix)
blue = media.get_blue(pix)

# introduce a new colour
new_color = media.orange

# make a 10 x 10 rectangle of the new colour inside our 
# picture, starting with our x and y as the upper 
# left corner. (In this case, it doesn't matter if some
# of the rectangle is outside the picture, as long as 
# the x,y corner is inside.)
media.add_rect_filled(pic, x, y, 10, 10, new_color)

# display the picture
media.show(pic)
Ejemplo n.º 14
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)
Ejemplo n.º 15
0
import media
f = media.choose_file()
pic = media.load_picture(f)
for p in media.get_pixels(pic):
    media.set_green(p,media.get_green(p)/2)

meida.show(pic)
Ejemplo n.º 16
0
import media
import random

# make a new 100 by 100 picture
pic = media.create_picture(100, 100)

# get 2 random numbers between 0 and 99 to use as coordinates
x = random.randint(0, 99)
y = random.randint(0, 99)

# get the pixel at this x,y coordinate
pix = media.get_pixel(pic, x, y)

# get the red, blue and green values of this pixel
red = media.get_red(pix)
green = media.get_green(pix)
blue = media.get_blue(pix)

# introduce a new colour
new_color = media.orange

# make a 10 x 10 rectangle of the new colour inside our
# picture, starting with our x and y as the upper
# left corner. (In this case, it doesn't matter if some
# of the rectangle is outside the picture, as long as
# the x,y corner is inside.)
media.add_rect_filled(pic, x, y, 10, 10, new_color)

# display the picture
media.show(pic)
Ejemplo n.º 17
0
    '''Test function for above_freezing.'''
    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
Ejemplo n.º 18
0
# -*- coding: utf-8 -*-

import media

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

for p in media.get_pixels(pic):
    new_green = int(0.5 * media.get_green(p))
    media.set_green(p, new_green)

media.show(pic)
Ejemplo n.º 19
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)