1

画像のさまざまな部分の色を変更するプログラムを書いています。この場合、画像の上 3 分の 1 と下 3 分の 1 です。

下 3 分の 1 を変更することはできますが、何らかの理由でプログラムが認識しないため、if (y<h/3)この代わりに実際の数字を入れてみたり、色の変更をコーディングする方法を変更したりしました。

誰かが私が犯している(おそらく非常に明白な)間違いを指摘してもらえますか.

def changeByThirds(pic):
  w= getWidth (pic)
  h = getHeight(pic)

  newPic = makeEmptyPicture(w,h)
  for x in range (0,w):
    for y in range (0,h):
      pxl = getPixel(pic, x, y)

      if (y<h/3):
        newPxl= getPixel (newPic, x, y)
        color = makeColor(getRed(pxl)*0.1, getGreen(pxl), getBlue(pxl))
        setColor ( newPxl, color)

      if (y>(h*2/3)):
        newPxl= getPixel (newPic, x, y)
        color = makeColor(getRed(pxl), getGreen(pxl), 0)  
        setColor ( newPxl, color)

      else:
        newPxl = getPixel (newPic, x, y)
        color = getColor(pxl)
        setColor ( newPxl, color)

  return (newPic)

def do():
  file = pickAFile()
  pic = makePicture(file)
  newPic = changeByThirds(pic)
  writePictureTo(newPic, r"D:\FOLDER\0pic3.jpg")
  explore (newPic)
4

1 に答える 1