Ask Your Question

Convert CV_16UC3 color image to CV_8U grayscale

asked 2015-03-24 17:27:18 -0500

emiswelt gravatar image


I'm trying to convert a CV_16UC3 color image to a CV_8U grayscale image.

However, the cvtColor function does not accept CV_16UC3 input images.

How could I do the desired conversion?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2015-03-25 02:41:51 -0500

matman gravatar image

updated 2015-03-25 12:56:43 -0500

From the head:

#include <opencv2/opencv.hpp>

using namespace cv;

// Your CV_16U3 Mat
Mat image16u3 = //$your data$;

// Convert it to CV_8U3 Mat
Mat image8u3;
image16u3.convertTo(image8U3, CV_8UC3); // CV_8U should work as well

// Convert color to grayscale
Mat image8u1;
cvtColor(image8u3, image8u1, COLOR_RGB2GRAY);

Edit: Code corrected (see below)

edit flag offensive delete link more


Works like a charm. Thank you. Just change CV_8U3 to CV_8UC3.

emiswelt gravatar imageemiswelt ( 2015-03-25 08:06:34 -0500 )edit

Question Tools

1 follower


Asked: 2015-03-24 17:27:18 -0500

Seen: 7,789 times

Last updated: Mar 25 '15