def whiteBalance():
myFile = pickAFile()
print myFile
myPicture = makePicture(myFile)
print myPicture
explore(myPicture)
xRef = requestInteger("Enter the X Value of the Reference Point")
yRef = requestInteger("Enter the Y value of the Reference Point")
for p in getPixels(myPicture):
average = (getRed(p)+getGreen(p)+getBlue(p))/3
setColor(p,makeColor(average,average,average))
for px in getPixels(myPicture):
newRed = getRed(px) * 0.9
newGreen = getGreen(px) * 0.944
newBlue = getBlue(px) * 1.20
explore(myPicture)
Above is my code! Im trying to make an image and make it whiter with whiteBalance().
Heres my planning
Calculation of grey value at reference point – The grey value of the pixel is the average of its red, green and blue values. For instance, in the example the RGB values of the reference point at this stage would be 151, 161 and 137. Therefore, the grey value should be 149.66...
Calculation of R, G, B adjustment factors – We want the RGB values of the reference point to be turned in to the grey value calculated above. For this, we divide the grey value by the individual red, green, blue values at the reference point and get the adjustment factor.
So thats the scenario, after that the image will be displayed brighter, what can i do, this current code glitches and makes the windows pop up 100 times, literally!
Thanks in Advance!
So in your code you ask for x and y but not use it to calculate the grey value? Also, where are those numbers come from? (the one you use to make new red, green and blue value?)
I'll explain every step but don't just copy the code, try to understand it and write it again. That how people learn to program. Good luck!
Use this to pick a file, make it your picture and display it for comparison later.
def whiteBalance():
file = pickAFile()
pic = makePicture(file)
explore(pic)
Then ask the user for a reference point in your picture
x = requestInteger ("Please specify X-coordinate")
y = requestInteger ("Please specify Y-coordinate")
Then get the RGB value of that specific pixel the user just gave you
pixel = getPixelAt(pic,x,y)
Pull R,G,B value from that pixel to use for calculation of the gray value
red = getRed(pixel)
green = getGreen(pixel)
blue = getBlue(pixel)
average = (red+green+blue)/3.00
Then calculate R, G, B adjustment factors.
redadj = average /red
greenadj = average /green
blueadj = average /blue
Now you can use a loop to apply the change to the entire immage.
for r in getPixels(pic):
value = getRed(r)
setRed(r, (value* redadj))
for g in getPixels(pic):
value = getGreen(g)
setGreen(g, (value* greenadj))
for b in getPixels(pic):
value = getBlue(b)
setBlue(b, (value* blueadj))
Then now you can display your edited image with explore(pic). Just pay attention to the indentation, that's why you're getting a lot of windows popping up.