Ask Your Question

tahseen_kamal's profile - activity

2015-02-27 00:52:51 -0600 asked a question opencv idft output and calculation of phase

I have been trying to calculate the phase information of a complex matrix in opencv. As I am new in using opencv I am sure I am failing to look for the correct answer. So, I have this program.

I am sure the matrix invDFT holds complex values.

So what is the easiest way of calculating the phase of the total matrix? And how can I imshow the DFT output for this program? I have used phase and I am not sure if its correct.

Thanks. I already said I am new in opencv. So please pardon if my questions are too basic. Thanks once again.

int main()
{
    // Read image from file
    // Make sure that the image is in grayscale
    Mat img = imread("input.bmp", 0);
    Mat mag, ph;

    Mat planes[] = { Mat_<float>(img), Mat::zeros(img.size(), CV_32F) };
    Mat complexI;    //Complex plane to contain the DFT coefficients {[0]-Real,[1]-Img}
    merge(planes, 2, complexI);
    dft(complexI, complexI);  // Applying DFT

    // Reconstructing original imae from the DFT coefficients
    Mat invDFT, invDFTcvt;

    idft(complexI, invDFT, DFT_SCALE | DFT_REAL_OUTPUT); // Applying IDFT

    Mat planesi[] = { Mat_<float>(invDFT), Mat::zeros(invDFT.size(), CV_32F) };
    split(invDFT, planesi);

    invDFT.convertTo(invDFTcvt, CV_8U);
    imshow("Output", invDFTcvt);

    phase(planesi[0], planesi[1], ph, false);


    namedWindow("phase image", CV_WINDOW_AUTOSIZE);
    imshow("phase image", ph);


    //show the image
    imshow("Original Image", img);

    // Wait until user press some key
    waitKey(0);
    return 0;
}