Colormap

141 views
Skip to first unread message

Horner

unread,
Jun 13, 2015, 7:32:57 AM6/13/15
to pyqt...@googlegroups.com

Hi,

Sorry if this is a stupid question, but I'm quite new to this sort of stuff.

I want to create a lookup table for images with intensity values from around -40 to +40 with negative values mapped to blue and positive values mapped to red.
Opacity should increase with increasing absolute number.
I want to specify a range around zero that has zero opacity and values above the minimum and maximum range should have full opacity.

I've attached an image to help me describe what I'm after.

Anybody got any ideas on how to achieve this?

Below is what I tried so far, but doesn't do what I want yet.

Cheers,

Neil

def get_lut(self, pos):
pos = np.array([pos[0], pos[1], 0, pos[2], pos[3]])
color = np.array([[0, 0, 255, 255],[0, 0, 0, 10], [0, 0, 0, 0], [0,0,0,10], [255, 0, 0, 255]], dtype=np.ubyte)
map = pg.ColorMap(pos, color)
lut = map.getLookupTable(values[0], values[3], 512, alpha=True)
return lut

lut = _tscore([-20, -2, 2, 20])
self.image_item.setLookupTable(self.lut)


cm.png

Horner

unread,
Jun 14, 2015, 8:09:02 AM6/14/15
to pyqt...@googlegroups.com
I managed to do what I needed by splitting my image into two imageItems, one with negative and the other with positive values and applying separate LUTs on each.

anonymou...@gmail.com

unread,
Jun 15, 2015, 4:49:26 PM6/15/15
to pyqt...@googlegroups.com
so i don't how if this code helps atp, i played with the challenge and
my incomplete solution makes a single colormap but i have zero clue about lut
maybe lut = cmap.getLookupTable(a, d) or more likely not  :)

from pyqtgraph.Qt import QtCore, QtGui
import numpy as np
import pyqtgraph as pg

app
= pg.QtGui.QApplication([])
win
= pg.QtGui.QMainWindow()
win
.resize(800,800)
imv
= pg.ImageView()
win
.setCentralWidget(imv)
win
.show()


a
= -40.
b
= -10.
c
= 10.
d
= 40.
a_map
= (0,0,255,255)
b_map
= (0,0,0,0)
c_map
= (0,0,0,0)
d_map
= (255,0,0,255)

cmap
= pg.ColorMap([a,b,c,d], [a_map,b_map,c_map,d_map])

data
= np.linspace(a, d, 100).reshape(10,10)
cmapd_data
= cmap.map(data)
imv
.setImage(cmapd_data)


if __name__ == '__main__':
   
import sys
   
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
       
QtGui.QApplication.instance().exec_()

untitled.PNG

anonymou...@gmail.com

unread,
Jun 16, 2015, 1:32:39 AM6/16/15
to pyqt...@googlegroups.com
WHOAA COOL!!! made few adjustments:

don't fade to black, only fade alpha
don't explicitly remap data, use lookup table

drag the histogram selection and check out the changing image

from pyqtgraph.Qt import QtCore, QtGui
import numpy as np
import pyqtgraph as
pg
pg
.setConfigOptions(background='#ffffff')


app
= pg.QtGui.QApplication([])
win
= pg.QtGui.QMainWindow()
win
.resize(800,800)
imv
= pg.ImageView()
win
.setCentralWidget(imv)
win
.show()


a
= -40.
b
= -10.
c
= 10.
d
= 40.
a_map
= (0,0,255,255)

b_map
= (0,0,255,0)
c_map
= (255,0,0,0)

d_map
= (255,0,0,255)

cmap
= pg.ColorMap([a,b,c,d], [a_map,b_map,c_map,d_map])

lut
= cmap.getLookupTable(a, d, alpha=True)


data
= np.linspace(a, d, 100).reshape(10,10)


imv
.imageItem.setLookupTable(lut)
imv
.setImage(data)



if __name__ == '__main__':
   
import sys
   
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
       
QtGui.QApplication.instance().exec_()

#ps, i don't know why my imageview sometimes crashes at exit)



untitled.PNG
Reply all
Reply to author
Forward
0 new messages