0
我想通過選擇一個圖像的子區域來變成一個新的圖像文件來裁剪圖像。在Python中裁剪圖像:Image.crop()與Image.transform()?
根據我在PIL文檔中看到的內容,我試圖在兩種方法之間做出決定。
這兩種方式:
# assume I already have a PIL-opened image called original_image
# assume I have a crop_box tuple for the area to crop, e.g. (0, 0, 100, 100)
途徑
直接裁剪的原始圖像,然後轉化返回的農作物種植面積到一個新文件。我似乎放棄了關於原始圖像的所有模式數據/其他元數據,然後必須重新加載?
cropped_image = original_image.crop(crop_box) # process cropped version as needed
做一個
image.transform()
我在其中選擇一個子區域# assume I have an output size of (100, 100) cropped_image = original_image.transform(size, Image.EXTENT, crop_box) # process cropped version as needed
是一種方法優於另在速度,數據保存,或另一個重要因素方面,我錯過了?
+1顯式優於隱式。 – 2013-02-25 23:05:01