0

我正在尝试在 JES 中创建一个具有两个函数 main() 和 addVignette(inputPic, vignette) 的程序

main() 函数是创建两个图片对象的地方。我希望它允许用户选择输入图片(要操作的图片)然后允许用户选择小插图(vignette_profile.jpg)。创建这两个图片对象后,它应该调用 addVignette(inputPic, vignette)。

应编写 addVignette(inputPic, vignette) 函数以接受两个图片对象作为参数。这些图片对象是在 main() 函数中创建的,并作为输入传递给该函数。所以基本上,使用这两个图片对象,我需要我的函数来执行晕影添加操作,并且这个操作应该应用于 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"    
4

1 回答 1

0

这可能不是您所追求的,但我从您的问题中得到的是,您有 2 张图像要合并在一起,其中一张恰好是小插图。

请用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)

我的结果与下面的测试图像

输入图像

小插图

在此处输入图像描述

于 2014-09-02T05:42:55.477 回答