# 画像の読み込み
img = cv2.imread('img.png')
img = cv2.imread('%d.png'%(i))#画像名,ファイル名に変数が含まれているとき
# 画像の保存
plt.imsave("img.png",img)
plt.savefig("img.png")#描画したものを保存したいとき
# 画像のトリミング
ymin, ymax, xmin, xmax = 0, 0, 0, 0 #任意に指定
img=img[ymin:ymax, xmin:xmax]
# 画像色変換
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) #3d→2d
# 画像リサイズ
img2 = cv2.resize(img , (100, 100))
# 空画像作成,空配列作成
test = np.zeros((100,100), dtype=np.uint8)#2次元配列全部0
test = np.full((100,100),0, np.uint8)#↑と同じ 変換後の数字を指定できる
More than 5 years have passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme