ImageView updates to improve subclassing flexibility:
- Allow non-ndarray image data - Make quickMinMax a normal method
This commit is contained in:
parent
4e1905f0e1
commit
210d07027e
|
@ -196,7 +196,12 @@ class ImageView(QtGui.QWidget):
|
||||||
img = img.asarray()
|
img = img.asarray()
|
||||||
|
|
||||||
if not isinstance(img, np.ndarray):
|
if not isinstance(img, np.ndarray):
|
||||||
raise Exception("Image must be specified as ndarray.")
|
required = ['dtype', 'max', 'min', 'ndim', 'shape', 'size']
|
||||||
|
if not all([hasattr(img, attr) for attr in required]):
|
||||||
|
raise TypeError("Image must be NumPy array or any object "
|
||||||
|
"that provides compatible attributes/methods:\n"
|
||||||
|
" %s" % str(required))
|
||||||
|
|
||||||
self.image = img
|
self.image = img
|
||||||
self.imageDisp = None
|
self.imageDisp = None
|
||||||
|
|
||||||
|
@ -319,11 +324,10 @@ class ImageView(QtGui.QWidget):
|
||||||
if self.imageDisp is None:
|
if self.imageDisp is None:
|
||||||
image = self.normalize(self.image)
|
image = self.normalize(self.image)
|
||||||
self.imageDisp = image
|
self.imageDisp = image
|
||||||
self.levelMin, self.levelMax = list(map(float, ImageView.quickMinMax(self.imageDisp)))
|
self.levelMin, self.levelMax = list(map(float, self.quickMinMax(self.imageDisp)))
|
||||||
|
|
||||||
return self.imageDisp
|
return self.imageDisp
|
||||||
|
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
"""Closes the widget nicely, making sure to clear the graphics scene and release memory."""
|
"""Closes the widget nicely, making sure to clear the graphics scene and release memory."""
|
||||||
self.ui.roiPlot.close()
|
self.ui.roiPlot.close()
|
||||||
|
@ -375,7 +379,6 @@ class ImageView(QtGui.QWidget):
|
||||||
else:
|
else:
|
||||||
QtGui.QWidget.keyReleaseEvent(self, ev)
|
QtGui.QWidget.keyReleaseEvent(self, ev)
|
||||||
|
|
||||||
|
|
||||||
def evalKeyState(self):
|
def evalKeyState(self):
|
||||||
if len(self.keysPressed) == 1:
|
if len(self.keysPressed) == 1:
|
||||||
key = list(self.keysPressed.keys())[0]
|
key = list(self.keysPressed.keys())[0]
|
||||||
|
@ -399,16 +402,13 @@ class ImageView(QtGui.QWidget):
|
||||||
else:
|
else:
|
||||||
self.play(0)
|
self.play(0)
|
||||||
|
|
||||||
|
|
||||||
def timeout(self):
|
def timeout(self):
|
||||||
now = ptime.time()
|
now = ptime.time()
|
||||||
dt = now - self.lastPlayTime
|
dt = now - self.lastPlayTime
|
||||||
if dt < 0:
|
if dt < 0:
|
||||||
return
|
return
|
||||||
n = int(self.playRate * dt)
|
n = int(self.playRate * dt)
|
||||||
#print n, dt
|
|
||||||
if n != 0:
|
if n != 0:
|
||||||
#print n, dt, self.lastPlayTime
|
|
||||||
self.lastPlayTime += (float(n)/self.playRate)
|
self.lastPlayTime += (float(n)/self.playRate)
|
||||||
if self.currentIndex+n > self.image.shape[0]:
|
if self.currentIndex+n > self.image.shape[0]:
|
||||||
self.play(0)
|
self.play(0)
|
||||||
|
@ -434,16 +434,13 @@ class ImageView(QtGui.QWidget):
|
||||||
self.roiChanged()
|
self.roiChanged()
|
||||||
self.sigProcessingChanged.emit(self)
|
self.sigProcessingChanged.emit(self)
|
||||||
|
|
||||||
|
|
||||||
def updateNorm(self):
|
def updateNorm(self):
|
||||||
if self.ui.normTimeRangeCheck.isChecked():
|
if self.ui.normTimeRangeCheck.isChecked():
|
||||||
#print "show!"
|
|
||||||
self.normRgn.show()
|
self.normRgn.show()
|
||||||
else:
|
else:
|
||||||
self.normRgn.hide()
|
self.normRgn.hide()
|
||||||
|
|
||||||
if self.ui.normROICheck.isChecked():
|
if self.ui.normROICheck.isChecked():
|
||||||
#print "show!"
|
|
||||||
self.normRoi.show()
|
self.normRoi.show()
|
||||||
else:
|
else:
|
||||||
self.normRoi.hide()
|
self.normRoi.hide()
|
||||||
|
@ -520,11 +517,10 @@ class ImageView(QtGui.QWidget):
|
||||||
xvals = (coords**2).sum(axis=0) ** 0.5
|
xvals = (coords**2).sum(axis=0) ** 0.5
|
||||||
self.roiCurve.setData(y=data, x=xvals)
|
self.roiCurve.setData(y=data, x=xvals)
|
||||||
|
|
||||||
#self.ui.roiPlot.replot()
|
def quickMinMax(self, data):
|
||||||
|
"""
|
||||||
|
Estimate the min/max values of *data* by subsampling.
|
||||||
@staticmethod
|
"""
|
||||||
def quickMinMax(data):
|
|
||||||
while data.size > 1e6:
|
while data.size > 1e6:
|
||||||
ax = np.argmax(data.shape)
|
ax = np.argmax(data.shape)
|
||||||
sl = [slice(None)] * data.ndim
|
sl = [slice(None)] * data.ndim
|
||||||
|
@ -533,7 +529,12 @@ class ImageView(QtGui.QWidget):
|
||||||
return data.min(), data.max()
|
return data.min(), data.max()
|
||||||
|
|
||||||
def normalize(self, image):
|
def normalize(self, image):
|
||||||
|
"""
|
||||||
|
Process *image* using the normalization options configured in the
|
||||||
|
control panel.
|
||||||
|
|
||||||
|
This can be repurposed to process any data through the same filter.
|
||||||
|
"""
|
||||||
if self.ui.normOffRadio.isChecked():
|
if self.ui.normOffRadio.isChecked():
|
||||||
return image
|
return image
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user