Python jython JES:添加一个小插曲概要

Python jython JES:添加一个小插曲概要,python,jython,jes,Python,Jython,Jes,我正在尝试用JES创建一个程序,其中包含两个函数,main()和addVignette(inputPic,vignette) main()函数用于创建两个图片对象。我希望它允许用户选择一个输入图片(要操纵的图片),然后允许用户选择vignette(vignette_profile.jpg)。一旦创建了这两个图片对象,它就应该调用addVignette(inputPic,vignette) addVignette(inputPic,vignette)函数应该被编写为接受两个图片对象作为参数。这些图

我正在尝试用JES创建一个程序,其中包含两个函数,main()和addVignette(inputPic,vignette)

main()函数用于创建两个图片对象。我希望它允许用户选择一个输入图片(要操纵的图片),然后允许用户选择vignette(vignette_profile.jpg)。一旦创建了这两个图片对象,它就应该调用addVignette(inputPic,vignette)

addVignette(inputPic,vignette)函数应该被编写为接受两个图片对象作为参数。这些图片对象是在main()函数中创建的,并作为输入传递到此函数。因此,基本上,使用这两个图片对象,我需要我的函数来执行vignette加法操作,这个操作应该应用于inputPic图片中的每个像素。新编辑的图片应显示在屏幕上

我无法将图片相乘。我不确定是编码错误还是我的公式不正确。 我不知道应该准确地编码什么,因为渐晕轮廓有较暗的边缘和较亮的中心

谢谢大家

    def main():
    file1 = pickAFile()
    file2 = pickAFile()
    inputPic=makePicture(file1)
    vignette=makePicture(file2)
    addVignette(inputPic,vignette)

    def addVignette(inputPic,vignette):
    if getWidth(inputPic)==getWidth(vignette) and getHeight(inputPic)==getHeight(vignette):
    explore(inputPic)
    explore(vignette)
    allpx=getAllPixels(inputPic)
    for px in getAllPixels(inputPic):
    x=getX(px)
    y=getY(px)
    px2=getPixelAt(vignette,x,y)
    x1=getX(px)
    y2=getY(px)
    r1=getRed(px)
    r2=getRed(px2)
    g1=getGreen(px)
    g2=getGreen(px2)
    b1=getBlue(px)
    b2=getBlue(px2)



    if (1<r2<137): 
      r3=(r2-r1)-33
      g3=(g2-g1)+21
      b3=(b1-b2)+51

    if (138<r2<210):
      r3=(r2-r1)-21
      g3=(g2-g1)+49
      b3=(b1-b2)+121

    if (211<r2<246):
      r3=(r2-r1)+66
      g3=(g2-g1)+138
      b3=(b1-b2)+177

    if (247<r2<255):
      r3=(r2-r1)+44
      g3=(g2-g1)+125
      b3=(b2-b1)+201

    setRed(px,r3)
    setGreen(px,g3)
    setBlue(px,b)

  explore(inputPic)  
   else:
   print "Try Again"    
def main():
file1=pickAFile()
file2=pickAFile()
inputPic=makePicture(文件1)
vignette=makePicture(文件2)
添加渐晕图(inputPic,渐晕图)
def addVignette(输入pic,vignette):
如果getWidth(inputPic)==getWidth(vignette)和getHeight(inputPic)==getHeight(vignette):
探索(inputPic)
探索(小插曲)
allpx=getAllPixels(inputPic)
对于以getAllPixels(inputPic)表示的px:
x=getX(px)
y=getY(px)
px2=getPixelAt(渐晕,x,y)
x1=getX(px)
y2=getY(px)
r1=getRed(px)
r2=getRed(px2)
g1=绿色(px)
g2=绿色(px2)
b1=getBlue(px)
b2=getBlue(px2)

如果(1这可能不是你想要的,但我从你的问题中得到的是,你有两张图片,你正试图合并在一起,其中一张恰好是一个小插曲

请用以下内容替换您的
addVignette()

def addVignette(inputPic,vignette):
  # Cycle through each pixel in the input image
  for oPixel in getPixels(inputPic):

    # Get the pixel from the Vignette image that is at the same
    # location as the current pixel of the input image
    vignettePixel = getPixel(vignette, getX(oPixel), getY(oPixel))

    # Get the average of the color values by adding the color
    # values from the input & vignette together and then dividing
    # by 2
    newRed = (getRed(oPixel) + getRed(vignettePixel)) / 2
    newGreen = (getGreen(oPixel) + getGreen(vignettePixel)) / 2
    newBlue = (getBlue(oPixel) + getBlue(vignettePixel)) / 2

    # Make a new color from those values
    newColor = makeColor(newRed, newGreen, newBlue)

    # Assign this new color to the current pixel of the input image
    setColor(oPixel, newColor)

  explore(inputPic)
下面是我的测试结果和图片