|
@@ -35,7 +35,8 @@ class ImageWrapper(object):
|
|
|
|
|
|
def __del__(self):
|
|
|
if isinstance(self._im, Image.Image):
|
|
|
- self._im.close()
|
|
|
+ if self._im is not None and self._im.fp is not None:
|
|
|
+ self._im.close()
|
|
|
|
|
|
@property
|
|
|
def im(self):
|
|
@@ -44,8 +45,18 @@ class ImageWrapper(object):
|
|
|
@property
|
|
|
def im_array(self):
|
|
|
if self._im_array is None:
|
|
|
- self.im = self.im.convert(self.mode)
|
|
|
- self._im_array = utils.asarray(self.im)
|
|
|
+ if isinstance(self._im, Image.Image):
|
|
|
+ _im = self._im.convert(self.mode)
|
|
|
+ self._im_array = utils.asarray(_im)
|
|
|
+ elif isinstance(self._im, np.ndarray):
|
|
|
+ if self.mode == "RGB" and self._im.ndim == 2:
|
|
|
+ self._im_array = np.stack((self._im,) * 3, axis=-1)
|
|
|
+ elif self._im.ndim == 3:
|
|
|
+ self._im_array = self._im
|
|
|
+ else:
|
|
|
+ raise ValueError()
|
|
|
+ else:
|
|
|
+ raise ValueError()
|
|
|
return self._im_array
|
|
|
|
|
|
@im.setter
|