如何在opencv中将图像从CV_8UC1转换为CV_32FC1类型?

N_K*_*_Kh 5 opencv image-processing

我读了一个图像,它的类型是CV_8UC1,我想将它转换为CV_32FC1.但是当我使用convertTO()函数时,我的图像变成完全白色,我不知道为什么!

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 );
Run Code Online (Sandbox Code Playgroud)

And*_*dov 6

因为32FC类型元素图像的可显示范围是[0:1](对于imshow).试试这个.

Image.convertTo(Image,CV_32FC1, 1.0/255.0);
Run Code Online (Sandbox Code Playgroud)

  • Image.convertTo(Image,CV_8UC1,255.0); (4认同)