I am trying to do logarithmic color mapping. I am using an imageView widget for displaying my data, but I cannot seem to figure out how to set the color scaling to be log instead of linear. Is this possible?
Hi Luke,
Taking the log of the data first worked just fine (although I did need to do a little extra data massaging because I have some data that went negative due to a background subtraction). It would be nice if I could keep the histogram values as the original data values instead of the log values, but that is not a big deal.
import pyqtgraph as pgimport numpy as npimg = np.exp(np.random.normal(size=(100,100), scale=1.0))v = pg.image(img)# approximate log lookup table as a set of 10 log-spaced linear transitionspos = np.exp(np.linspace(-5, 0, 10))color = np.empty((10,4), dtype=np.ubyte)color[:,:3] = np.linspace(0, 255, 10).reshape(10, 1)color[:,3] = 255cm = pg.ColorMap(pos, color)v.ui.histogram.gradient.setColorMap(cm)
# image with larger log-rangeimg = np.exp(np.random.normal(size=(100,100), scale=3.0))v = pg.image(img)# manually construct a larger lookup table to handle this dataN = 1000000lut = np.empty((N,4), dtype=np.ubyte)grad = np.log(np.linspace(1, 1e5, N))lut[:,:3] = (255 * grad / grad.max()).reshape(N,1)lut[:, 3] = 255v.imageItem.setLookupTable(lut)
# note that the LUT is reset if you modify the gradient in the imageview.