I am having trouble with this problem, I need to enhance the red intensity of each pixel
This is what i have

import cImage
def makeRedScale(imageFile):
    myImageWindow = ImageWin("Image Processing",600,300)
    oldImage = fileImage(imageFile)
    oldImage.draw(myImageWindow)
    width = oldImage.getWidth()
    height = oldImage.getHeight()
    newImage = emptyImage (width,height)
    for row in range(height):
        for col in range(width):
            originalPixel = oldImage.getPixel(col,row)
            newPixel = redPixel(originalPixel)
            newImage.setPixel (col,row,newPixel)
        newImage.setPosition(width + 1,0)
        newImage.draw(myImageWindow)
        myImageWindow.exitOnClick()
def redPixel(oldPixel):
     intensitySum = oldPixel.getRed() + oldPixel.getGreen() + \
                        oldPixel.getBlue()
     AveRGB = intensitySum//3
     newPixel = pixel(AveRGB,AveRGB,AveRGB)
     return newPixel

Can you give description of your algorithm for red_pixel function? You should change the capital letter words to underscore words if you are allowed (PEP 8 conventions). What is your problem and tell how have you tried to debug it. Give also exact error messages.

I changed some things but I am having trouble getting the gif file. This is my error
makeRedScale("horse.gif")
Traceback (most recent call last):
File "<pyshell#7>", line 1, in <module>
makeRedScale("horse.gif")
File "C:\Python31\redPixel.py", line 4, in makeRedScale
oldImage = cImage.FileImage(imageFile)
File "C:\Python31\lib\site-packages\cImage.py", line 398, in __init__
super(FileImage, self).__init__(fname = thefile)
File "C:\Python31\lib\site-packages\cImage.py", line 241, in __init__
self.loadImage(fname)
File "C:\Python31\lib\site-packages\cImage.py", line 277, in loadTkImage
self.im = tkinter.PhotoImage(file=fname)
File "C:\Python31\lib\tkinter\__init__.py", line 3269, in __init__
Image.__init__(self, 'photo', name, cnf, master, **kw)
File "C:\Python31\lib\tkinter\__init__.py", line 3225, in __init__
self.tk.call(('image', 'create', imgtype, name,) + options)
_tkinter.TclError: couldn't open "horse.gif": no such file or directory

Here is my code

import cImage
def makeRedScale(imageFile):
    myImageWindow = cImage.ImageWin("Image Processing",600,300)
    oldImage = cImage.FileImage(imageFile)
    oldImage.draw(myImageWindow)
    width = oldImage.getWidth()
    height = oldImage.getHeight()
    newImage = emptyImage (width,height)
    for row in range(height):
        for col in range(width):
            originalPixel = oldImage.getPixel(col,row)
            newPixel = redPixel(originalPixel)
            newImage.setPixel (col,row,newPixel)
        newImage.setPosition(width + 1,0)
        newImage.draw(myImageWindow)
        myImageWindow.exitOnClick()
def redPixel(oldPixel):
     intensitySum = oldPixel.getRed() + oldPixel.getGreen() + \
                        oldPixel.getBlue()
     AveRGB = intensitySum//3
     newPixel = pixel(AveRGB,AveRGB,AveRGB)
     return newPixel

_tkinter.TclError: couldn't open "horse.gif": no such file or directory

It could not open the file. Try it with the complete path.

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