2 Replies - 3025 Views - Last Post: 19 September 2011 - 10:48 AM Rate Topic: -----

#1 kkasp   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 12-September 11

Image module changing image from color to sepia

Posted 19 September 2011 - 09:57 AM

Hi, I am trying to convert a color image (smokey.gif) to grayscale and then to sepia.
The function is called sepia and it is supposed to call grayscale first.
Here is what I have so far, any suggestions?
import Image

def sepia (image, grayscale):
    if red < 63:
        red = int(red * 1.1)
        blue = int(blue * 0.9)  
    elif red < 192:
        red = int(red * 1.15)
        blue = int(blue * 0.85)
    else:
        red = min(int(red * 1.08), 255)
        blue = int(blue * 0.93)
        
def grayscale(image):
    for y in xrange(image.getHeight()):
        for x in xrange(image.getWidth()):
            (r, g, B)/> = image.getPixel(x, y)
            r = int(r * 0.299)
            g = int(g * 0.587)
            b = int(b * 0.114)
            lum = r + g + b
            image.setPixel(x, y, (lum, lum, lum))
    
def main(filename = "smokey.gif"):
    image = Image(smokey.gif)
    print "Close the image window to continue."
    image.draw()
    sepia(image)
    print "Close the image window to quit."
    image.draw()
main()



The error I am getting is
Traceback (most recent call last):
File "C:\Python27\7_8", line 40, in <module>
main()
File "C:\Python27\7_8", line 34, in main
image = Image(smokey.gif)
NameError: global name 'smokey' is not defined

which I am not sure why- I have the file smokey saved in my working directory.
Thanks in advance for any help.
Kkasp

Is This A Good Question/Topic? 0
  • +

Replies To: Image module changing image from color to sepia

#2 Motoma   User is offline

  • D.I.C Addict
  • member icon

Reputation: 452
  • View blog
  • Posts: 798
  • Joined: 08-June 10

Re: Image module changing image from color to sepia

Posted 19 September 2011 - 10:03 AM

On line 25, image = Image(smokey.gif).

You will need to encapsulate the file name in either quotes or apostrophes. More likely, you'll want to use the filename variable instead.
Was This Post Helpful? 0
  • +
  • -

#3 kkasp   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 12-September 11

Re: Image module changing image from color to sepia

Posted 19 September 2011 - 10:48 AM

thanks, that was a stupid mistake.... I am going to send to my prof and get his input also.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1