예제 #1
0
파일: e1.py 프로젝트: Zhaeong/School
def same_dimensions():
    filename = media.choose_file()
    pic = media.load_picture(filename)
    filename2 = media.choose_file()
    pic2 = media.load_picture(filename2)

    h1 = media.get_height(pic)
    w1 = media.get_width(pic)
    h2 = media.get_height(pic2)
    w2 = media.get_width(pic2)
    if h1 == h2 and w1 == w2:
        print "true"
    else:
        print "false"
예제 #2
0
파일: e1.py 프로젝트: Zhaeong/School
def same_dimensions():
    filename = media.choose_file()
    pic = media.load_picture(filename)
    filename2 = media.choose_file()
    pic2 = media.load_picture(filename2)
    
    h1=media.get_height(pic)
    w1=media.get_width(pic)
    h2=media.get_height(pic2)
    w2=media.get_width(pic2)
    if h1==h2 and w1==w2:
        print "true"
    else:
        print "false"
예제 #3
0
def test_make_picture():
    """Test making picture from a valid file."""
    # ensure that this returns an identical picture from one created manually
    image_loc = resi('white.bmp')
    tester_pict = media.load_picture(image_loc)
    manual_tester_pict = Picture(filename=image_loc)
    ensure_pictures_equal(tester_pict, manual_tester_pict)
예제 #4
0
파일: label_image.py 프로젝트: idcxb/python
def open_pic(label):
    '''Prompt for a Picture file, load that picture, and display it in Label
    label.'''
    
     # Keep a reference to the picture so it can be modified.
    label.picture = media.load_picture(media.choose_file())
    update_label(label)
예제 #5
0
def test_make_picture():
    """Test making picture from a valid file."""
    # ensure that this returns an identical picture from one created manually
    image_loc = resi('white.bmp')
    tester_pict = media.load_picture(image_loc)
    manual_tester_pict = Picture(filename=image_loc)
    ensure_pictures_equal(tester_pict, manual_tester_pict)
예제 #6
0
def open_pic_GUI (label):
    '''Prompt for a Picture file, load that picture, and display it in Label
    label.'''
    #Clear all the temp pics in front of the current pic current_pic
    global temp_label
    global current_pic
    temp_label = temp_label[0:current_pic+1]
    #This function is based on label_image.py
    label.picture = media.load_picture(media.choose_file())
    #Keep a copy of the current pic for the functions Undo and Redo
    temp_label.append(label.picture)
    current_pic += 1
    #Update the label
    update_label(label)
예제 #7
0
def is_dinosaur(name):
    '''
    Return True if the named creature is recognized as a dinosaur,
    and False otherwise.
    '''
    return name in ['Tyrannosaurus', 'Triceratops']
if __name__ == '__main__':
    help(__name__)

 

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

 

 
...
----------------------------------------------------------------------
Ran 3 tests in 0.002s

OK

 

 
media.crop_picture(pic, 150, 50, 450, 300)
예제 #8
0
import media
f = media.choose_file()
pic = media.load_picture(f)
media.show(f)
media.show(f)
예제 #9
0
def loadPicture(filename):
    pic = media.load_picture(filename)
    return pic
예제 #10
0
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)
예제 #11
0
import media
pic=media.load_picture('i:\2.jpg')
media.show(pic)
import media

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.'''
    
    colour = media.get_color(media.get_pixel(person, 60, 60))
    for p in person:
		# 42 is a guess. Other values might work much better.
        if media.distance(media.get_color(p), colour) < 42:
            x = media.get_x(p)
            y = media.get_y(p)
            background_px = media.get_pixel(background, x, y)
            media.set_color(p, media.get_color(background_px))

if __name__ == '__main__':
    pic1 = media.load_picture(media.choose_file())
    #media.show(pic1)
    pic2 = media.load_picture(media.choose_file())
    #media.show(pic2)
    chromakey(pic1, pic2)
    media.show(pic1)
import media

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

pic2 = media.load_picture('piccrop_picture/pic207cropped.jpg')
media.show(pic2)
#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)
예제 #15
0
파일: a1.py 프로젝트: Zhaeong/School
    Return a new picture that contains the pixels of the original picture flipped across the vertical axis.'''
    
    copy  = media.copy(pic)
    max_x = media.get_width(pic)
    max_y = media.get_height(pic)
    
    for x in range(max_x/2):
        for y in range(max_y):
            originalpix = copy.get_pixel(x,y)
            reversepix  = copy.get_pixel((max_x - x - 1), y)
            color = media.get_color(originalpix)
            reversecolor = media.get_color(reversepix)
            media.set_color(originalpix,reversecolor)
            media.set_color(reversepix,color)
    return copy
    

        

    

if __name__ == "__main__":
    pic = media.create_picture(50, 50, media.red)
    pic.inspect()
    pic2 = media.create_picture(50, 50, media.blue)
    pic2.inspect()
    str1 = 'redundancy'
    str2 = 'redundancy'
    filename = media.choose_file()
    mypic = media.load_picture(filename)
예제 #16
0

def flip(pic):
    '''(Pic) -> Picture 
    Return a new picture that contains the pixels of the original picture flipped across the vertical axis.'''

    copy = media.copy(pic)
    max_x = media.get_width(pic)
    max_y = media.get_height(pic)

    for x in range(max_x / 2):
        for y in range(max_y):
            originalpix = copy.get_pixel(x, y)
            reversepix = copy.get_pixel((max_x - x - 1), y)
            color = media.get_color(originalpix)
            reversecolor = media.get_color(reversepix)
            media.set_color(originalpix, reversecolor)
            media.set_color(reversepix, color)
    return copy


if __name__ == "__main__":
    pic = media.create_picture(50, 50, media.red)
    pic.inspect()
    pic2 = media.create_picture(50, 50, media.blue)
    pic2.inspect()
    str1 = 'redundancy'
    str2 = 'redundancy'
    filename = media.choose_file()
    mypic = media.load_picture(filename)
예제 #17
0
import media

pic1 = media.load_picture('pic207.jpg')
media.show(pic1)
pic2 = media.load_picture('pic207cropped.jpg')
media.show(pic2)
pic3 = media.load_picture('pic207named.jpg')
media.show(pic3)
    width_shorter_pic = media.get_width(shorter_pic)
    
    if width_shorter_pic > width_pic_2:
        width_factor = width_shorter_pic / width_pic_2
        adjusted_pic = reduce_width(shorter_pic, width_factor)
    else:
        width_factor = width_pic_2 / width_shorter_pic
        adjusted_pic = expand_width(shorter_pic, width_factor)
    
    #scale the new pic we have based on the average colours of pic_2
    scale_red_to = red_average(pic_2)
    scale_green_to = green_average(pic_2)
    scale_blue_to = blue_average(pic_2)
    
    adjusted_pic = scale_red(adjusted_pic, scale_red_to)
    adjusted_pic = scale_green(adjusted_pic, scale_green_to)
    adjusted_pic = scale_blue(adjusted_pic, scale_blue_to)
    
    scale_red_to = red_average(adjusted_pic)
    scale_green_to = green_average(adjusted_pic)
    scale_blue_to = blue_average(adjusted_pic)
    
    #run simple_difference function between new pic and pic_2
    true_difference = simple_difference(adjusted_pic, pic_2)
    
    return true_difference

if __name__ == "__main__":
    a=media.load_picture("original.jpg")
    b=media.load_picture("mosaic.jpg")
    print smart_difference(a,b)
예제 #19
0
파일: sunset.py 프로젝트: rgamado/book_code
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)
예제 #20
0
파일: open_pic.py 프로젝트: chaubeau/Python
# -*- coding:utf-8 -*-
#
#  Date: 2014-03-20 18:01:09
#
#  Copyright 2014 chaubeau <*****@*****.**>
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
#  MA 02110-1301, USA.
#  Desc :
#

import media

f = media.choose_file()

pic = media.load_picture(f)

media.show(pic)
예제 #21
0
import media
lake = media.load_picture('lake.png')
width, height = media.get_width(lake), media.get_height(lake)
for y in range(0, height, 2): # Skip odd-numbered lines
    for x in range(0, width):
        p = media.get_pixel(lake, x, y)
        media.set_color(p, media.black)
media.show(lake)
예제 #22
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)
예제 #23
0
import media
baseball = media.load_picture('baseball.png')
lake = media.load_picture('lake.png')
width, height = media.get_width(baseball), media.get_height(baseball)

for y in range(0, height):
    for x in range(0, width):
        # Position the top-left of the baseball at (50, 25)
        from_p = media.get_pixel(baseball, x, y)
        to_p = media.get_pixel(lake, 50 + x, 25 + y)
        media.set_color(to_p, media.get_color(from_p))
media.show(lake)