2016-04-27 14 views
0

ワンドで画像の複数の部分を抽出したい。ワンドを使用したスライス画像

私はちょうどimg.crop(left, top, right, bottom)の画像を(その場で)切り取る機能を見つけましたが、スライスはin the docと書いてあります。

あなたは、画像をトリミングではなく、その場で、 演算子をスライス使用したい場合。

答えて

1

例については、テストディレクトリのtest_slice_cropメソッドを参照してください。

with Image(filename='source.jpg') as img: 
    with img[100:200, 100:200] as cropped: 
     # The `cropped' is an instance if wand.image.Image, 
     # and can be manipulated independently of `img' instance. 
     pass 

編集

完了するために、sliceは、反復のセット(すなわちa[start:stop:step])を表すためにPythonで組み込み関数です。 では、これは、短手行列の反復を

wand_instance[x:width, y:height] 

を可能にするために使用される。ここで

from wand.image import Image 

with Image(filename="rose:") as rose: 
    x = 0 
    chunk_size = 10 
    while True: 
     try: 
      with rose[x:x+chunk_size, 0:rose.height] as chunk: 
       chunk.save(filename='rose_{0}.png'.format(x)) 
       x += chunk_size 
     except IndexError: 
      break 

sliced image

... 10pxの列を生成する例です
関連する問題