OpenCV: cvLoadImage opens 16-bit image as 8-bit
I am trying to process 16-bit single-channel uncompressed TIFF images with OpenCV 2.1, but when I call cvLoadImage, apparently they 开发者_如何学Cget converted to 8-bit:
IplImage* img = cvLoadImage("myImage.tif",
CV_LOAD_IMAGE_ANYDEPTH | CV_LOAD_IMAGE_ANYCOLOR);
std::cout << img->depth << std::endl;
prints
8
The images have been produced by a fluorescence scanner that generates only this kind of images, and I have confirmed with a commercial software package that they really are 16-bit.
How can I open these images and work with the original bit depth?
In OpenCV Loading a tif image (16 bits for example) in python should work by typing:
im = cv.LoadImageM("test.tif",cv.CV_LOAD_IMAGE_UNCHANGED)
I am using OpenCV 2.3.1, this version allows opening images of 16 bits like jpromvi made:
IplImage* img = cvLoadImage("myImage.tif",
CV_LOAD_IMAGE_ANYDEPTH | CV_LOAD_IMAGE_ANYCOLOR);
Hmm... you could write your own code to load the image. Its uncompressed TIFF, so shouldn't be much trouble.
I had a similar problem (using OpenCV 2.x on Linux, with the latest libtiff). I was actually using 12bit tiff Images, which does not make it easier...
I can recommend ImageMagic.
You can verify that your image is really 16bit
display myImage.tiff (right click, "Image Info")
I converted it to png - which worked perfectly in my case
convert myImage.tiff myImage.png
use GDAL lib to open 16 bit tiff image, and then convert gdal dataset to opencv Mat
see: https://github.com/marvins/Code_Sandbox/blob/master/c%2B%2B/opencv/geo_tools/gdalToOpenCV.cpp
精彩评论