Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 );
like image 937
N_Kh Avatar asked May 21 '15 11:05

N_Kh


1 Answers

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

Image.convertTo(Image,CV_32FC1, 1.0/255.0);
like image 52
Andrey Smorodov Avatar answered Sep 20 '22 12:09

Andrey Smorodov