JES - Alter the amount of red of an image

613 views Asked by At

I need to decrease the amount of red in a pixel by 50% on the top half of the image and then increase bottom half by 50%

def changeRed():
    setMediaPath("/Users/addison/Downloads/Cmpt101_Pics/Learjet31A.jpg")
    filename1 = "/Users/addison/Downloads/Cmpt101_Pics/Learjet31A.jpg"
    source = makePicture(filename1)
    halfWidth = getWidth(source)/2
    for y in range(0,getHeight(source)):
      for x in range(0, halfWidth):
        pixel = getPixel(source, x, y)      
        value = getRed(pixel)        
        setRed(pixel, value-127.5)
    show(source)

This is what I have right now, I'm not sure how to change it to make it halved on the X axis instead of the Y axis which it currently does right now..I have attempted to look everywhere for the solution but can't seem to find anything...Help Please

1

There are 1 answers

0
super_mario3d On BEST ANSWER

All you need to do is swap the x and y in the for loops. For example

for x in range(0, getWidth(source)):
  for y in range(0, halfHeight):
     # Do stuff