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.
|
|
|
|
"""
|
|
|
|
|
2021-04-21 02:57:15 +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
|
|
|
|
|
2021-04-21 02:57:15 +00:00
|
|
|
import pyqtgraph as pg
|
|
|
|
from pyqtgraph.Qt import QtGui
|
2012-03-02 02:55:32 +00:00
|
|
|
|
2021-01-27 18:59:07 +00:00
|
|
|
app = pg.mkQApp("Histogram Lookup Table Example")
|
2012-03-02 02:55:32 +00:00
|
|
|
win = QtGui.QMainWindow()
|
2021-04-21 02:57:15 +00:00
|
|
|
win.resize(880, 600)
|
2012-03-02 02:55:32 +00:00
|
|
|
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)
|
|
|
|
|
2021-04-21 02:57:15 +00:00
|
|
|
layout = QtGui.QGridLayout()
|
|
|
|
cw.setLayout(layout)
|
|
|
|
layout.setSpacing(0)
|
2012-03-02 02:55:32 +00:00
|
|
|
|
2021-04-21 02:57:15 +00:00
|
|
|
view = pg.GraphicsView()
|
2012-03-02 02:55:32 +00:00
|
|
|
vb = pg.ViewBox()
|
|
|
|
vb.setAspectLocked()
|
2021-04-21 02:57:15 +00:00
|
|
|
view.setCentralItem(vb)
|
|
|
|
layout.addWidget(view, 0, 1, 3, 1)
|
|
|
|
|
|
|
|
hist = pg.HistogramLUTWidget(gradientPosition="left")
|
|
|
|
layout.addWidget(hist, 0, 2)
|
2012-03-02 02:55:32 +00:00
|
|
|
|
|
|
|
|
2017-09-26 15:50:31 +00:00
|
|
|
monoRadio = QtGui.QRadioButton('mono')
|
|
|
|
rgbaRadio = QtGui.QRadioButton('rgba')
|
2021-04-21 02:57:15 +00:00
|
|
|
layout.addWidget(monoRadio, 1, 2)
|
|
|
|
layout.addWidget(rgbaRadio, 2, 2)
|
2017-09-26 15:50:31 +00:00
|
|
|
monoRadio.setChecked(True)
|
|
|
|
|
2021-04-21 02:57:15 +00:00
|
|
|
|
2017-09-26 15:50:31 +00:00
|
|
|
def setLevelMode():
|
|
|
|
mode = 'mono' if monoRadio.isChecked() else 'rgba'
|
2021-04-21 02:57:15 +00:00
|
|
|
hist.setLevelMode(mode)
|
|
|
|
|
|
|
|
|
2017-09-26 15:50:31 +00:00
|
|
|
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()
|
|
|
|
|
2021-04-21 02:57:15 +00:00
|
|
|
hist.setImageItem(img)
|
2012-03-02 02:55:32 +00:00
|
|
|
|
2012-12-05 05:25:45 +00:00
|
|
|
if __name__ == '__main__':
|
2021-05-13 21:28:22 +00:00
|
|
|
pg.exec()
|