2011-12-08 21 views
-1

大きな画像(5000 x 5000)があると仮定して、この大きな画像からランダムに部分(200 x 200 square)を選択できますか?また、境界線を設定して、選択範囲が画像の外側の領域を取らないようにしたい。pythonで画像からランダムな部分を選択する方法

誰かが何らかのアイデアを持っている場合は、光を当ててください。

答えて

2
import random 

image_size = (5000,5000) 
portion_size = (200, 200) 

x1 = random.randint(0, image_size[0]-portion_size[0]-1) 
y1 = random.randint(0, image_size[1]-portion_size[1]-1) 

x2, y2 = x1+portion_size[0]-1, y1+portion_size[1]-1 

# Grab the area of the image that is the rectangle defined by (x1,y1) and (x2,y2) 

どのように最後のビットを行うかは、画像の操作方法によって異なります。

+0

おっと。 :) 一定。 – Amber

+0

私はそれを試してみましょう。私が問題に遭遇したら、私はあなたに知らせるでしょう。ありがとう –

関連する問題