# Cannot view 16-bit grey level Images.

I have images in '.tiff' format with 10-bit grey level (i.e 0 to 1023) in a 16-bit containers. I cannot access them. I have tried using function 'imread' and read the images without changing anything it has. But I cannot, it gives output no image data. I am sure that this files has the images. Also, I have tried to read other 8bit and rgb images of '.tiff' format using the same funtion and it works.

So, I would like to know how to access the 10-bit grey level images in 16-bit containers using any fuctions from opencv.

EDIT: Now I have changed the image to .png format. Now the image can be processed. When I try to view it through opencv, I see only a black image. In case, when the image is converted to 8-bit image. I can view it. But I would like to view it as 16 bit grey images.

edit retag close merge delete

Sort by » oldest newest most voted

You should look at the fact that your image is a 16-bit image. CV_16U corresponds to 16 bit unsigned integers, meaning your range is [0; 255 * 255]. Be sure this corresponds to your actual data.

The description of the imshow function clearly states that:

If the image is 16-bit unsigned or 32-bit integer, the pixels are divided by 256. That is, the value range [0,255256] is mapped to [0,255].*

If the image is 32-bit floating-point, the pixel values are multiplied by 255. That is, the value range [0,1] is mapped to [0,255].

So either the wrong values are inside your matrix, and they are not between 0 and 255 OR you have used another type.

Try to multiply the complete matrix with 255 before doing an imshow. IF this works, your data is mapped in the range [0 1] and needs to be mapped to [0 256].

Also try the opposite, dividing your matrix by 255. It can be possible that the imshow is unable to correctly retrieve the data type for some reason.

more

1

I got it. Thanks for the detailed answer such that everybody understands..

( 2013-05-14 08:10:51 -0500 )edit

I don't know about the TIFF reader, but OpenCV can read and even write 16bit PNG files. You can convert your TIFF to PNG without loss.

This works for me:

cv::Mat input = cv::imread(filename, -1);


To write a matrix 16bit, make sure it has CV_16U format and pass it to imwrite.

more

yes, you are correct. some problem with the tiff reader. I converted the image to png and other formats. Its working now. But, I cannot view this. I can see only a black image. (I am sure that there is a image. When I convert it to 8-bit I can view that.)

( 2013-05-14 05:13:13 -0500 )edit

Official site

GitHub

Wiki

Documentation