Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

So for 16 bit processing there are several things to pay attention to.

First, imwrite will output proper 16-bit images if you save as PNG, BMP, or TIF formats. PNG is usually best. However, viewing it almost always show the image just divided by 256, which on many 16-bit images is very dark. Try normalizing before saving.

Imshow definitely shows 16-bit images as an 8-bit images divided by 256.

More and more OpenCV functions are handling 16-bit images properly, and many more will work if you're willing to get into the code and alter things.

To convert to 8-bit there are several ways.

  1. Normalize min/max. This doesn't saturate any extremes, but if most of your information is far from the extremes, you'll lose it.
  2. meanStdDev and convertTo. Take the mean-xstd as your min, and mean+ystd as your max. You saturate extreme values, but you preserve the information in the middle values as much as possible and cause no distortion in relative values.
  3. CLAHE or Histogram Equalization. These saturate the extremes, and alter the relative values of pixels, but visually they're great. CLAHE has local boxes which can cause artifacts between parts of the image if they have different statistics. After these you'll need to use convertTo(dst, CV_8U, 1.0/256.0) to get the 8 bit version.

Good Luck.