pikesaku’s blog

個人的な勉強メモです。記載内容について一切の責任は持ちません。

ピクセルデータを指定した画像作成方法

サンプルコード(参考URLまるまる利用)

# -*- coding:utf-8 -*-

import matplotlib.pyplot as plt
import PIL
import numpy as np

img_rgb = np.array([
                    [[255,0,0],[0,255,0],[0,0,255]],
                    [[255,255,0],[0,255,255],[255,0,255]],
                    [[0,0,0],[127,127,127],[255,255,255]],
], dtype = np.uint8)

#画像の表示
#plt.imshow(img_rgb, cmap = 'gray', vmin = 0, vmax = 255, interpolation = 'none')
plt.imshow(img_rgb, interpolation = 'none')

plt.show()

アウトプット

f:id:pikesaku:20181014222120p:plain