Start New Discussion within our Software Development Community

Using the following code as a foundation (it reddens the upper left corner of an image), I was told to create 2 different programs: one that would brighten the entire image, and one that would convert the entire image to grayscale. I need major help with this. Here's the code I was given to edit:

#!/usr/bin/python

import os
import sys
from PIL import Image

#----------------------
# Function redden: adds red to the upper left 1/4 of image
# - input: inPic is the input image (not modified)
# - output: outPic is the inPic copied and modified
#----------------------
def redden(inPic,outPic):
   xmax = inPic.size[0]
   ymax = inPic.size[1]
   for x in range(0,xmax):
      for y in range(0,ymax):
         p = inPic.getpixel((x,y))
         if x < xmax/2 and y < ymax/2:
            pnew = (p[0]+100,p[1],p[2])
         else:
            pnew = p
         outPic.putpixel((x,y),pnew)

#----------------------
# Main program
#----------------------

# open image file that is given on command line
print "Opening image " + sys.argv[1]
inPic = Image.open(sys.argv[1])

# create output image, and an output filename
outPic = Image.new("RGB",inPic.size)
outParts = os.path.splitext(sys.argv[1])
outName = outParts[0] + '-red' + outParts[1]
print "Will create output image " + outName

# do the reddening operation (call the function!)
print "Reddening some portion..."
redden(inPic,outPic)

# save and display the result
print "Saving " + outName + "..."
outPic.save(outName)
print "Displaying..."
outPic.show()
print "Done!"

Sorry you never received help on this, but what have you tried so far? I take it the assignment was due by now?

This article has been dead for over six months. Start a new discussion instead.