2012-03-02 02:55:32 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2013-02-25 04:09:03 +00:00
|
|
|
"""
|
|
|
|
Use a HistogramLUTWidget to control the contrast / coloration of an image.
|
|
|
|
"""
|
|
|
|
|
2012-03-02 02:55:32 +00:00
|
|
|
## Add path to library (just for examples; you do not need this)
|
2012-12-26 22:51:52 +00:00
|
|
|
import initExample
|
2012-03-02 02:55:32 +00:00
|
|
|
|
|
|
|
import numpy as np
|
2012-03-02 03:53:52 +00:00
|
|
|
from pyqtgraph.Qt import QtGui, QtCore
|
2012-03-02 02:55:32 +00:00
|
|
|
import pyqtgraph as pg
|
|
|
|
|
|
|
|
|
|
|
|
app = QtGui.QApplication([])
|
|
|
|
win = QtGui.QMainWindow()
|
|
|
|
win.resize(800,600)
|
|
|
|
win.show()
|
2013-02-25 04:09:03 +00:00
|
|
|
win.setWindowTitle('pyqtgraph example: Histogram LUT')
|
2012-03-02 02:55:32 +00:00
|
|
|
|
|
|
|
cw = QtGui.QWidget()
|
|
|
|
win.setCentralWidget(cw)
|
|
|
|
|
|
|
|
l = QtGui.QGridLayout()
|
|
|
|
cw.setLayout(l)
|
|
|
|
l.setSpacing(0)
|
|
|
|
|
|
|
|
v = pg.GraphicsView()
|
|
|
|
vb = pg.ViewBox()
|
|
|
|
vb.setAspectLocked()
|
|
|
|
v.setCentralItem(vb)
|
2017-09-26 15:50:31 +00:00
|
|
|
l.addWidget(v, 0, 0, 3, 1)
|
2012-03-02 02:55:32 +00:00
|
|
|
|
|
|
|
w = pg.HistogramLUTWidget()
|
|
|
|
l.addWidget(w, 0, 1)
|
|
|
|
|
2017-09-26 15:50:31 +00:00
|
|
|
monoRadio = QtGui.QRadioButton('mono')
|
|
|
|
rgbaRadio = QtGui.QRadioButton('rgba')
|
|
|
|
l.addWidget(monoRadio, 1, 1)
|
|
|
|
l.addWidget(rgbaRadio, 2, 1)
|
|
|
|
monoRadio.setChecked(True)
|
|
|
|
|
|
|
|
def setLevelMode():
|
|
|
|
mode = 'mono' if monoRadio.isChecked() else 'rgba'
|
|
|
|
w.setLevelMode(mode)
|
|
|
|
monoRadio.toggled.connect(setLevelMode)
|
|
|
|
|
|
|
|
data = pg.gaussianFilter(np.random.normal(size=(256, 256, 3)), (20, 20, 0))
|
2012-03-02 02:55:32 +00:00
|
|
|
for i in range(32):
|
|
|
|
for j in range(32):
|
|
|
|
data[i*8, j*8] += .1
|
|
|
|
img = pg.ImageItem(data)
|
|
|
|
vb.addItem(img)
|
|
|
|
vb.autoRange()
|
|
|
|
|
|
|
|
w.setImageItem(img)
|
|
|
|
|
|
|
|
|
|
|
|
## Start Qt event loop unless running in interactive mode.
|
2012-12-05 05:25:45 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
import sys
|
|
|
|
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
|
|
|
|
QtGui.QApplication.instance().exec_()
|