Convert a .txt 16 bit into a 16 bit image

Hello! I save the .txt as an image 16 bit nevertheless when I use the website https://exifinfo.org/ for example, show that the image is 8 bit. There something wrong with my code? Other question is: Why the .deth() is printed as 6? It is a image 6 bit?? Thank you

double x;
Mat radiance_image = Mat::zeros(rows, cols, CV_64F);
std::ifstream fileStream(filename.txt);
int cnt = 0;
while (fileStream >> x)
{
int row = cnt / cols;
int col = cnt % cols;
radiance_image.at(row, col) = x;
cnt++;
}
std::cout<< radiance_image.depth();std::ifstream fileStream(filename);
int cnt = 0;
while (fileStream >> x)
{
int row = cnt / cols;
int col = cnt % cols;
radiance_image.at(row, col) = x;
cnt++;
}
std::cout<< radiance_image.depth();

CV_64F is defined to be 6. what did you expect depth() to return?

and where is your code that does the imwrite?

Hello Crackwitz! I was expecting 16, 32 or 64 because these are, for least, the most common bit depth. And when i get the metadata is shown 8 bit, so, what means this 6?

Sorry for that! Here is my imwrite:

imwrite(“2.png”, radiance_image);

it does not return any number of bits. it returns the type. the type is a quasi-enum. the numbers are arbitrary but fixed and represent types, according to this documentation:

https://docs.opencv.org/master/d3/d63/classcv_1_1Mat.html#a8da9f853b6f3a29d738572fd1ffc44c0

1 Like

Ah Okay. Anyway, for some reason my matrix is converted into 8 bit image even though being a 16 bit floating grayscale … My imwrite should be different?

correct. kinda. not imwrite but the data you give it.

you’re giving it 64 bit floats. it doesn’t necessarily handle that right. docs state that 16 bit integer and 32 bit float are special cases. this also depends on the file type you make it use.

https://docs.opencv.org/3.4/d4/da8/group__imgcodecs.html#gabbc7ef1aa2edfaa87772f1202d67e0ce

1 Like

Amazing… I understood now, the data also has negative numbers, and in that case. could not be saved as a PNG… that only supports CV_16Unsigned according the documentation that you cited.