1

I have this cv::Mat image of type CV_16SC3 (16 bit signed, 3 channels). Before using convertTo to change its depth from 16 bit to 8 bit, the image looks like this:

enter image description here

I need to make the image this type: CV_8UC3. Tried converting it by:

image.convertTo(image, CV_8U, 0.00390625);

(source)

However it resulted in this image here: enter image description here

Any ideas why this is and how I can fix it?

alittlebirdy
  • 93
  • 1
  • 7

1 Answers1

1

If you look over OpenCV documentation at cv::convertTo function, the formula used to compute the pixels values is:

m(x,y) = staturate_cast<rType>(alpha (*this)(x, y) + beta)

This means that the pixel value is multiplied by alpha and added with beta (= 0 by default). Your alpha value is very low (alpha = 0.00390625). This is why you see a black image. Try to use a bigger value for alpha. For example, you can use alpha = 0.7, or you can use 1, the default value.

Raluca Pandaru
  • 295
  • 3
  • 10
  • thanks. I assumed from the source that the reason alpha = 0.00390625 was because you have to scale the values from 16 bit to 8 bit or 1/256. WIll give the other alpha values a try. – alittlebirdy Apr 09 '20 at 17:04
  • Raluca, you are a genius! Works great with alpha = 0.7. Thanks! – alittlebirdy Apr 09 '20 at 18:05