c++opencvimage-processing

How to convert an image from CV_8UC1 to CV_32FC1 type in opencv?


I readed an image which type of it is CV_8UC1, and I want to convert it to CV_32FC1.but when I use convertTo() function my image become completely white and I don't know why!

Mat Image(512,512,CV_32FC1);     
Image = imread("C:\\MGC.jpg",CV_LOAD_IMAGE_GRAYSCALE);   

/// show image
namedWindow("pic");
int x = 0; int y = 0;
imshow("pic", Image);

cout<<Image.type()<<endl;
Image.convertTo(Image,CV_32FC1);
cout<<Image.type()<<endl;

////show converted image 
namedWindow("pic1");
imshow("pic1",Image );

Solution

  • Because displayable range for 32FC type element images is [0:1] (for imshow). Try this.

    Image.convertTo(Image, CV_32FC1, 1.0 / 255.0);