from cImage import* #Look up online a description of how to make a…
Question Answered step-by-step from cImage import* #Look up online a description of how to make a… from cImage import*#Look up online a description of how to make a picture sepia toned#Sepia toned images are often associated with photos from the 1800’sdef sepiaPixel(p): pass#This routine should just return a black pixel if the original avg RGB#is less than 128, white pixel otherwisedef blackAndWhite(p): threshold=128 pass#Turns a pixel from color to gray approximationdef grayPixel(p): nc=(p.getRed()+p.getGreen()+p.getBlue())//3 return Pixel(nc,nc,nc)#Turns a pixel into the photographic negative of itdef negativePixel(p): r=255-p.getRed() g=255-p.getGreen() b=255-p.getBlue() return Pixel(r,g,b)#e.g. percentage 1.2 increases RG & B by 20%, but never let a component color exceed 255# percentage .7 should decrease RG & B by 30%def RGBAdjust(p,percentage): pass#This function should reduce the image to 1/4 the original number of pixelsdef halfSize(oldImage): oldWidth=oldImage.getWidth() oldHeight=oldImage.getHeight() myImageWindow = ImageWin(“Half-size”, oldWidth*1.5, oldHeight) oldImage.draw(myImageWindow) halfImage=EmptyImage(oldWidth//2,oldHeight//2) for y in range(oldHeight//2): for x in range(oldWidth//2): avgRed=(oldImage.getPixel(x*2,y*2).getRed()+oldImage.getPixel(x*2+1,y*2).getRed()+oldImage.getPixel(x*2,y*2+1).getRed()+oldImage.getPixel(x*2+1,y*2+1).getRed())//4 avgGreen=(oldImage.getPixel(x*2,y*2).getGreen()+oldImage.getPixel(x*2+1,y*2).getGreen()+oldImage.getPixel(x*2,y*2+1).getGreen()+oldImage.getPixel(x*2+1,y*2+1).getGreen())//4 avgBlue=(oldImage.getPixel(x*2,y*2).getBlue()+oldImage.getPixel(x*2+1,y*2).getBlue()+oldImage.getPixel(x*2,y*2+1).getBlue()+oldImage.getPixel(x*2+1,y*2+1).getBlue())//4 pixel=Pixel(avgRed,avgGreen,avgBlue) halfImage.setPixel(x,y,pixel) halfImage.setPosition(oldWidth + 1, 0) halfImage.draw(myImageWindow) myImageWindow.exitOnClick() #A function which can be used to show old and new image side by side#Only works with rgbfunctions that take a single argumentdef pixelMapper(rgbFunction,oldImage,title): width = oldImage.getWidth() height = oldImage.getHeight() myImageWindow = ImageWin(title, width*2, height) oldImage.draw(myImageWindow) newIm = EmptyImage(width,height) for row in range(height): for col in range(width): originalPixel = oldImage.getPixel(col,row) newPixel = rgbFunction(originalPixel) newIm.setPixel(col,row,newPixel) newIm.setPosition(width + 1, 0) newIm.draw(myImageWindow) myImageWindow.exitOnClick()#Main routinedef imageProc(fname): if fname!=””: myImage=FileImage(fname) else: myImage=”” answer=0 while answer != 8: if myImage !=””: print(“1) Load an imagen2) Adjust RGB valuesn3) Produce a gray-scale image of the current imagen4) Produce a black and white of the current imagen5) Produce a sepia-toned image of the current imagen6) Produce a negative of the current imagen7) Reduce image size by 1/2 (1/4 the original pixels)n8) Exit”) answer=int(input(“Select a menu choice => “)) while answer not in [1,2,3,4,5,6,7,8]: print(“1) Load an imagen2) Adjust overall intensity by specified %n3) Produce a gray-scale image of the current imagen4) Produce a black and white of the current imagen5) Produce a sepia-toned image of the current imagen6) Produce a negative of the current imagen7) Reduce image size by 1/2 (1/4 the original pixels)n8) Exit”) answer=int(input(“Select a menu choice => “)) else: #the default image is not present print(“1) Load an imagen8) Exit”) answer=int(input(“Select a menu choice => “)) while answer not in [1,8]: print(“1) Load an imagen8) Exit”) answer=int(input(“Select a menu choice => “)) if answer==1: pass #Your code here elif answer==2: pass #Your code here elif answer==3: newImage=pixelMapper(grayPixel,myImage,”Grayscale Image”) elif answer==4: pass #Your code here elif answer==5: pass #Your code here elif answer==6: newImage=pixelMapper(negativePixel,myImage,”Negative Image”) elif answer==7: newImage=halfSize(myImage) elif answer==8: pass #Your code here imageProc(“stmarks.gif”)#imageProc(“”) Computer Science Engineering & Technology Python Programming CSE 200 Share QuestionEmailCopy link Comments (0)


