First time here? Check out the FAQ!

Ask Your Question
1

Convert CV_16UC3 color image to CV_8U grayscale

asked Mar 24 '15

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?

Preview: (hide)

1 answer

Sort by » oldest newest most voted
3

answered Mar 25 '15

matman gravatar image

updated Mar 25 '15

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)

Preview: (hide)

Comments

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

emiswelt gravatar imageemiswelt (Mar 25 '15)edit

Question Tools

1 follower

Stats

Asked: Mar 24 '15

Seen: 9,468 times

Last updated: Mar 25 '15