problem to load 32 bit img
Hello,
I have a problem to read a 32-bit image. Actually, I can read the image but I don't understand why, the image is a little bit different.
A snipped of my code : (the image is saved in grayscale)
#include <iostream>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
int main() {
int heigh = 6004 ;
int width = 7920 ;
float* imgDark = new float[heigh*width] ;
cv::Mat imgDarkcv = cv::imread("/home/nl37/Desktop/0uA_no_binning.tif",2) ;
for(int i = 0 ; i<heigh ; i++)
{
for(int j =0 ; j<width ; j++)
{
imgDark[i*width + j] = imgDarkcv.at<float>(i, j) ;
}
}
cv::Mat *img_cp = new cv::Mat(heigh , width, CV_32FC1, imgDark) ;
cv::imwrite("/home/nl37/Desktop/LUT1.tif", *img_cp) ;
return 0 ;
}
Then, with imagej, I calculate the difference between 0uA_no_binning.tif and LUT1. The is not 0. I do not understand my error here. Noticed that I need to convert the image in float*.
Thank you for your help !
What is the difference? I mean it's in the size? Values? Do the images look the same? Is the difference important or very small? (like <1% difference for each pixel)
Anyway, I don't understand why you convert the image like this from float to float...
The pixels are different. The size of the image is the the same, and the images look the same. The difference is rather important, and I can't process my image because of the difference.
Actually, I get image from camera in 8-bit. Here, I just need to read a result image using openCV in 32-bit. In my algorithm, I do not use cv::Mat, here I only use openCV to read the image, to validate my algorithm. Is it more clear ?
so please check
imgDarkcv.type()
before trying to access it asimgDarkcv.at<float>(i, j)
(it's probably NOT float)also, imwrite() may convert your float imge to uchar internally (not sure about tiff, though)