コード例 #1
0
def main(argv):
    if len(argv) < 3:
        print 'Usage: testpixmap.py <ppm image 1> <ppm image 2>'
        print '\n       Reads in the two images and builds a collage'
        print '       with the second image overlapping the first '
        print '       using an alpha blend of 0.5'
        print '\n       The output image is called tpixmap.ppm'
        print
        exit()

    # read both images
    srcA = graphics.Pixmap(argv[1])
    srcB = graphics.Pixmap(argv[2])

    # get the maximum height of the two images
    rows = srcA.getHeight()
    if srcB.getHeight() > rows:
        rows = srcB.getHeight()

    # make the columns big enough
    cols = srcA.getWidth() / 2 + srcB.getWidth()

    # create the background canvas
    dst = graphics.Pixmap(cols, rows)

    # put both images into the canvas
    filter.placePixmap(dst, srcA, 0, 0, 1.0)
    filter.placePixmap(dst, srcB, srcA.getWidth() / 2, 0, 0.5)

    # write out the canvas
    dst.save('tpixmap.ppm')

    return
コード例 #2
0
def test(argv):

    # test if the user provided a filename
    if len(argv) < 2:
        print 'usage: %s <image filename>' % (argv[0])
        exit()

    filename = argv[1]

    # see if we can open the file
    try:
        srcImage = graphics.Pixmap(filename)
    except:
        print 'error: unable to open file %s' % (filename)
        exit()

    # create a new empty image that is the same height and twice as wide
    dstImage = graphics.Pixmap(srcImage.getWidth() * 2, srcImage.getHeight())

    # place the original image into the empty image in two places
    filter.placePixmap(dstImage, srcImage, 0, 0)
    filter.placePixmap(dstImage, srcImage, srcImage.getWidth(), 0)

    # save the new image to the file duplicate.ppm
    dstImage.save('duplicate.ppm')

    return
コード例 #3
0
def main(argv):
	if len(argv) <2:
		print "Usage: python show.py <filename>"
		exit()
		
	filename = argv[1]
	filename2 = argv[2]
	
# define pmap as one pixmap
	me = graphics.Pixmap( filename )
	monster = graphics.Pixmap( filename2 )
	'''read in one pixmap'''
	
# makes eight copies of pixmap
	'''makes 8 copies'''
	map1 = me.clone()
	map2 = monster.clone()
	map3 = me.clone()
	map4 = monster.clone()
	map5 = me.clone()
	map6 = monster.clone()
	map7 = me.clone()
	map8 = monster.clone()


# filters for each separate square of extension picture
	'''each picture gets separate filter from task 2'''
	filter.swapRedBlue(map1)
	filter.moreGreen(map2)
	filter.purpleHaze(map3)
	filter.colorNegative(map4)
	filter.swapRedBlue(map6)
	filter.moreGreen(map7)
	filter.purpleHaze(map8)
	filter.colorNegative(map5)

# defines variable name for larger Pixmap
	extension1 = graphics.Pixmap(4*me.getWidth(), 2*me.getHeight())
	'''make an empty pixmap big enough to hold 4 copies of this one'''
	
# places the eight images at different locations 
# into the 'extension1' pixmap
# each of the eight images gets a different filter
	filter.placePixmap( extension1, map2, 0, 0 )
	'''put the 4 filtered images into the big one'''
	filter.placePixmap( extension1, map1, me.getWidth(), 0 )
	filter.placePixmap( extension1, map4, 2*me.getWidth(), 0 )
	filter.placePixmap( extension1, map3, 3*me.getWidth(), 0 )
	filter.placePixmap( extension1, map5, 0, me.getHeight() )
	filter.placePixmap( extension1, map6, me.getWidth(), me.getHeight() )
	filter.placePixmap( extension1, map7, 2*me.getWidth(), me.getHeight() )
	filter.placePixmap( extension1, map8, 3*me.getWidth(), me.getHeight() )

	
# save the resulting image as a file name 'extension1.py'
	extension1.save( 'extension1.ppm' )
コード例 #4
0
def main(argv):
    if len(argv) < 2:
        print "Usage : GreenScreenPic.py filename"
        exit()

    file = argv[1]
    pm = graphics.Pixmap(file)
    source = graphics.Pixmap(file)
    dest = graphics.Pixmap('OceanBackground.ppm')
    placePixmapinOcean(dest, source)
    dest.save('MeInOcean.ppm')
コード例 #5
0
def main( argv ):
	if len(argv)<2:
		print "Usage : GreenScreenPic.py filename"
		exit()
		
	file = argv[1]
	pm = graphics.Pixmap( file )
	source=graphics.Pixmap( file ) 
	dest=graphics.Pixmap('WoodsScene.ppm')
	placePixmapinOcean(dest,source)
	dest.save('PhrasantInOcean.ppm')
コード例 #6
0
def main(argv):
    if len(argv) < 2:
        print "Usage: python show.py <filename>"
        exit()
    monster = graphics.Pixmap('biggodzilla.ppm')
    me = graphics.Pixmap('me.ppm')
    '''read in one pixmap'''

    extension3 = graphics.Pixmap(monster.getWidth(), monster.getHeight())

    filter.placePixmap(extension3, monster, 0, 0)
    placeNoGreenPixmap(extension3, me, 0, 0)

    # save the resulting image as a file name 'extension3.py'
    extension3.save('extension3.ppm')
コード例 #7
0
def buildCollage( clist ):
	'''builds collage with input image lists
		with different filters, alpha values and locations'''
	(cols, rows) = getImageSize(clist)
	dst = graphics.Pixmap(cols, rows)
	for item in clist:
		filename = item[0]
		x0 = item[1]
		y0 = item[2]
		operator = item[3]
		alpha = item[4]
		noBkg = item[5]
		src = item[-1]
		if operator == 'swapRedBlue':
			filter.swapRedBlue(src)
		elif operator == 'colorNegative':
			filter.colorNegative(src)
		elif operator == 'purpleHaze':
			filter.purpleHaze(src)
		elif operator == 'moreGreen':
			filter.moreGreen(src)
		'''now considers boolean value of NoBkg
			and removes background if true'''
		if noBkg == True:
			filter.placePixmapNoBkg(dst, src, x0, y0, alpha)
		else:
			filter.placePixmap(dst, src, x0, y0, alpha)
		
	return dst
コード例 #8
0
def greenscreen(argv):
    ''' we want to remove green from green screen '''

    if len(argv) < 2:
        print "Usage: python show.py <filename>"
        exit()

    pm = graphics.Pixmap('me.ppm')
    w = pm.getWidth()
    h = pm.getHeight()

    # this will loop through pixels and
    # find all super green pixels
    # and changed their color
    for i in range(w):
        for j in range(h):
            (r, g, b) = pm.getPixel(i, j)
            if g > r and g > b:
                pm.setPixel(i, j, (0.5 * r, 0, 0.7 * b))
                '''gets rid of all the green in the pixels
					it has scanned through'''

    filename = argv[1]

    pm.save('newme.ppm')
コード例 #9
0
def main(argv):
    if len(argv) < 2:
        print "Usage : show.py filename"
        exit()

    file = argv[1]
    pm = graphics.Pixmap(file)
    warhol(file)
コード例 #10
0
def main(argv):
    if len(argv) < 2:
        print "Usage : GreenScreenPic.py filename"
        exit()

    file = argv[1]
    pm = graphics.Pixmap(file)
    changeVeryGreen(pm)
コード例 #11
0
ファイル: collage.py プロジェクト: btroisi/PythonProjects
def readImages( clist ):
	'''
	This reads all of the images defined in clist. 
	'''
	for picParams in clist:
		filename=picParams[IDXFilename]
		source=graphics.Pixmap(filename)
		picParams[IDXPixmap]=source
コード例 #12
0
ファイル: filter.py プロジェクト: btroisi/PythonProjects
def test(argv):
    '''
	This tells python to only save negative image
	'''
    if len(argv) < 2:
        print "Usage : show.py filename"
        exit()

    file = argv[1]
    pm = graphics.Pixmap(file)
    reversepixels(pm)
コード例 #13
0
ファイル: collage.py プロジェクト: btroisi/PythonProjects
def buildCollage( clist ):
	'''
	This is what builds a collage with any ppm picture saved in the project 5 folder. 
	In the collage you can make it as big as you want, apply any filter you want, move 
	each image to a certain position in the collage, and use the alpha blend feature
	to blend pictures together any way you want. 
	'''
	(cols, rows) = getImageSize( clist )
	dest = graphics.Pixmap(cols,rows)
	for picParams in clist:
		filename=picParams[IDXFilename]
		x0=picParams[IDXXoffset]
		y0=picParams[IDXYoffset]
		filter=picParams[IDXeffect]
		alpha=picParams[IDXalpha]
		noBkg=picParams[IDXNoBkg]
		source=picParams[IDXPixmap]
	
	'''
	This assigns the filename to the first element of each inner list in clist, 
	the x offset of the image to the second, y offset of the image to the third, 
	the filter effect to the fourth, alpha blend to the fifth,
	wether to remove the background to the sixth, and pixmap source after image
	is read to the seventh. 
	'''	
		
		
		if filter == 'swapRedBlue':
			filter.swapRedBlue(source)
		elif operator == 'grayscale':
			filter.grayscale(source)
		elif filter == 'quarterBlueHalfGreen':
			filter.quarterBlueHalfGreen(source)
		elif filter == 'swapBluetoYellowRedtoPurple':
			filter.swapBluetoYellowRedtoPurple(source)
		elif filter == 'negative':
			filter.negative(source)
		elif filter == 'mirrorhoriz':
			filter.mirrorhoriz(source)
		elif filter == 'mirrorvert':
			filter.mirrorvert(source)
		elif filter == 'reversepixels':
			filter.reversepixels(source)
		'''
		These series of if statemtents are what applies a certain filter to a certain type
		of
		'''
		
		if noBkg == True:
			filter.placePixmapNoBkg(dest,source,x0,y0,alpha,'blue')
		else:	
			filter.placePixmap(dest,source,x0,y0,alpha)

		'''
コード例 #14
0
def test(argv):
    '''
	This tells python to only save grayscale image
	'''
    if len(argv) < 2:
        print "Usage : show.py filename"
        exit()

    file = argv[1]
    pm = graphics.Pixmap(file)
    grayscale(pm)
コード例 #15
0
def main(argv):
    if len(argv) < 2:
        print "Usage : show.py filename"
        exit()

    file = argv[1]
    pm = graphics.Pixmap(file)

    print pm.getHeight(), ", ", pm.getWidth()

    wn = display.displayPixmap(pm, file)
    wn.getMouse()
コード例 #16
0
ファイル: warhol.py プロジェクト: akaralekas/cs151-colby
def main(argv):
    if len(argv) < 2:
        print "Usage: python show.py <filename>"
        exit()

    filename = argv[1]

    # define pmap as one pixmap
    pmap = graphics.Pixmap(filename)
    '''read in one pixmap'''

    # makes four copies of pixmap
    '''makes 4 copies'''
    map1 = pmap.clone()
    map2 = pmap.clone()
    map3 = pmap.clone()
    map4 = pmap.clone()

    # filters for each separate square of warhol picture
    '''each picture gets separate filter from task 2'''
    filter.swapRedBlue(map1)
    filter.colorNegative(map2)
    filter.moreGreen(map3)
    filter.purpleHaze(map4)

    # defines variable name for twice as large Pixmap
    big = graphics.Pixmap(2 * pmap.getWidth(), 2 * pmap.getHeight())
    '''make an empty pixmap big enough to hold 4 copies of this one'''

    # places the four images at different locations
    # into the 'big' pixmap
    # each of the four images gets a different filter
    filter.placePixmap(big, map1, 0, 0)
    '''put the 4 filtered images into the big one'''
    filter.placePixmap(big, map2, 0, pmap.getHeight())
    filter.placePixmap(big, map3, pmap.getWidth(), 0)
    filter.placePixmap(big, map4, pmap.getWidth(), pmap.getHeight())

    # save the resulting image as a file name 'warhol.py'
    big.save('warhol.ppm')
コード例 #17
0
def warhol(file):
    '''
	This creates a warhol style collage that saves four images of a lake in different
	filter effects. The filter effecs are the ones defined in the filter file.
	'''

    pmap = graphics.Pixmap(file)  #image read in one pixmap
    map1 = pmap.clone()  #makes four copies of it
    map2 = pmap.clone()
    map3 = pmap.clone()
    map4 = pmap.clone()

    filter.swapRedBlue(map1)
    filter.grayscale(map2)
    filter.quarterBlueHalfGreen(map3)
    filter.swapBluetoYellowRedtoPurple(map4)
    '''
	Sets each clone to different filter.
	'''

    source = graphics.Pixmap(file)
    dest = graphics.Pixmap(
        graphics.Pixmap.getWidth(source) * 2,
        graphics.Pixmap.getHeight(source) * 2)

    filter.placePixmap(dest, map1, 0, 0)
    filter.placePixmap(dest, map2, 0, graphics.Pixmap.getHeight(source))
    filter.placePixmap(dest, map3, graphics.Pixmap.getWidth(source), 0)
    filter.placePixmap(dest, map4, graphics.Pixmap.getWidth(source),
                       graphics.Pixmap.getHeight(source))
    '''
	Sets filtered pixmap to different positions on second pixmap created by
	placePixmap function. 
	'''

    dest.save("Bigfile.ppm")
    '''
コード例 #18
0
ファイル: filter.py プロジェクト: akaralekas/cs151-colby
def main(argv):
    ''' reads in an image file and displays it in a window '''

    if len(argv) < 2:
        print "Usage: python show.py <filename>"
        exit()

    filename = argv[1]

    dst = graphics.Pixmap(filename)

    purpleHaze(dst)
    '''change this filter function to test out other filters'''

    win = display.displayPixmap(dst, filename)

    win.getMouse()
コード例 #19
0
ファイル: show.py プロジェクト: akaralekas/cs151-colby
def main(argv):
    ''' reads in an image file and displays it in a window '''

    if len(argv) < 2:
        print "Usage: python show.py <filename>"
        exit()

    filename = argv[1]

    pixm = graphics.Pixmap(filename)

    # put a little test code
    # (r, g, b) = pixm.getPixel( 42, 35 )
    #print "color:", r, g, b
    #pixm.setPixel( 42, 35, (b,g,r) )

    win = display.displayPixmap(pixm, filename)

    win.getMouse()
コード例 #20
0
def greenscreen(argv):
	''' reads in an image file and displays it in a window '''
	
	if len(argv) < 2:
		print "Usage: python show.py <filename>"
		exit()
	
	pm = graphics.Pixmap( 'me.ppm' )
	w= pm.getWidth()
	h = pm.getHeight()
	# splits the pixmap into four separate corners
	# using four for loops with different coordinate ranges
	for i in range(w/2):
		for j in range(h/2):
			'''this one for example, takes the corner of the
				pixmap that has a width/2 and a height/2'''
			(r, g, b) = pm.getPixel( i, j )
			if g > r and g > b:
				pm.setPixel( i, j, (0.5*r, 0, 0.7*b) )
	for i in range(w/2):
		for j in range(h):
			(r, g, b) = pm.getPixel( i, j )
			if g > r and g > b:
				pm.setPixel( i, j, (0.25*r, 0, b) )
	for i in range(w):
		for j in range(h/2):
			(r, g, b) = pm.getPixel( i, j )
			if g > r and g > b:
				pm.setPixel( i, j, (0.75*r, 0, .25*b) )
	for i in range(w):
		for j in range(h):
			(r, g, b) = pm.getPixel( i, j )
			if g > r and g > b:
				pm.setPixel( i, j, (0.5*r, 0.7*g, 0.2*b) )
			
	filename = argv[1]
	
# save the resulting image as a file name 'extension2.py'
	pm.save( 'extension2.ppm' )
コード例 #21
0
def readImages(clist):
	for item in clist:
		filename = 	item[0]
		src = graphics.Pixmap( filename )
		item[-1] = src