Ask Your Question
1

Convert CV_16UC3 color image to CV_8U grayscale

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

emiswelt gravatar image

Hi

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
3

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

matman gravatar image

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

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

Comments

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

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

Question Tools

1 follower

Stats

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

Seen: 9,031 times

Last updated: Mar 25 '15