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
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
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
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
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
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) '''
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')
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' )
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')
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") '''
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' )