From e740cb4b4931f0e068c6524b97957e5c082323e0 Mon Sep 17 00:00:00 2001 From: Luke Campagnola Date: Tue, 3 May 2016 09:13:25 -0700 Subject: [PATCH] updated examples to use normal axis order, fixed a few ROI bugs --- examples/ROIExamples.py | 6 ++++++ examples/imageAnalysis.py | 6 +++--- pyqtgraph/graphicsItems/ROI.py | 24 +++++++++++++----------- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/examples/ROIExamples.py b/examples/ROIExamples.py index 55c671ad..e52590f6 100644 --- a/examples/ROIExamples.py +++ b/examples/ROIExamples.py @@ -11,6 +11,7 @@ import pyqtgraph as pg from pyqtgraph.Qt import QtCore, QtGui import numpy as np +pg.setConfigOptions(imageAxisOrder='normal') ## Create image to display arr = np.ones((100, 100), dtype=float) @@ -24,6 +25,11 @@ arr[:, 50] = 10 arr += np.sin(np.linspace(0, 20, 100)).reshape(1, 100) arr += np.random.normal(size=(100,100)) +# add an arrow for asymmetry +arr[10, :50] = 10 +arr[9:12, 44:48] = 10 +arr[8:13, 44:46] = 10 + ## create GUI app = QtGui.QApplication([]) diff --git a/examples/imageAnalysis.py b/examples/imageAnalysis.py index be64815e..18e96e97 100644 --- a/examples/imageAnalysis.py +++ b/examples/imageAnalysis.py @@ -58,10 +58,10 @@ win.show() # Generate image data -data = np.random.normal(size=(100, 200)) +data = np.random.normal(size=(200, 100)) data[20:80, 20:80] += 2. data = pg.gaussianFilter(data, (3, 3)) -data += np.random.normal(size=(100, 200)) * 0.1 +data += np.random.normal(size=(200, 100)) * 0.1 img.setImage(data) hist.setLevels(data.min(), data.max()) @@ -80,7 +80,7 @@ p1.autoRange() def updatePlot(): global img, roi, data, p2 selected = roi.getArrayRegion(data, img) - p2.plot(selected.mean(axis=1), clear=True) + p2.plot(selected.mean(axis=0), clear=True) roi.sigRegionChanged.connect(updatePlot) updatePlot() diff --git a/pyqtgraph/graphicsItems/ROI.py b/pyqtgraph/graphicsItems/ROI.py index d5f41af4..267773fd 100644 --- a/pyqtgraph/graphicsItems/ROI.py +++ b/pyqtgraph/graphicsItems/ROI.py @@ -1020,11 +1020,8 @@ class ROI(GraphicsObject): If the slice can not be computed (usually because the scene/transforms are not properly constructed yet), then the method returns None. """ - #print "getArraySlice" - ## Determine shape of array along ROI axes dShape = (data.shape[axes[0]], data.shape[axes[1]]) - #print " dshape", dShape ## Determine transform that maps ROI bounding box to image coordinates try: @@ -1033,25 +1030,28 @@ class ROI(GraphicsObject): return None ## Modify transform to scale from image coords to data coords - #m = QtGui.QTransform() - tr.scale(float(dShape[0]) / img.width(), float(dShape[1]) / img.height()) - #tr = tr * m + axisOrder = getConfigOption('imageAxisOrder') + if axisOrder == 'normal': + tr.scale(float(dShape[1]) / img.width(), float(dShape[0]) / img.height()) + else: + tr.scale(float(dShape[0]) / img.width(), float(dShape[1]) / img.height()) ## Transform ROI bounds into data bounds dataBounds = tr.mapRect(self.boundingRect()) - #print " boundingRect:", self.boundingRect() - #print " dataBounds:", dataBounds ## Intersect transformed ROI bounds with data bounds - intBounds = dataBounds.intersected(QtCore.QRectF(0, 0, dShape[0], dShape[1])) - #print " intBounds:", intBounds + if axisOrder == 'normal': + intBounds = dataBounds.intersected(QtCore.QRectF(0, 0, dShape[1], dShape[0])) + else: + intBounds = dataBounds.intersected(QtCore.QRectF(0, 0, dShape[0], dShape[1])) ## Determine index values to use when referencing the array. bounds = ( (int(min(intBounds.left(), intBounds.right())), int(1+max(intBounds.left(), intBounds.right()))), (int(min(intBounds.bottom(), intBounds.top())), int(1+max(intBounds.bottom(), intBounds.top()))) ) - #print " bounds:", bounds + if axisOrder == 'normal': + bounds = bounds[::-1] if returnSlice: ## Create slice objects @@ -1650,6 +1650,8 @@ class MultiRectROI(QtGui.QGraphicsObject): ## make sure orthogonal axis is the same size ## (sometimes fp errors cause differences) + if getConfigOption('imageAxisOrder') == 'normal': + axes = axes[::-1] ms = min([r.shape[axes[1]] for r in rgns]) sl = [slice(None)] * rgns[0].ndim sl[axes[1]] = slice(0,ms)