我想使用用户输入确定的范围内的像素的平均颜色来更改整个图片的白平衡。我正在使用称为startX
,endX
,startY
和endY
的变量。
我设法从单个像素坐标进行了操作,但不是从该范围内的像素的平均值中进行的。greyValue
是我卡住的地方,因为我不知道如何返回颜色平均值。
def whiteBalanceBonus():
File=pickAFile()
myPict=makePicture(File)
startX=requestInteger("Enter the value of the first 'X' Coordinate in the range")
startY=requestInteger("Enter the value of the first 'Y' Coordinate in the range")
endX=requestInteger("Enter the value of the last 'X' Coordinate in the range")
endY=requestInteger("Enter the value of the last 'Y' Coordinate in the range")
for x in range(startX,endX):
for y in range(startY,endY):
pixel=getPixel(myPict,x,y)
greyValue=
不要介意解决它:)
def whiteBalanceBonus():
File=pickAFile()
myPict=makePicture(File)
startX=requestInteger("Enter the value of the first 'X' Coordinate in the range")
startY=requestInteger("Enter the value of the first 'Y' Coordinate in the range")
endX=requestInteger("Enter the value of the last 'X' Coordinate in the range")
endY=requestInteger("Enter the value of the last 'Y' Coordinate in the range")
for x in range(startX,endX):
for y in range(startY,endY):
pixels=getPixel(myPict,x,y)
greyValue=(getRed(pixels)+getGreen(pixels)+getBlue(pixels))/3
redAdjust=(greyValue)/float(getRed(pixels))
greenAdjust=(greyValue)/float(getGreen(pixels))
blueAdjust=(greyValue)/float(getBlue(pixels))
for px in getPixels(myPict):
if (distance(white,getColor(px))>10):
setRed(px,getRed(px)*redAdjust)
setGreen(px,getGreen(px)*greenAdjust)
setBlue(px,getBlue(px)*blueAdjust)
repaint (myPict)