LookupTable and ImageItem: how to prevent colors from changing

18 views
Skip to first unread message

Manu

unread,
Mar 25, 2020, 8:19:04 AM3/25/20
to pyqtgraph
Hello,

I am displaying an image of integers, a so-called label map. Each integer corresponds to a different class and should have its own color. It works fine when the image does not change. However in my application, the label map changes and new integer values are added. When this happens, the color assigned to already existing integer values change. I want them to stay the same. 

What happens in practice: in current label map, '1' corresponds to blue. When I add the new value '2' : '1' changes to red, and '2' adopts blue. I want '1' to keep its initial color blue, and '2' to adopt a new color.

Any idea?

If it helps, here is how I create the lookuptable (I use a method found in this group to convert from matplotlib):

colormap = matplotlib.cm.get_cmap('CMRmap')
colormap._init()
lut = (colormap._lut * 255).view(np.ndarray)
# edit alpha channel so that '0'->transparent
alpha = np.ones(lut.shape[0]) * 255
alpha[0] = 0
lut[:,3] = alpha

my_imageItem.setLookupTable(lut)

Best,
Manu

Patrick

unread,
Mar 25, 2020, 10:00:44 PM3/25/20
to pyqtgraph
Hi,

I think you want to disable the (default) autoLevels when setting your image data: http://www.pyqtgraph.org/documentation/graphicsItems/imageitem.html#pyqtgraph.ImageItem.setImage
So just something like
my_imageItem.setImage(data, levels=(0, 100), lut=lut)
should do it, changing the levels to whatever limits of your integer data are.

Manu

unread,
Mar 27, 2020, 5:17:51 AM3/27/20
to pyqt...@googlegroups.com
Yes, that was it, thanks a lot ! :-)

--
You received this message because you are subscribed to the Google Groups "pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyqtgraph+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyqtgraph/d7dcf184-e538-4baa-8d6f-b5ac293845a8%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages