Fix ImageView levelMode (#1974)
* fixes #1769 * Automatically set image to ImageView if imageItem is provided. Added a test for correct initialization of ImageView with imageItem and levelMode.
This commit is contained in:
parent
babd037cf7
commit
6f4b6b1b88
@ -443,7 +443,7 @@ class HistogramLUTItem(GraphicsWidget):
|
||||
self.regions[i].setVisible(False)
|
||||
|
||||
if self.levelMode == 'rgba':
|
||||
imax = 4
|
||||
nch = 4
|
||||
if self.imageItem() is not None:
|
||||
# Only show rgb channels if connected image lacks alpha.
|
||||
nch = self.imageItem().channels()
|
||||
|
@ -127,7 +127,6 @@ class ImageView(QtGui.QWidget):
|
||||
self.ui = ui_template.Ui_Form()
|
||||
self.ui.setupUi(self)
|
||||
self.scene = self.ui.graphicsView.scene()
|
||||
self.ui.histogram.setLevelMode(levelMode)
|
||||
|
||||
self.ignorePlaying = False
|
||||
|
||||
@ -139,15 +138,6 @@ class ImageView(QtGui.QWidget):
|
||||
self.view.setAspectLocked(True)
|
||||
self.view.invertY()
|
||||
|
||||
if imageItem is None:
|
||||
self.imageItem = ImageItem()
|
||||
else:
|
||||
self.imageItem = imageItem
|
||||
self.view.addItem(self.imageItem)
|
||||
self.currentIndex = 0
|
||||
|
||||
self.ui.histogram.setImageItem(self.imageItem)
|
||||
|
||||
self.menu = None
|
||||
|
||||
self.ui.normGroup.hide()
|
||||
@ -171,6 +161,18 @@ class ImageView(QtGui.QWidget):
|
||||
self.timeLine.setZValue(1)
|
||||
self.ui.roiPlot.addItem(self.timeLine)
|
||||
self.ui.splitter.setSizes([self.height()-35, 35])
|
||||
|
||||
# init imageItem and histogram
|
||||
if imageItem is None:
|
||||
self.imageItem = ImageItem()
|
||||
else:
|
||||
self.imageItem = imageItem
|
||||
self.setImage(imageItem.image, autoRange=False, autoLevels=False, transform=imageItem.transform())
|
||||
self.view.addItem(self.imageItem)
|
||||
self.currentIndex = 0
|
||||
|
||||
self.ui.histogram.setImageItem(self.imageItem)
|
||||
self.ui.histogram.setLevelMode(levelMode)
|
||||
|
||||
# make splitter an unchangeable small grey line:
|
||||
s = self.ui.splitter
|
||||
|
@ -10,3 +10,9 @@ def test_nan_image():
|
||||
v.imageItem.getHistogram()
|
||||
app.processEvents()
|
||||
v.window().close()
|
||||
|
||||
def test_init_with_mode_and_imageitem():
|
||||
data = np.random.randint(256, size=(256, 256, 3))
|
||||
imgitem = pg.ImageItem(data)
|
||||
pg.ImageView(imageItem=imgitem, levelMode="rgba")
|
||||
assert(pg.image is not None)
|
||||
|
Loading…
x
Reference in New Issue
Block a user