In [27]:
from skimage import io

グレースケールチャート読み込んでみる。

  • QVGAの白黒チャート
In [29]:
img_bw=io.imread('QVGA_bw.jpg')
  • グレースケールなので1pixelが0~255のスカラー値の二次元配列
In [30]:
print(img_bw)
[[  0   0   0 ... 255 255 255]
 [  0   0   0 ... 255 255 255]
 [  0   0   0 ... 255 255 255]
 ...
 [  0   0   0 ... 255 255 255]
 [  0   0   0 ... 255 255 255]
 [  0   0   0 ... 255 255 255]]
In [31]:
img_bw.shape
Out[31]:
(240, 320)

画像表示のためにPyplotをインポート

In [28]:
from matplotlib import pyplot as plt
In [32]:
plt.imshow(img_bw)
Out[32]:
<matplotlib.image.AxesImage at 0x1df2685f9e8>
In [33]:
plt.get_cmap().name
Out[33]:
'viridis'

colormapを指定して表示する

In [8]:
plt.imshow(img_bw, cmap='gray')
Out[8]:
<matplotlib.image.AxesImage at 0x1df2678cb70>
In [9]:
from skimage import color as cl
In [10]:
img_bw=cl.gray2rgb(img_bw)
In [11]:
img_bw
Out[11]:
array([[[  0,   0,   0],
        [  0,   0,   0],
        [  0,   0,   0],
        ...,
        [255, 255, 255],
        [255, 255, 255],
        [255, 255, 255]],

       [[  0,   0,   0],
        [  0,   0,   0],
        [  0,   0,   0],
        ...,
        [255, 255, 255],
        [255, 255, 255],
        [255, 255, 255]],

       [[  0,   0,   0],
        [  0,   0,   0],
        [  0,   0,   0],
        ...,
        [255, 255, 255],
        [255, 255, 255],
        [255, 255, 255]],

       ...,

       [[  0,   0,   0],
        [  0,   0,   0],
        [  0,   0,   0],
        ...,
        [255, 255, 255],
        [255, 255, 255],
        [255, 255, 255]],

       [[  0,   0,   0],
        [  0,   0,   0],
        [  0,   0,   0],
        ...,
        [255, 255, 255],
        [255, 255, 255],
        [255, 255, 255]],

       [[  0,   0,   0],
        [  0,   0,   0],
        [  0,   0,   0],
        ...,
        [255, 255, 255],
        [255, 255, 255],
        [255, 255, 255]]], dtype=uint8)
In [12]:
img_bw.shape
Out[12]:
(240, 320, 3)
In [13]:
plt.imshow(img_bw)
Out[13]:
<matplotlib.image.AxesImage at 0x1df268002b0>