Get ImageView ROI working with both row and col major data

This commit is contained in:
Kenneth Lyons 2020-07-04 23:14:08 -07:00
parent b79c979663
commit 6052ba7668

View File

@ -590,30 +590,42 @@ class ImageView(QtGui.QWidget):
self.ui.roiPlot.setVisible(showRoiPlot)
def roiChanged(self):
# Extract image data from ROI
if self.image is None:
return
image = self.getProcessedImage()
# Extract image data from ROI
axes = (self.axes['x'], self.axes['y'])
# getArrayRegion axes should be (x, y) of data array for col-major,
# (y, x) for row-major
# can't just transpose input because ROI is axisOrder aware
colmaj = self.imageItem.axisOrder == 'col-major'
if colmaj:
axes = (self.axes['x'], self.axes['y'])
else:
axes = (self.axes['y'], self.axes['x'])
data, coords = self.roi.getArrayRegion(
image.view(np.ndarray), img=self.imageItem, axes=axes,
returnMappedCoords=True)
data, coords = self.roi.getArrayRegion(image.view(np.ndarray), self.imageItem, returnMappedCoords=True)
if data is None:
return
# Convert extracted data into 1D plot data
if self.axes['t'] is None:
# Average across y-axis of ROI
data = data.mean(axis=axes[1])
if axes == (1,0): ## we're in row-major order mode -- there's probably a better way to do this slicing dynamically, but I've not figured it out yet.
coords = coords[:,0,:] - coords[:,0,0:1]
else: #default to old way
coords = coords[:,:,0] - coords[:,0:1,0]
data = data.mean(axis=self.axes['y'])
# get coordinates along x axis of ROI mapped to range (0, roiwidth)
if colmaj:
coords = coords[:, :, 0] - coords[:, 0:1, 0]
else:
coords = coords[:, 0, :] - coords[:, 0, 0:1]
xvals = (coords**2).sum(axis=0) ** 0.5
else:
# Average data within entire ROI for each frame
data = data.mean(axis=max(axes)).mean(axis=min(axes))
data = data.mean(axis=axes)
xvals = self.tVals
# Handle multi-channel data