Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

it's just a clever trick (maybe too clever, if it's hard to understand ...)

i guess, the context here is some dft analysis, which requires complex, float input.

normally, you would have to do:

Mat srcImage = imread("1.jpg", 0); // read the grayscale image. it's still uchar.
Mat realPart; 
srcImage.convertTo(realPart, CV_32F); // manual conversion
Mat imPart = Mat::zeros(srcImage.size(), CV_32F); 
Mat planes [] = { realPart, imPart };
merge(planes, 2, complexI);

the Mat_<float>(img) constructor does an internal, automatic conversion to float (it obviously cannot hold any other data type). it's a shortcut, saving some lines of code, simply.

it's just a clever trick (maybe too clever, if it's hard to understand ...)

i guess, the context here is some dft analysis, which requires complex, float input.

normally, you would have to do:

Mat srcImage = imread("1.jpg", 0); // read the grayscale image. it's still uchar.
Mat realPart; 
srcImage.convertTo(realPart, CV_32F); // manual conversion
Mat imPart = Mat::zeros(srcImage.size(), CV_32F); 
Mat planes [] = { realPart, imPart };
merge(planes, 2, complexI);

the Mat_<float>(img) constructor does an internal, automatic conversion to float (it (it's a template object, it's type is determined at compile time, so it obviously cannot hold any other data type). it's a shortcut, saving some lines of code, simply.

it's just a clever trick (maybe too clever, if it's hard to understand ...)

i guess, the context here is some dft analysis, which requires complex, float input.

normally, you would have to do:

Mat srcImage = imread("1.jpg", 0); // read the grayscale image. it's still uchar.
Mat realPart; 
srcImage.convertTo(realPart, CV_32F); // manual conversion
Mat imPart = Mat::zeros(srcImage.size(), CV_32F); 
Mat planes [] = { realPart, imPart };
merge(planes, 2, complexI);

the Mat_<float>(img) constructor does an internal, automatic conversion to float (it's a template object, it's type is determined at compile time, so it obviously cannot hold any other data type). it's a shortcut, saving some lines of code, simply.

those template Mat's also have some other, interesting poroperties:

since the type is already handled in the constructor, you no more need at<type> to access the elements, but can use a straightforward m(2,2)

then, it has an overloaded comma operator, so you can fill it like:

Mat_<float> T(3,3); T << .2, .2, .4, .1, .2, .1, .2, .1, .3;

(which is quite useful for setting up transformation Matrices, or filter kernels)

it's just a clever trick (maybe too clever, if it's hard to understand ...)

i guess, the context here is some dft analysis, which requires complex, float input.

normally, you would have to do:

Mat srcImage = imread("1.jpg", 0); // read the grayscale image. it's still uchar.
Mat realPart; 
srcImage.convertTo(realPart, CV_32F); // manual conversion
Mat imPart = Mat::zeros(srcImage.size(), CV_32F); 
Mat planes [] = { realPart, imPart };
merge(planes, 2, complexI);

the Mat_<float>(img) constructor does an internal, automatic conversion to float (it's a template object, it's type is determined at compile time, so it obviously cannot hold any other data type). it's a shortcut, saving some lines of code, simply.

those template Mat's also have some other, interesting poroperties:

since the type is already handled in the constructor, you no more need at<type> to access the elements, but can use a straightforward m(2,2)

then, it has an overloaded comma operator, so you can fill it like:

Mat_<float> T(3,3);
T << .2, .2, .4,
 .1, .2, .1,
 .2, .1, .3;

.3;

(which is quite useful for setting up transformation Matrices, or filter kernels)

it's just a clever trick (maybe too clever, if it's hard to understand ...)

i guess, the context here is some dft analysis, which requires complex, float input.

normally, you would have to do:

Mat srcImage = imread("1.jpg", 0); // read the grayscale image. it's still uchar.
Mat realPart; 
srcImage.convertTo(realPart, CV_32F); // manual conversion
Mat imPart = Mat::zeros(srcImage.size(), CV_32F); 
Mat planes [] = { realPart, imPart };
merge(planes, 2, complexI);

the Mat_<float>(img) constructor does an internal, automatic conversion to float (it's a template object, it's type is determined at compile time, so it obviously cannot hold any other data type). it's a shortcut, saving some lines of code, simply.

those template Mat's also have some other, interesting poroperties:

since the type is already handled in the constructor, you no more need at<type> to access the elements, but can use a straightforward m(2,2)

then, it has an overloaded comma operator, so you can fill it like:

Mat_<float> T(3,3);
T << .2, .2, .4,
     .1, .2, .1,
     .2, .1, .3;

(which is quite useful for setting up transformation Matrices, or filter kernels)

it's just a clever trick (maybe too clever, if it's hard to understand ...)

i guess, the context here is some dft analysis, which requires complex, float input.

normally, you would have to do:

Mat srcImage = imread("1.jpg", 0); // read the grayscale image. it's still uchar.
Mat realPart; 
srcImage.convertTo(realPart, CV_32F); // manual conversion
Mat imPart = Mat::zeros(srcImage.size(), CV_32F); 
Mat planes [] = { realPart, imPart };
merge(planes, 2, complexI);

the Mat_<float>(img) constructor does an internal, automatic conversion to float (it's a template object, it's type is determined at compile time, so it obviously cannot hold any other data type). it's a shortcut, saving some lines of code, simply.

those template Mat's also have some other, interesting poroperties:

since the type is already handled in the constructor, you no more need at<type> to access the elements, but can use a straightforward m(2,2)

then, it has an overloaded comma operator, so you can fill it like:

Mat_<float> T(3,3);
T << .2, .2, .4,
     .1, .2, .1,
     .2, .1, .3;

(which is quite useful for quickly setting up transformation Matrices, or filter kernels)

it's just a clever trick (maybe too clever, if it's hard to understand ...)

i guess, the context here is some dft analysis, which requires complex, float input.

normally, you would have to do:

Mat srcImage = imread("1.jpg", 0); // read the grayscale image. it's still uchar.
Mat realPart; 
srcImage.convertTo(realPart, CV_32F); // manual conversion
Mat imPart = Mat::zeros(srcImage.size(), CV_32F); 
Mat planes [] = { realPart, imPart };
merge(planes, 2, complexI);

the Mat_<float>(img) constructor does an internal, automatic conversion to float (it's a template object, it's type is determined at compile time, so it obviously cannot hold any other data type). it's a shortcut, saving some lines of code, simply.

those template Mat's Mat_'s also have some other, interesting poroperties:properties:

since the type is already handled in the constructor, you no more need at<type> to access the elements, but can use a straightforward m(2,2)

then, it has an overloaded comma operator, so you can fill it like:

Mat_<float> T(3,3);
T << .2, .2, .4,
     .1, .2, .1,
     .2, .1, .3;

(which is quite useful for quickly setting up transformation Matrices, or filter kernels)