How can i change the datatype used in storing the pixels in a Mat class instance?
For example after reading an image using the line below
Mat I = imread(file,0);
i obtain a grayscale image with pixels of type unsigned char. I want to change this to a double.
What's the best way to do the conversion? I wasn't able to find a function to do that.
Thanks in advance
To change your selection tap the mat settings icon in the upper left corner. Then tap Select Material Load Type and choose a new Type from the list. Tap OK to apply the change.
The Mat class of OpenCV library is used to store the values of an image. It represents an n-dimensional array and is used to store image data of grayscale or color images, voxel volumes, vector fields, point clouds, tensors, histograms, etc.
OpenCV has been around since 2001. In those days the library was built around a C interface and to store the image in the memory they used a C structure called IplImage. This is the one you'll see in most of the older tutorials and educational materials.
Mat is basically a class with two data parts : the matrix header (containing information such as the size of the matrix, the method used for storing, at which address is the matrix stored, and so on) and a pointer to the matrix containing the pixel values (taking any dimensionality depending on the method chosen for ...
It is very simple. See the documentation at OpenCV website.
Basically do
Mat double_I;
I.convertTo(double_I, CV_64F);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With