3

写真を半分に「カット」して、両側を水平に反転しようとしています。以下のリンクを参照してください。

http://imgur.com/a/FAksh

原画:

ここに画像の説明を入力

出力が必要なもの:

ここに画像の説明を入力

私が得ているもの

ここに画像の説明を入力

これは私が持っているものですが、画像を水平に反転するだけです

def mirrorHorizontal(picture):
  mirrorPoint = getHeight(picture)/2
  height = getHeight(picture)
  for x in range(0, getWidth(picture)):
    for y in range(0, mirrorPoint):
      topPixel = getPixel(picture, x, y)
      bottomPixel = getPixel(picture, x, height - y - 1)
      color = getColor(topPixel)
      setColor(bottomPixel, color)

では、2 番目の写真のように見えるように、各面を水平に反転するにはどうすればよいでしょうか。

4

2 に答える 2

1

1 つのアプローチは、画像の一部を水平方向に反転する関数を定義することです。

def mirrorRowsHorizontal(picture, y_start, y_end):
    ''' Flip the rows from y_start to y_end in place. '''
    # WRITE ME!

def mirrorHorizontal(picture):
    h = getHeight(picture)
    mirrorRowsHorizontal(picture, 0, h/2)
    mirrorRowsHorizontal(picture, h/2, h)

うまくいけば、それがあなたのスタートになります。

ヒント: 2 つのピクセルを交換する必要がある場合があります。これを行うには、一時変数を使用する必要があります。

于 2012-10-23T02:19:57.767 に答える
0

1年後、私たちは答えを出すことができると思います:

def mirrorRowsHorizontal(picture, y_start, y_end):
    width = getWidth(picture)

    for y in range(y_start/2, y_end/2):
        for x in range(0, width):
            sourcePixel = getPixel(picture, x, y_start/2 + y)
            targetPixel = getPixel(picture, x, y_start/2 + y_end - y - 1)
            color = getColor(sourcePixel)
            setColor(sourcePixel, getColor(targetPixel))
            setColor(targetPixel, color)

def mirrorHorizontal(picture):
    h = getHeight(picture)
    mirrorRowsHorizontal(picture, 0, h/2)
    mirrorRowsHorizontal(picture, h/2, h)

ここで垂直フリップから撮影。

3 つのストライプの例:

mirrorRowsHorizontal(picture, 0, h/3)
mirrorRowsHorizontal(picture, h/3, 2*h/3)
mirrorRowsHorizontal(picture, 2*h/3, h)

前 :

ここに画像の説明を入力

後 :

ここに画像の説明を入力

于 2013-06-16T06:43:35.903 に答える