Ask Your Question
1

Arbitrary grayscale pixel range

asked 2013-03-17 03:35:51 -0600

piedar gravatar image

I have a cv::Mat of uint16_t representing a grayscale depth map. The values in this map are in the range 0 - 10000. I construct and display the map like this:

cv::Mat raw(frame.height(), frame.width(), CV_16UC1, frame.data.data());
raw.copyTo(depth_image);
cv::imshow("depth", depth_image);

The problem is that cv::Mat seems to be expecting the full range of possible values for a 16-bit unsigned integer, so I can barely see differences between areas in my image (everything is very dark). Is there any way I can tell cv::Mat to expect grayscale values no larger than 10000?

Maybe using cv::Mat::convertTo()? I don't know what to use for scale though. The obvious guesses (10000, 1/10000) don't work.

raw.convertTo(raw, CV_8UC1, ???);
edit retag flag offensive close merge delete

Comments

255.0 / 10000.0 ?

berak gravatar imageberak ( 2013-03-17 13:52:29 -0600 )edit

Thanks berak, that works. I would answer my own question, but the site won't let me for another 17 hours.

piedar gravatar imagepiedar ( 2013-03-18 10:09:13 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2013-03-20 20:40:17 -0600

piedar gravatar image

updated 2013-03-20 20:41:41 -0600

Got it thanks to berak! It seems so obvious after a good night's sleep.

The scale value for cv::Mat::convertTo() should be the maximum possible value of the data type over the maximum possible value of the arbitrary range. So if the values are in the range 0 - 10000, conversion would be done like so to remain in 16 bits:

raw.convertTo(raw, CV_16UC1, 65535.0 / 10000);

and to convert to 8 bits:

raw.convertTo(raw, CV_8UC1, 255.0 / 10000);
edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-03-17 03:35:51 -0600

Seen: 2,650 times

Last updated: Mar 20 '13