0

I am having some trouble with finding documentation of visualization of LAB color space in matplotlib. I got the channels separated. Here is my code for that:

img = cv2.imread("image.jpg")
img_LAB = cv2.cvtColor(img, cv2.COLOR_BGR2LAB)
l,a,b = cv2.split(img_LAB)

I don't have any problems with displaying the L channel as it is just grayscale.

plt.imshow(l,cmap='gray')

however I cannot find any colormaps for a and b. "a" is red-green and "b" is blue-yellow and matplotlib doesn't have cmap option for them. If I try to directly imshow the channels, it gives RGB image. I tried creating a red-green channel. don't know if this is correct:

cdict1 = {'red':   ((0.0, 0.0, 0.0),
                    (0.5, 0.0, 1.0),
                    (1.0, 0.1, 1.0)),

          'blue': ((0.0, 0.0, 0.0),
                    (1.0, 0.0, 0.0)),

          'green':  ((0.0, 0.0, 0.1),
                    (0.5, 1.0, 0.0),
                    (1.0, 0.0, 0.0))
          }
red_green = LinearSegmentedColormap("RdGn",cdict1)

I am also having confusion regarding the cmap dict. what does the two y values signify? the documentations do have clear explanation. I don't know if my cmap is correct. But I still don't get how to display b channel. What can be the better way of doing this?

Shantanu Shinde
  • 932
  • 3
  • 23
  • 48
  • [This answer](https://stackoverflow.com/questions/38246559/how-to-create-a-heat-map-in-python-that-ranges-from-green-to-red/38247002#38247002) shows how you can create a red-green colormap. you could do something similar for blue-yellow (see also the `cividis` colormap which ranges from blue to yellow.) – tmdavison Aug 25 '20 at 15:17
  • @tmdavison I think that helps, but I am having confusion understanding the dictionary. what does X, i.e. the first element of the tuple signify? also, if 0.8 on both means less bright, what will y = 0,0.8 or .8,0 mean? – Shantanu Shinde Aug 26 '20 at 02:33
  • I tried explaining it as best I can in that answer. If that's still not clear, perhaps you could try the `from_list` method in the answer below on that question. – tmdavison Aug 26 '20 at 08:12

0 Answers0