-2
画像の一部を選択して画像ファイルとして保存したいが、imcrop()関数を使用したくない。これには多くの回答がある私は作物機能を使用したくない。他の方法は?Pythonで画像の一部を選択する(imcropを使用しない)
画像の一部を選択して画像ファイルとして保存したいが、imcrop()関数を使用したくない。これには多くの回答がある私は作物機能を使用したくない。他の方法は?Pythonで画像の一部を選択する(imcropを使用しない)
これを配列に変換し、インデックスを作成して「トリミング」して、画像に戻すことができます。
from PIL import Image
import numpy as np
# Create an image for example
w, h = 512, 512
data = np.zeros((h, w, 3), dtype=np.uint8)
data[:, :, :] = 100 # Grey image
img = Image.fromarray(data, 'RGB')
img.save('my.png')
img.show() # View the original image
img_array = np.asarray(img) # Convert image to an array
cropped = img_array[:100, :100, :] # Select portion to keep
img = Image.fromarray(cropped, 'RGB') # Convert back to image
img.save('my.png')
img.show() # View the cropped image
どの画像処理ライブラリを使用していますか? 'imcrop'とは何ですか?なぜあなたはそれを使いたくないのですか? – martineau