cv::Mat convertion to double type
Hi,
I am not really familiar with openCV, so I am probably using its functions wrong.
The code is as follows.
cv::Mat im0Bgr = cv::imread("colormapTest.png"); // 32x32 test image
cv::Mat im0BgrDouble;
im0Bgr.convertTo(im0BgrDouble, CV_32F);
// Then //
cv::namedWindow("Figure 1");
cv::namedWindow("Figure 2");
cv::imshow("Figure 1", im0Bgr);
cv::imshow("Figure 2", im0BgrDouble);
//... and destroyed just after
My original image is of type CV_8U. It is displayed correctly. My converted image is supposed to be in the range [0,1], while it is not ([0,255] instead). More than that, only the half top part is displayed, and the bottom half is displayed white, though the converted object contains some 0 there.
Can someone point out where I am mistaken? I guess such a simple thing does not come from OpenCV. Thank you.
It cant really work. The only thing you do is convert the values from an 8bit unsigned to 32bit float which will create crap. What is your goal actually? Do you just want to have a binary image ( 0 or 1) or do you want that all values are between 0 and 1 (so also 0.1, 0.11232 etc.)
My program needs more accuracy (filtering, reduction by the average... this kind of operations). So the first thing I need is to use floating points. But the behavior I have, just by converting it, is unexpected. And since 32 = 8 x 4, why does it display half of my image?
you'd want im0Bgr.convertTo(im0BgrDouble, CV_32F, 1.0/255); // it does not scale automatically.
And CV_32F is a float. If you want double precision - use CV_64F.