cv.applyColorMap - MATLAB File Help |
Applies a GNU Octave/MATLAB equivalent colormap on a given image
dst = cv.applyColorMap(src, colormap)
dst = cv.applyColorMap(src, userColor)
dst = cv.applyColorMap(..., 'OptionName',optionValue, ...)
uint8
.uint8
(1 or 3 channels) and
length 256.src
.dst
, from OpenCV's BGR to between MATLAB's RGB. default trueThe human perception isn't built for observing fine changes in grayscale images. Human eyes are more sensitive to observing changes between colors, so you often need to recolor your grayscale images to get a clue about them. OpenCV now comes with various colormaps to enhance the visualization in your computer vision application.
The second variant of the function applies a user-defined colormap on the given image.
In OpenCV you only need cv.applyColorMap to apply a colormap on a given image. The following sample code takes an image and applies a Jet colormap on it and shows the result:
% We need an input image. (can be grayscale or color)
img_in = im2uint8(mat2gray(peaks(500)));
% Apply the colormap
%img_color2 = im2uint8(ind2rgb(img_in, jet(256)));
img_color = cv.applyColorMap(img_in, 'Jet');
% Show the result
imshow(img_color)
cmaps = {'Autumn', 'Bone', 'Jet', 'Winter', 'Rainbow', 'Ocean', ...
'Summer', 'Spring', 'Cool', 'HSV', 'Pink', 'Hot', 'Parula'};
img = cell2mat(cellfun(@(cmap) ...
cv.applyColorMap(repmat(uint8(0:255), 20, 1), cmap), cmaps(:), ...
'UniformOutput',false));
image(img)
set(gca, 'YTick', 10:20:20*numel(cmaps), 'YTickLabel',cmaps)
title('Colormaps')