Reputation: 732
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?
Upvotes: 1
Views: 2063
Reputation: 701
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().
Upvotes: 2
Reputation: 1762
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
Upvotes: 0