2016-12-11 5 views
0

を使用して2枚の画像をブレンド:私はエラーを取得する私は一緒に2枚の画像をブレンドするトリング午前と毎回私はこれを実行するJythonの

getPixel(picture,x,y): x (= 310) is less than 0 or bigger than the width (= 309) 

エラー値は次のとおりです。

Inappropriate argument value (of correct type). 
An error occurred attempting to pass an argument to a function. 
Please check line 18 

私がリサイズされていますそれがうまくいくかどうかを確認するために複数の画像を表示します。どんな助けも素晴らしいだろう。

次のように私は私の写真は大きさでてきた今の時点で:
アンテロープ= 310x369
Jackolope = 250x341

def blendPictures():    #define a new function 
    Pic1=makePicture(pickAFile())  #Pick Pic1 Antelope(Barb) 
    Pic2=makePicture(pickAFile())  #Pick Pic2 Jackalope(Katie) 
    canvas=makeEmptyPicture(640,480) #Create an empty picture file 
    sourceX=0 
    for targetX in range(0,150):  #Let's ad our first loop 
    sourceY=0 
    for targetY in range(0,getHeight(Pic1)): 
     color = getColor(getPixel(Pic1,sourceX,sourceY)) 
     setColor(getPixel(canvas,targetX,targetY),color) 
     sourceY = sourceY + 1 
    sourceX = sourceX +1 
    overlap = getWidth(Pic1)-150 
    sourceX=0 
    for targetX in range(150,getHeight(Pic1)): 
    sourceY=0 
    for targetY in range(0,getHeight(Pic2)): 
     APixel = getPixel(Pic1,sourceX+150,sourceY) 
     BPixel = getPixel(Pic2,sourceX,sourceY) 
     newRed=0.50*getRed(APixel)+0.50*getRed(BPixel) 
     newGreen=0.50*getGreen(APixel)+0.50*getGreen(BPixel) 
     newBlue=0.50*getBlue(APixel)+0.50*getBlue(BPixel) 
     color=makeColor(newRed,newGreen,newBlue) 
     setColor(getPixel(canvas,targetX,targetY),color) 
     sourceY=sourceY+1 
    sourceX=sourceX+1 
    sourceX=overlap 
    for targetX in range(150+overlap,150+getWidth(Pic2)): 
    sourceY=0 
    for targetY in range(0,getHeight(Pic2)): 
     color=getColor(getPixel(Pic2,sourceX,sourceY)) 
     setColor(getPixel(canvas,targetX,targetY),color) 
     sourceY=sourceY+1 
    sourceX=sourceX+1 
    show(canvas) 
    return canvas 

答えて

0

を私は、あなたがやろうとしているかわからないんだけど なく、明白1問題は、あなたの第2のループ部分である:

for targetX in range(150, getHeight(Pic1)): 

これは次のようになります。

for targetX in range(150, getWidth(Pic1)): 

そうしないと、ループラインで述べたエラーが発生しますx方向、 で219回(369から150):反復160 219の中で、コードがgetPixel(Pic1, 310, 0)をしようとします

APixel = getPixel(Pic1, sourceX+150, sourceY) 

のでこれは境界外です。

+1

ありがとうございます!あなたがそれを指摘したので、それは非常に明白です。私はこのコードをどのくらい見ていて、それを理解できなかったのか分かりません。今すぐ完璧に動作します。別の写真を撮る必要があります。もう一度ありがとうSMeyer –

関連する問題