0
from cImage import *
fileImageName = "butterfly.png"

def getNegativePixel(oldPixel):
    newRed = 255 - oldPixel.getRed()
    newGreen = 255 - oldPixel.getGreen()
    newBlue = 255 - oldPixel.getBlue()
    newPixel = Pixel(newRed, newGreen, newBlue)
    return newPixel

def makeNegativeImage(imageFile):
    oldImage = FileImage(imageFile)
    oHeight = oldImage.getHeight()
    oWidth = oldImage.getWidth()

    myWindow = ImageWin("Negative Butterfly Image",oWidth * 2, oHeight)
    oldImage.draw(myWindow)

    newImage = EmptyImage(oWidth,oHeight)

    for row in range(oHeight):
        for column in range(oWidth):
            oldPixel = oldImage.getPixel(column, row)
            newPixel = getNegativePixel(oldPixel)
            newImage.setPixel( column, row,newPixel )


    
    newImage.setPosition(oWidth + 1, 0)
    newImage.draw(myWindow)
    
    myWindow.exitOnClick()


makeNegativeImage(fileImageName)

I have just been stuck with it tried changing certain variables but couldn't really work it out. Ive tried asking them for help but didnt really provide so im hoping someone would know how to do it, so i could better understand how to make it work

  • For each new pixel, average all 3 values together, that'd work – Random Davis Dec 16 '22 at 23:25
  • just search for grayscale with rgb and workout some samples. If you get stuck ask a specific question on where in the code you're having problems with. you can be sure someone here will help. – MZM Dec 16 '22 at 23:26

0 Answers0