Ask Your Question
0

What will do this code?

asked 2018-07-18 06:56:48 -0600

Hi all! I have following code on C++:

Mat planes[]  = {Mat_<double>(img), Mat::zeros(img.size(),CV_32FC1)};

Where is img is original gray scale image converted to CV_32FC1, then multiplied by 1/255(but I think it's not critical) and resized to 128x128 pixels(this might be important). So my question is what will contains in planes and what dims it will has. When I make std::cout << planes it's gives me an address(I think it's object's address). Also my goal is translate this code in to the Python.

edit retag flag offensive close merge delete

Comments

my goal is translate this code in to the Python

what is the context ?

also note, if img is of type CV_32FC1, then Mat_<double>(img) is plain wrong.

berak gravatar imageberak ( 2018-07-18 08:16:43 -0600 )edit

I didn't understand your question about context) And thanks, I will know :-)

iamlion12 gravatar imageiamlion12 ( 2018-07-18 08:23:13 -0600 )edit

what are you trying to do with it / next ?

above is just an array of 2 Mat's

berak gravatar imageberak ( 2018-07-18 08:29:10 -0600 )edit
1

Oh, sorry. planes will be used for Fourier transformation function, not by it self, dft function output will be separated in to the planes. The whole function compute third salience for an image

iamlion12 gravatar imageiamlion12 ( 2018-07-18 08:41:10 -0600 )edit

wait, this is the input for a complex dft, right ? (left Mat s the real part, the right Mat (all zeros) the imaginary one ?)

you probably need to merge() the array (make it interleaved, CV_32FC2) before feeding it into dft()

and you don't have to pre-allocate the output as opencv will do that already

berak gravatar imageberak ( 2018-07-18 08:47:19 -0600 )edit
1

I think will be better, if I will add this:

Mat planes[]  = {Mat_<double>(img),               Mat::zeros(img.size(),CV_32FC1)};
Mat planes2[] = {Mat::zeros(img.size(),CV_32FC1), Mat::zeros(img.size(),CV_32FC1)};
Mat planesr[] = {Mat::zeros(img.size(),CV_32FC1), Mat::zeros(img.size(),CV_32FC1)};

Mat complexI, magI, phasem;
merge( planes, 2, complexI ); // Merges for FT
dft( complexI, complexI );    //Forward DFT
split( complexI, planes );    // planes[0] = Re(DFT(I), planes[1] = Im(DFT(I))
magnitude( planes[0], planes[1], magI );    //DFT magnitude (amplitude)
phase( planes[0], planes[1], phasem );      //DFT phase
iamlion12 gravatar imageiamlion12 ( 2018-07-18 08:50:21 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2018-07-18 09:27:35 -0600

berak gravatar image

Also my goal is translate this code in to the Python.

so, let's try:

   planes   = [np.asarray(img, np.float32), np.zeros(img.shape, np.float32)]
   complexI = cv2.merge(planes)
   complexI = cv2.dft(complexI, cv2.DFT_COMPLEX_OUTPUT) # i think, it need this flag !
   planes   = cv2.split(complexI)
   magI     = cv2.magnitude(planes[0], planes[1])
   phasem   = cv2.phase(planes[0], planes[1])
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2018-07-18 06:56:48 -0600

Seen: 99 times

Last updated: Jul 18 '18