def image_from_array(img_array, format='png'):
"""Creates an image object from a given numpy array.
Parameters
----------
img_array : numpy.ndarray
The image data, which can have 1 or 3 color channels.
Returns
-------
IPython.display.Image
An image object for plots.
"""
factor = 1
if utils.image.is_float_image(img_array):
factor = 255
img_data = np.uint8(img_array * factor)
f = StringIO()
img_data = utils.image.to_rgb(img_data)
arr = PIL.Image.fromarray(img_data)
arr.save(f, format)
return Image(data=f.getvalue())
评论列表
文章目录