Traceback (most recent call last):
File "/Users/j1/Desktop/COMP480/Week 11/imageMaster.py", line 157, in <module>
main()
File "/Users/j1/Desktop/COMP480/Week 11/imageMaster.py", line 128, in main
im = Image.open('/Users/j1/Desktop/COMP480/Week 11/hw7pics/pie.jpg')
NameError: global name 'Image' is not defined
Here is what my code looks like:
#!/usr/bin/env python
# starter program for image manipulation program
#
# written by e.bonakdarian nov 2009
# updated mar 2010
#
from imageMaster import *
# choices
DIAGONAL = 1
STRIPE_HORIZ = 2
STRIPE_VERTICAL = 3
COLOR_BLUE = 4
REVERSE_DIAGONAL = 5
#####################################################
def Diag(img, pixel_color):
# put a diagonal line across the image in the
# specified color
#
# *** ALREADY WORKING - PLEASE DO NOT MODIFY ***
pix_ar = img.load() # load image into 2D array
cols = img.size[0] # number of columns
rows = img.size[1] # number of rows
for row in range(rows): # our nested loop
for col in range(cols):
if row == col:
pix_ar[col, row] = pixel_color
#####################################################
def Reverse_Diag(img, pixel_color):
# put a reverse diagonal line across the image in
# the specified color (OPTIONAL for extra credit)
pix_ar = img.load() # load image into 2D array
cols = img.size[0] # number of columns
rows = img.size[1] # number of rows
print 'not finished'
#####################################################
def Stripe_H(img, pixel_color):
# put a line in the specified color across the
# image every other line.
pix_ar = img.load() # load image into 2D array
cols = img.size[0] # number of columns
rows = img.size[1] # number of rows
print 'not finished'
#####################################################
def Stripe_V(img, pixel_color):
# put a line in the specified color down the
# image every other line.
pix_ar = img.load() # load image into 2D array
cols = img.size[0] # number of columns
rows = img.size[1] # number of rows
print 'not finished'
#####################################################
def ColorIt_Blue(img):
# set all the pixels to red
pix_ar = img.load() # load image into 2D array
cols = img.size[0] # number of columns
rows = img.size[1] # number of rows
print 'not finished'
#######################################################
def display_menu():
# displays the menu, and returns the user selection
print '\t========================================='
print '\tMenu'
print '\t========================================='
print '\t1) Diagonal line' #done for you
print '\t2) Stripe vertical (every other column)'
print '\t3) Stripe horizontal (every other row)'
print '\t4) Color image solid blue'
print '\t5) Reverse diagonal line (optional)' # optional for extra credit
print '\t========================================='
print '\t0) Quit'
selection = input('\n\tEnter your choice: ')
return selection
#######################################################
def main():
# our main program
choice = display_menu()
if choice == 0:
print 'Quitting program.'
else:
#load image
im = Image.open('/Users/j1/Desktop/COMP480/Week 11/hw7pics/pie.jpg')
pixel_color = 255, 0, 0 # red RGB pixel
if choice == DIAGONAL:
Diag(im, pixel_color)
elif choice == STRIPE_HORIZ:
Stripe_H(im, pixel_color)
elif choice == STRIPE_VERTICAL:
Stripe_V(im, pixel_color)
elif choice == COLOR_BLUE:
ColorIt_Blue(im)
elif choice == REVERSE_DIAGONAL:
Reverse_Diag(im, pixel_color)
else:
print 'Error: Unknown choice: ', choice
im.show()
if __name__ == '__main__':
main()
Any help is greatly appreciated!
This post has been edited by j1_osu2002: 06 April 2010 - 06:05 AM

New Topic/Question
Reply




MultiQuote




|