0
0

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.

機械学習で使用する画像のサイズ変換

Last updated at Posted at 2018-12-20

画像処理ライブラリpillow

PIL(Python Imaging Library)の後継として開発されている。

(参考URL)
https://www.sejuku.net/blog/62599
https://python-pillow.org

インストール方法

pip install pillow

使い方

色々できますが、今回やりたかった内容について記載します。
今回やりたいことは、1万枚のサイズが異なる画像を、すべて224x24のサイズに変更する。

# -*- coding:utf-8 -*-
name_list = ["a.jpg", "b.jpg","c.jpg"]
from PIL import Image

# ファイル名を1つづつ取り出し、サイズ変換して、同じファイル名でsave
for i in name_list:
  img_resize = Image.open(i).resize((224,224))
  img_resize.save(i)

ファイル名のリスト箇所は、フォルダから1つづつ取り出すような効率いいやり方できると思うので、そこは後日。
今回はとりあえず、上記を実行して全画像224x224に変更できた。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?