Merge pull request #1291 from ixjlyons/roi-axisorder
Get ImageView ROI working with both row and col major data
This commit is contained in:
commit
c03018005a
@ -590,30 +590,42 @@ class ImageView(QtGui.QWidget):
|
|||||||
self.ui.roiPlot.setVisible(showRoiPlot)
|
self.ui.roiPlot.setVisible(showRoiPlot)
|
||||||
|
|
||||||
def roiChanged(self):
|
def roiChanged(self):
|
||||||
|
# Extract image data from ROI
|
||||||
if self.image is None:
|
if self.image is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
image = self.getProcessedImage()
|
image = self.getProcessedImage()
|
||||||
|
|
||||||
# Extract image data from ROI
|
# 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'])
|
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:
|
if data is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
# Convert extracted data into 1D plot data
|
# Convert extracted data into 1D plot data
|
||||||
if self.axes['t'] is None:
|
if self.axes['t'] is None:
|
||||||
# Average across y-axis of ROI
|
# Average across y-axis of ROI
|
||||||
data = data.mean(axis=axes[1])
|
data = data.mean(axis=self.axes['y'])
|
||||||
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]
|
# get coordinates along x axis of ROI mapped to range (0, roiwidth)
|
||||||
else: #default to old way
|
if colmaj:
|
||||||
coords = coords[:,:,0] - coords[:,0:1,0]
|
coords = coords[:, :, 0] - coords[:, 0:1, 0]
|
||||||
|
else:
|
||||||
|
coords = coords[:, 0, :] - coords[:, 0, 0:1]
|
||||||
xvals = (coords**2).sum(axis=0) ** 0.5
|
xvals = (coords**2).sum(axis=0) ** 0.5
|
||||||
else:
|
else:
|
||||||
# Average data within entire ROI for each frame
|
# 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
|
xvals = self.tVals
|
||||||
|
|
||||||
# Handle multi-channel data
|
# Handle multi-channel data
|
||||||
|
Loading…
Reference in New Issue
Block a user