1

写真の一部、この例では鼻を拡大したいと思います。

写真の拡大したい部分を選択する機能があります。

def copyAndPaste(picture):
  height = getHeight(picture)
  width = getWidth(picture)
  newPicture = makeEmptyPicture(width, height)
  for x in range(width):
    for y in range(height):
      pxl = getPixel(picture,x,y)
      if (x>48 and x<59) and (y>58 and y<71):
        newPxl =getPixel(newPicture, #?,#?)
      else:
        newPxl = getPixel(newPicture, x,y)
      color = getColor(pxl)
      setColor(newPxl,color)

  return newPicture

def d():    
  f=pickAFile()
  picture=makePicture(f)        
  newPicture = copyAndPaste(picture)        
  writePictureTo(newPicture, r"D:\FOLDER\0Pic4.jpg")
  explore (newPicture)

コピペ鼻

写真を拡大する機能もあります。

def Enlarge(picture):
  height = getHeight(picture)
  width = getWidth(picture)
  newPicture = makeEmptyPicture(width*2, height*2)
  x1=0
  for x in range(0,width):
    y1=0
    for y in range(0,height):
      pxl = getPixel(picture,x,y)
      newPxl = getPixel(newPicture, x1,y1)
      color = getColor(pxl)
      setColor(newPxl,color)

      y1=y1+2
    x1=x1+2

  return newPicture

例えば。
から:

元の写真

に:

拡大写真

私は多くのことを試しましたが、2 つを組み合わせて画像の一部を拡大し、画像の残りの部分をそのままにする方法がわかりません。

これは、結果の画像がどのように見えるかです (ばかげているように)。

拡大した鼻

プログラムの実行に時間がかかる可能性があるため、小さな画像で練習してきました。この段階では、大きな画像を操作することは実行できません。つまり、結果は大ざっぱですが、少なくとも機能するかどうかは示されます。

4

2 に答える 2

5

あなたが何をしようとしているのかまだよくわかりませんが、次のようなものだと思います:カット アンド ペーストの代わりに鼻をコピー アンド ペーストし、ペーストしたコピーを2番目の例と同じ独特の方法。

したがって、顔の中央に 10x10 の鼻があり、さらに右下に 20x20 の色あせた鼻があります。


まず、コピーして貼り付けるには、ピクセルを新しい位置だけでなく、古い位置と新しい位置にコピーする必要があります。

def copyAndPaste(picture):
  height = getHeight(picture)
  width = getWidth(picture)
  newPicture = makeEmptyPicture(width+100, height+100)
  for x in range(width):
    for y in range(height):
      pxl = getPixel(picture,x,y)
      color = getColor(pxl)
      if (x>48 and x<59) and (y>58 and y<71):
        newPxl =getPixel(newPicture, x+100,y+100)
        setColor(newPxl,color)
      newPxl = getPixel(newPicture, x,y)
      setColor(newPxl,color)

ここで、新しく貼り付けたコピーを拡大するには、オフセットを 2 倍にするだけです。つまり、49,59 の最初のピクセルは 149,159 になりますが、50,60 のピクセルは 151,161 になり、51,61 のピクセルは 153,163 になります。

したがって、必要なのは、49,59 から距離を取得し、それを 2 倍にして 49,59 に戻し、100,100 ずつ移動することです。

      if (x>48 and x<59) and (y>58 and y<71):
        newPxl =getPixel(newPicture, (x-49)*2+49+100,(y-59)*2+59+100)
        setColor(newPxl,color)
于 2013-07-05T11:51:38.570 に答える