-4

I need to build code for this question.

  1. First we need to understand what the vignette looks like in isolation, without the clutter of a beautiful scene. For this, a picture of a flat surface of a single colour that is evenly lit (such as a white wall or plain blue sky during mid-day) is obtained and used as a “vignette profile”. You are given the following vignette profile image.

    In this image, the pixels towards the center of the image have higher RGB values (i.e. brighter pixels) than the pixels that are away from the center. The image is also black and white, so red, green and blue values of any given pixel are the same. You must not modify this image.

  2. We need to use the vignette profile image from step #1 as a filter for our normal photos captured by our camera so that the vignette can be removed. For this you need to divide the photo image (with vignette) by the vignette profile image. As the pixels in the vignette image have RGB values that are smaller (darker) towards its edges, dividing the original image's corresponding pixels by a small number will make them brighter

These are the hints

Hint 1: This requires you to perform your operations on your images, pixel by pixel. I.e. you cannot do it in a single step.

Hint 2: The first challenge for you will be keeping the RGB values resulting from the division within the 0-255 range for each channel, as valid RGB values are between 0 (darkest) and 255 (brightest).


Edit:

Sample code:

def runA1(picture): myFile = pickAFile() picture = makePicture(myFile)

 myFile2 = pickAFile()
picture2 = makePicture(myFile2)


for x in range(0,getWidth(picture)):
    for y in range(0,getHeight(picture)):
      px = getPixel(picture,x,y)
      color = getColor(px)
      color = makeLighter(color)
      setColor(px,color)

for x in range(2,getWidth(picture)):
    for y in range(2,getHeight(picture)):
      px = getPixel(picture,x,y)
      color = getColor(px)
      color = makeDarker(color)
      setColor(px,color)



show(picture2)
4

1 回答 1

2

由于您还没有证明您自己尝试过任何事情,因此我只会提示您应该尝试什么。

  1. 考虑以 0-255 的形式表示为三个整数的单个像素(R,G,B)。晕影蒙版中的相应像素具有值A0-255。除以并(R,G,B)乘以255 得到未晕影的像素。(为什么我们需要乘以 256?)A(RR,GG,BB)

  2. 决定你想对R,G,B超过255. 如果晕影值A为零会怎样?

  3. 对图像中的每个像素执行此操作,从左到右的第一行像素开始,然后是下一行,依此类推,直到完成。


顺便说一句,这种事情在具有一流数值矩阵支持的语言中的一步操作——比如 MATLAB、Octave、Numpy/Scipy。这是一个 MATLAB 示例:

processed_image = original_image ./ repmat(vignette_image,[1 1 3]) * 256

编辑2:

对您的示例代码的一些评论:

  1. 您的缩进错误 - 此代码将无法运行。当您将其粘贴到 StackOverflow 时,它可能会被破坏。请修复它。尤其是,

    • def语句必须单独一行。
    • myFile2 =....必须从 def: 语句中缩进。
  2. myFile1, myFile2- 这些变量名可能更有意义。(其中哪张是原始照片?哪个是晕影遮罩?您可以尝试调用这些变量original_filevignette_file而不是。同上myPicture1myPicture2。)

  3. 您的代码中的注释在哪里?很难说你的代码做了什么。

除此之外,您需要发布更多代码。您的示例必须是简短、自包含、正确的示例。现在您的代码示例不是独立的,因为要运行它,我们还需要getPixel()getColor()makeLighter()等函数。由于缩进错误,它也无法编译。

于 2012-04-16T08:27:49.243 回答