Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

If you need coloring for display, you have to create a copy of the Mat, then convert it to a three channel image (type CV_8UC3) and play with the channels. Don't touch the original kernel, because it won't work after.

But probably you want only to apply a color map. This is the simplest solution for this problem.

Here is what you should do:

Mat kernel_byte,kernel_color;
kernel.convertTo(kernel_byte,CV_8U,128,128);   // check the last two parameters
                                               // for correct normalization
applyColorMap(kernel_byte, kernel_color, COLORMAP_JET);

Here is a tutorial about color maps: Tutorial

click to hide/show revision 2
No.2 Revision

updated 2015-11-26 03:51:43 -0600

berak gravatar image

If you need coloring for display, you have to create a copy of the Mat, then convert it to a three channel image (type CV_8UC3) and play with the channels. Don't touch the original kernel, because it won't work after.

But probably you want only to apply a color map. This is the simplest solution for this problem.

Here is what you should do:

Mat kernel_byte,kernel_color;
kernel_byte = new Mat(), kernel_color = new Mat();
kernel.convertTo(kernel_byte,CV_8U,128,128);   // check the last two parameters
                                               // for correct normalization
applyColorMap(kernel_byte, kernel_color, COLORMAP_JET);

Here is a tutorial about color maps: Tutorial

click to hide/show revision 3
No.3 Revision

updated 2015-11-26 03:59:14 -0600

berak gravatar image

If you need coloring for display, you have to create a copy of the Mat, then convert it to a three channel image (type CV_8UC3) and play with the channels. Don't touch the original kernel, because it won't work after.

But probably you want only to apply a color map. This is the simplest solution for this problem.

Here is what you should do:

Mat kernel_byte = new Mat(), kernel_color = new Mat();
kernel.convertTo(kernel_byte,CV_8U,128,128);   // check the last two parameters
                                               // for correct normalization
applyColorMap(kernel_byte, Imgproc.applyColorMap(kernel_byte, kernel_color, COLORMAP_JET);
Imgproc.COLORMAP_JET);

Here is a tutorial about color maps: Tutorial