Merge pull request #675 from campagnola/fix-empty-image

Gracefully handle case where image data has size==0
This commit is contained in:
Luke Campagnola 2018-04-25 16:57:43 -07:00 committed by GitHub
commit 748ca554e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 3 deletions

View File

@ -469,11 +469,11 @@ class ImageItem(GraphicsObject):
This method is also used when automatically computing levels.
"""
if self.image is None:
if self.image is None or self.image.size == 0:
return None,None
if step == 'auto':
step = (int(np.ceil(self.image.shape[0] / targetImageSize)),
int(np.ceil(self.image.shape[1] / targetImageSize)))
step = (max(1, int(np.ceil(self.image.shape[0] / targetImageSize))),
max(1, int(np.ceil(self.image.shape[1] / targetImageSize))))
if np.isscalar(step):
step = (step, step)
stepData = self.image[::step[0], ::step[1]]

View File

@ -633,8 +633,12 @@ class ImageView(QtGui.QWidget):
cax = self.axes['c']
if cax is None:
if data.size == 0:
return [(0, 0)]
return [(float(nanmin(data)), float(nanmax(data)))]
else:
if data.size == 0:
return [(0, 0)] * data.shape[-1]
return [(float(nanmin(data.take(i, axis=cax))),
float(nanmax(data.take(i, axis=cax)))) for i in range(data.shape[-1])]