Ask Your Question
1

Cannot view 16-bit grey level Images.

asked 2013-05-08 08:56:43 -0600

chris_chris gravatar image

updated 2013-05-14 05:01:56 -0600

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 flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
6

answered 2013-05-14 05:51:50 -0600

updated 2013-05-14 05:55:24 -0600

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.

edit flag offensive delete link more

Comments

1

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

chris_chris gravatar imagechris_chris ( 2013-05-14 08:10:51 -0600 )edit
2

answered 2013-05-11 21:10:11 -0600

ypnos gravatar image

updated 2013-05-11 21:12:17 -0600

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.

edit flag offensive delete link more

Comments

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.)

chris_chris gravatar imagechris_chris ( 2013-05-14 05:13:13 -0600 )edit

Question Tools

Stats

Asked: 2013-05-08 08:56:43 -0600

Seen: 18,747 times

Last updated: May 14 '13