0
1

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.

手元にある画像データ(png)を.pbm画像に変換する

Posted at

opencvでやろうと思っていたけど、
pillowの方が初心者向けっぽいのでまずはそっちでお試し。

png_to_pbm.py

# jupyterで表示する場合に有効にする。
# %matplotlib inline

from PIL import Image
import os
import matplotlib.pyplot as plt

file_name = 'piet.png'

# 画像ファイル開く
img = Image.open(file_name)

# 1bitに変換?の意味?
img_pbm = img.convert('1')
img_pbm.save('piet.pbm')
plt.imshow(img_pbm)

# 'L'だとグレースケールになる
# img_pgm = img.convert('L')

# 'RGB'だとRGBになる
# img_ppm = img.convert('RGB')


リサイズしたい場合は以下。

png_to_pbm.pyつづき
lf_img_resize = lf_img.resize((512,128))
lf_img_resize.save('lf_img_resize.pbm')
plt.imshow(lf_img_resize)
0
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?