def new_image(self, image, diag=False):
if isinstance(image, str):
self.image_file = image
self.image = np.array(PIL.Image.open(image))
else:
self.image_file = None
self.image = image
# Get the image into the right format.
if self.image.dtype != np.uint8:
raise TypeError('Image %s dtype is not unsigned 8 bit integer, image.dtype is %s.'%(
'"%s"'%self.image_file if self.image_file is not None else 'argument',
self.image.dtype))
self.image = np.squeeze(self.image)
if len(self.image.shape) == 2:
self.image = np.dstack([self.image] * 3)
self.preprocess_edges()
self.randomize_view()
if diag:
plt.figure('Image')
plt.title('Image')
plt.imshow(self.image, interpolation='nearest')
plt.show()
评论列表
文章目录