when I use following code in matplotlib, I can get a picture like this :
import cv2
import numpy as np
import matplotlib.pyplot as plt
from skimage.color import rgb2hed
from matplotlib.colors import LinearSegmentedColormap
roi_select = cv2.imread(r"C:\Users\hutao\Desktop\cell.png")
roi_select_11 = rgb2hed(roi_select)
cmap_dab = LinearSegmentedColormap.from_list('mycmap', ['white','saddlebrown'])
plt.imshow(roi_select_11[:,:,0],cmap=cmap_dab)
But when I use OpenCV ,there is my code :
def get_mpl_colormap(cmap_name):
cmap = LinearSegmentedColormap.from_list('mycmap', ['white','saddlebrown'])
sm = plt.cm.ScalarMappable(cmap=cmap)
color_range = sm.to_rgba(np.linspace(0, 1, 256), bytes=True)[:,2::-1]
return color_range.reshape(256, 1, 3)
roi_select = cv2.imread(r"C:\Users\hutao\Desktop\cell.png")
image_bgr = cv2.applyColorMap(roi_select[:,:,0],get_mpl_colormap('bwr'))
cv2.imshow('image with colormap', image_bgr)
cv2.waitKey()
I can't get the same picture,there is the OpenCV's picture
How can I get the same picture in OpenCV like figure2?
I'am a new hand in OpenCV , thank you for your answers!