Fall 2006 Midterm 1 Review: Generalized image filter
Questions?
I dont understand how you can take in negative parameters in this context. When you multiply them by the former pixel value, don't you get a negative number?? How can you set a pixel to a negative color??
dont you have to set the red or green or whatever your are changing to 1.25 to increase it by 25% not just .25
| Sort of. That's how the function will work internally, but that's not how you give this function the values to make it work. I.e. if you give the function a red parameter of 0.25, it will multiply the red value by 1.25. If you give it a red parameter of -0.25, it will multiply the red value by 0.75. Think of the values as like the points on a dial that you can turn left (negative values) or right (positive values) to reduce or crank up the colors. Colin Potts |
Confusing.... :)
how's this look (or am I COMPLETELY off track)
def changeRGB(pic):
for p in getPixels(pic):
redvalue = getRed(p)
greenvalue = getGreen(p)
bluevalue = getBlue(p)
diffColor = makeColor(redvalue*.5, greenvalue*.5, bluevalue*.5)
setColor(p, diffColor)
show(pic)
return(pic)
Thanks again! Brittany Walsh
def changeRGB(pic):
for p in getPixels(pic):
value=getColor(p)
anothercolor=makeColor(p, value*amount)
setColor(p, anothercolor)
show(pic)
return pic
Stacy Schwaiger
So, can you put in just getColor for the values or do I need to define it for all three?
| Stacy, Your first function was CLOSER, but are you going to want to hardcode the amount your changing each color by? Or do you want that value to be an input for each color *hint hint, re-read the problem statement * Amanda Bennett |
WHAT???? I'm not sure what you mean by hard coding?
Brittany Walsh
def changeRGB(pic):
for p in getPixels(pic):
redvalue = getRed(p)
greenvalue = getGreen(p)
bluevalue = getBlue(p)
diffColor = makeColor(redvalue*amount, greenvalue*amount, bluevalue*amount)
setColor(p, diffColor)
show(pic)
return(pic)
Stacy Schwaiger
So, you want to leave the number as an amount......
| Once again, you need to define what amount is before you use it! And, for this function, you can change the redvalue, greenvalue, and bluevalue by different amounts, so you need to make sure each one has it's own individual "amount" variable defined. Amanda Bennett |
| FYI, the called function in the problem statement [where it says changeRGB(picture, .10, -.5, .3)] gives you a HUGE hint about what inputs you need in your def statement Amanda Bennett |
def changeRGB(pic, amount, amount, amount):
for p in getPixels(pic):
redvalue = getRed(p)
greenvalue = getGreen(p)
bluevalue = getBlue(p)
diffColor = makeColor(redvalue*amount, greenvalue*amount, bluevalue*amount)
setColor(p, diffColor)
show(pic)
return(pic)
Stacy Schwaiger
Is this closer?
| Closer, but you have three arguments with the same name, and they represent different quantities. So you need separate names. Also, remember what the amounts mean. Should you simply be multiplying the current values by these amounts or doing something else? Colin Potts |
def changeRGB(pic, amountRed, amountGreen, amountBlue):
for p in getPixels(pic):
redValue = getRed(p)
greenValue = getGreen(p)
blueValue = getBlue(p)
diffColor = makeColor(redValue + (redValue*amountRed), greenValue + (greenValue*amountGreen), blueValue + (blueValue*amountBlue)
setColor(p, diffColor)
show(pic)
return(pic)
So maybe more like this? The amounts now have specific names designating the color that it is altering. Also the colors should adjust the way we want them to?
Megan Bowen
the following code works on my friends computer but not mime:
def changeRGB(pic,amount1, amount2,amount3):
for p in getPixels(pic):
r =getRed(p)
g = getGreen(p)
b = getBlue(p)
setRed(p,r*amount1)
setGreen(p,g*amount2)
setBlue(p,b*amount3)
return pic
In the command area:
pic=makePicture(pickAFile())
changeRGB(pic, -.75, .25, -.25)
I get the following: A local or global name could not be found. You need to define the function or variable before you try to use it in any way.
how does this look?
def changeRGB(pic,changeR,changeG,changeB):
for p in getPixels(pic):
r=getRed(p)
setRed(p,r+(r*changeR))
g=getGreen(p)
setGreen(p,g+(g*changeG))
b=getBlue(p)
setBlue(p,b+(b*changeB))
show(pic)
charlie blackmon
For the second to last piece of code on here, are you sure you pressed "LOAD"?
For charlie: That looks perfect :)
Sweta Vajjhala
This seems to work, but I'm not sure if it is doing what it's supposed to do:
def changeRGB(pic, amountRed, amountGreen, amountBlue):
for p in getPixels(pic):
rValue = getRed(p)
gValue = getGreen(p)
bValue = getBlue(p)
newRed = (rValue + (rValue*amountRed))
newGreen = (gValue + (gValue*amountGreen))
newBlue = (bValue + (bValue*amountBlue))
setRed (p, newRed)
setGreen (p, newGreen)
setBlue (p, newBlue)
Courteney Ross
why do we add the original value to the newly multiplied value instead of just using the multiplied value?
| The multiplied value is only how much to take off or add on. Adding back to the original will give you the end result. -poof #10 |
because if you don't add, you get whatever percent instead of 100andwhatever percent. Like if you increased by 25% and you just multiply, you're getting 25%, not 125% which is what you're supposed to get
Link to this Page