Change Contents of the Bubble
Welcome to CS1315. Click on the python to add comments.

Looking for the book? They have it at the Engineer's Bookstore at 748 Marietta St NW. Here is there website: http://www.engrbookstore.com/ - Monica

Hotspots: Slides and CodeTA CornerComments?AnnouncementsFAQStatic Webspace
View this PageEdit this PageUploads to this PageHistory of this PageHomeRecent ChangesSearchHelp Guide

Summer2006 Midterm 1 Review: Generalized image filter

Questions?

def changeRGB(picture, red, green, blue):
  for p in getPixels(picture):
    red = getRed(p)
    green = getGreen(p)
    blue = getBlue(p)
    setRed (p, red*-.75)
    setGreen (p, green*.25)
    setBlue (p, blue-.25)

Close but not quite. Math Problem: How do I calculate 75% of 50? -Albert d'Heurle


Shouldn't this be another generalized function like the one before, without hard coding the percentages into the program?

Yes, the numbers shouldn't be hardcoded. That would make the above function incorrect. - Bobby Mathew

def changeRGB(picture, red, green, blue):
  for p in getPixels(picture):
    red = getRed(p)
    green = getGreen(p)
    blue = getBlue(p)
    setRed (p, red*.75)
    setGreen (p, green*1.25)
    setBlue (p, blue*.25)


Read the above post. You shouldn't be having the numbers like .75, 1.25 etc. Use the parameters instead of the actual numbers. - Bobby Mathew

Would this work?

def changeRGB(picture, red, green, blue):
for p in getPixels (picture):
red = getRed(p)
green = getGreen(p)
blue = getBlue(p)
setRed = (p, red - (red.75))
setGreen = (p, green + (green.25))
setBlue = (p, blue - (blue.25))

so the last answer should be correct, but instead of each percentage do you want us to write 'amount'?
The parameters 'red', 'green' and 'blue' represent the amount for each value so you wouldn't actually need to use amount as a seperate variable. -Bobby Mathew



def changeRGB(picture, redamount, greenamount, blueamount)
   for p in getPixels(picture):
      red = getRed(p)
      green = getGreen(p)
      blue = getBlue(p)
      setRed = (p, red*(1+redamount))
      setGreen = (p, green*(1+blueamount))
      setBlue = (p, blue*(1+greenamount))



That's right. - Bobby Mathew

no its not, he forgot his colon :)
Good eye, I'm mainly checking if the actual calculation steps are right. - Bobby Mathew


Link to this Page