2012-03-01 21:55:32 -05:00
|
|
|
# -*- coding: utf-8 -*-
|
2013-02-24 23:09:03 -05:00
|
|
|
"""
|
|
|
|
Use a HistogramLUTWidget to control the contrast / coloration of an image.
|
|
|
|
"""
|
|
|
|
|
2021-04-20 19:57:15 -07:00
|
|
|
# Add path to library (just for examples; you do not need this)
|
2012-12-26 17:51:52 -05:00
|
|
|
import initExample
|
2012-03-01 21:55:32 -05:00
|
|
|
|
|
|
|
import numpy as np
|
|
|
|
|
2021-04-20 19:57:15 -07:00
|
|
|
import pyqtgraph as pg
|
|
|
|
from pyqtgraph.Qt import QtGui
|
2012-03-01 21:55:32 -05:00
|
|
|
|
2021-01-27 10:59:07 -08:00
|
|
|
app = pg.mkQApp("Histogram Lookup Table Example")
|
2012-03-01 21:55:32 -05:00
|
|
|
win = QtGui.QMainWindow()
|
2021-04-20 19:57:15 -07:00
|
|
|
win.resize(880, 600)
|
2012-03-01 21:55:32 -05:00
|
|
|
win.show()
|
2013-02-24 23:09:03 -05:00
|
|
|
win.setWindowTitle('pyqtgraph example: Histogram LUT')
|
2012-03-01 21:55:32 -05:00
|
|
|
|
|
|
|
cw = QtGui.QWidget()
|
|
|
|
win.setCentralWidget(cw)
|
|
|
|
|
2021-04-20 19:57:15 -07:00
|
|
|
layout = QtGui.QGridLayout()
|
|
|
|
cw.setLayout(layout)
|
|
|
|
layout.setSpacing(0)
|
2012-03-01 21:55:32 -05:00
|
|
|
|
2021-04-20 19:57:15 -07:00
|
|
|
view = pg.GraphicsView()
|
2012-03-01 21:55:32 -05:00
|
|
|
vb = pg.ViewBox()
|
|
|
|
vb.setAspectLocked()
|
2021-04-20 19:57:15 -07:00
|
|
|
view.setCentralItem(vb)
|
|
|
|
layout.addWidget(view, 0, 1, 3, 1)
|
|
|
|
|
|
|
|
hist = pg.HistogramLUTWidget(gradientPosition="left")
|
|
|
|
layout.addWidget(hist, 0, 2)
|
2012-03-01 21:55:32 -05:00
|
|
|
|
|
|
|
|
2017-09-26 08:50:31 -07:00
|
|
|
monoRadio = QtGui.QRadioButton('mono')
|
|
|
|
rgbaRadio = QtGui.QRadioButton('rgba')
|
2021-04-20 19:57:15 -07:00
|
|
|
layout.addWidget(monoRadio, 1, 2)
|
|
|
|
layout.addWidget(rgbaRadio, 2, 2)
|
2017-09-26 08:50:31 -07:00
|
|
|
monoRadio.setChecked(True)
|
|
|
|
|
2021-04-20 19:57:15 -07:00
|
|
|
|
2017-09-26 08:50:31 -07:00
|
|
|
def setLevelMode():
|
|
|
|
mode = 'mono' if monoRadio.isChecked() else 'rgba'
|
2021-04-20 19:57:15 -07:00
|
|
|
hist.setLevelMode(mode)
|
|
|
|
|
|
|
|
|
2017-09-26 08:50:31 -07:00
|
|
|
monoRadio.toggled.connect(setLevelMode)
|
|
|
|
|
|
|
|
data = pg.gaussianFilter(np.random.normal(size=(256, 256, 3)), (20, 20, 0))
|
2012-03-01 21:55:32 -05: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()
|
|
|
|
|
2021-04-20 19:57:15 -07:00
|
|
|
hist.setImageItem(img)
|
2012-03-01 21:55:32 -05:00
|
|
|
|
2012-12-05 00:25:45 -05:00
|
|
|
if __name__ == '__main__':
|
2021-05-14 05:28:22 +08:00
|
|
|
pg.exec()
|