Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Arbitrary grayscale pixel range

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, ???);