6

このプログラムは、画像の輪郭を取得し、それをさまざまな象限に分割してから、アンディ ウォーホル マリリン モンローの写真のように色付けすることになっています。

「Warholize」機能までのすべての機能が機能しますが、どうすればよいかわからない機能c=getPixel(picEdge,x,y)の下でスタックします。warholizeどんな助けでも大歓迎です。「c を picEdge の位置 x,y のピクセルの色とする」

def main():
  pic= makePicture( pickAFile() )
  show( pic )
  threshold= 10
  edgePic= makeOutline( pic, threshold )
  warholize(pic)
  show(warholize(pic))

def difference( a, b ):
  if a > b :
    return a - b
  else:
    return b - a

def intensity( px ) :
  r= getRed( px )
  g= getBlue( px )
  b= getGreen( px )
  avg= ( r + g + b ) / 3
  return avg

def makeOutline( pic, threshold ):
  w= getWidth( pic )
  h= getHeight( pic )
  edgePic= makeEmptyPicture( w, h )
  for x in range(2,w-1) :
    for y in range(2,h-1):
      px= getPixel( pic, x, y )
      pxLeft= getPixel( pic, x-1, y )
      pxUp= getPixel( pic, x, y-1 )
      leftDiff= difference( intensity(pxLeft), intensity(px) )
      upDiff= difference( intensity(pxUp), intensity(px) )
      if leftDiff > threshold or upDiff > threshold :
        setColor( getPixel(edgePic,x,y), black )   

def warholize(pic):
    threshold=10
    picEdge=makeOutline(pic,threshold)
    w= getWidth( pic )
    h= getHeight( pic )
    picNew= makeEmptyPicture( w, h )

    for x in range(0,w,2):
        for y in range (0,h,2):
           c=getPixel(picEdge,x,y)
           px=getPixel(picNew,x/2,y/2)
           if c is black:
               setColor(px,blue)
           else:
               setColor(px,yellow)
    return picNew
4

1 に答える 1