Attention! This forum will be made read-only by Dec-20. Please migrate to https://forum.opencv.org. Most of existing active users should've received invitation by e-mail.
Ask Your Question
0

16-bit image processing

asked 2017-03-28 19:20:54 -0500

chippy gravatar image

updated 2017-03-28 19:22:14 -0500

Hello! I am processing a 16-bit 3D CT Scan image formatted as .mhd/.raw Opening the file and taking a 2D slice using Fiji/ImageJ gives me a regular grayscale image, but when I import it into OpenCV (python), and also get a 2D slice, both imshow and imwrite do not give me a good image.

Is there a way so OpenCV can process the image correctly?

Also,I need to be able to convert the image to unsigned 8bit so I could use OpenCV functions on it, specifically adaptive threshold. I tried using scikit's conversion tools and OpenCV's convertScaleAbs but the results are not good.

Thanks for any help!

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
1

answered 2017-03-28 20:17:55 -0500

Tetragramm gravatar image

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.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2017-03-28 19:20:54 -0500

Seen: 14,309 times

Last updated: Mar 28 '17