please help regarding cropping a complex matrix

asked 2015-06-17 21:59:11 -0600

tkamal gravatar image

Hi, I don't know why I can't access the other account I opened in Feb this year. So thanks to thudor who replied to my question in February.

Now the problem I am facing is, (I am still novice in opencv, so please bear):

  1. I am taking DFT of an image.
  2. From the complex output I am cropping a circular portion surrounding a set of coordinates.
  3. I am doing inverse Fourier Transform of this cropped Image (the size of the cropped image is equal to the complex output of DFT).
  4. Now when I take the magnitude of the IDFT its fine. But the phase is not what I get in MATLAB. I mean the pattern.

So, I tried to look at the possible troubles. When I am cropping the image, I am creating a mask.

temp = new_mask(complexI, real_center);

Mat new_mask(Mat q, max_intensity m) {

Mat masks = Mat::zeros(q.size(), CV_8U);
circle(masks, Point(m.col_ref, m.row_ref), int(filter_rad), Scalar(255, 255, 255), -1, 8, 0); //-1 means filled
return masks;

}

And then using this mask I am cropping the complex matrix.

Mat cropped(complexI.size(), complexI.type(), Scalar::all(0));
complexI.copyTo(cropped, temp);

Do you think, because I used CV_8U as the type of the mask matrix it is causing trouble when I am doing inverse Fourier transform? Please suggest.

I tried using other data types like CV_64FC2 but then the sentence complexI.copyTo(cropped, temp) doesn't work. Even if I use the type complexI.type() for the masks matrix this sentence doesn't work.

I am giving an example of the comparison of phase output of IDFT in MATLAB and opencv. PLEASE HELP!!!image description

The blue line is MATLAB output and the red one is opencv.

THANKS A LOT IN ADVANCE whoever helps :)

edit retag flag offensive close merge delete

Comments

1

"Do you think, because I used CV_8U as the type of the mask matrix it is causing trouble" - no, that's perfectly ok. if you're getting different results than matlab, it must be another reason. e.g. opencv's dft has 0.0 not at the center of the image, but at top-left corner

berak gravatar imageberak ( 2015-06-18 00:51:30 -0600 )edit

Hi Berak, Thanks a lot. I was thinking that cv_8U might cause a problem because the cropped portion is of complex type and the surrounding 0's are of cv_8u type.

Can you suggest if I use q.type() for the masks matrix type why complexI.copyTo(cropped, temp) doesn't work? :(

tkamal gravatar imagetkamal ( 2015-06-18 20:28:44 -0600 )edit