1

In openCv when we change the type of the matrix from CV_8U to CV_64F or CV_32F should we also divide the elements of the matrix with 255 because the range of CV_8u is 0-255 and CV_32F is 0-1?

2 Answers 2

2

Yes.

if you have a 32-bit floating-point image directly converted from 8-bit image without any scaling, then it will have 0..255 value range, instead of the assumed by the function 0..1. So, before calling cvtColor , you need first to scale the image down:

img *= 1./255;
cvtColor(img, img, CV_BGR2Luv);

from: http://opencv.willowgarage.com/documentation/cpp/miscellaneous_image_transformations.html

If you're using c++ then you can do:

originalMatrix.convertTo(temp, CV_64F, 1./255);

My code was giving me headaches, until I did this conversion. If you're using C version, you probably have to use cvConvertScale().

0
0

CV_32F are 2^(32 - 1) floating point values between 0 and 1 CV_64F are 2^(64 - 1) floating point values between 0 and 1

1

Not the answer you're looking for? Browse other questions tagged or ask your own question.