扩展维数

$ python
Python 2.7.15+ (default, Oct  7 2019, 17:39:04)
[GCC 7.4.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import PIL
>>> PIL.file
>>> from PIL import Image

>>> import numpy as np
>>> z=np.array([124, 117, 104])
>>> z=np.expand_dims(np.expand_dims(np.array([124, 117, 104]), axis=0), axis=0)

>>> z
array([[[124, 117, 104]]])

>>> z=np.broadcast_to(z, (224, 224, 3))
>>> z
array([[[124, 117, 104],
        [124, 117, 104],
        [124, 117, 104],
        ...,
        [124, 117, 104],
        [124, 117, 104],
        [124, 117, 104]],

       [[124, 117, 104],
        [124, 117, 104],
        [124, 117, 104],
        ...,
        [124, 117, 104],
        [124, 117, 104],
        [124, 117, 104]],

       [[124, 117, 104],
        [124, 117, 104],
        [124, 117, 104],
        ...,
        [124, 117, 104],
        [124, 117, 104],
        [124, 117, 104]],

       ...,

       [[124, 117, 104],
        [124, 117, 104],
        [124, 117, 104],
        ...,
        [124, 117, 104],
        [124, 117, 104],
        [124, 117, 104]],

       [[124, 117, 104],
        [124, 117, 104],
        [124, 117, 104],
        ...,
        [124, 117, 104],
        [124, 117, 104],
        [124, 117, 104]],

       [[124, 117, 104],
        [124, 117, 104],
        [124, 117, 104],
        ...,
        [124, 117, 104],
        [124, 117, 104],
        [124, 117, 104]]])
>>> Image.fromarray(np.array(z, dtype=np.uint8))
<PIL.Image.Image image mode=RGB size=224x224 at 0x7F303FE11A90>

>>> Image.fromarray(np.array(z, dtype=np.uint8)).save('./x.ppm')
>>>

  save ppm

posted on 2019-12-03 15:14  cdekelon  阅读(90)  评论(0)    收藏  举报

导航