1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

よく使うPythonコード  画像処理編

1
Last updated at Posted at 2021-02-19
# 画像の読み込み
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)#↑と同じ 変換後の数字を指定できる
1
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?