def read_image(image_name, img_size=None):
"""
Read image from file
:param image_name: string, image full name including path
:param img_size: tuple of two ints, optional, specify if you want to resize image
:return: numpy 2d array
"""
filename = image_name
try:
img = io.imread(filename)
except IOError:
return None
img = img_as_float(img)
if len(img.shape) > 2:
img = img[:, :, 0]
if img_size is not None:
img = resize(img, (img_size[0], img_size[1]))
img = img.reshape((1, img_size[0], img_size[1]))
return img
评论列表
文章目录