Ask Your Question
1

complex conjugate

asked 2016-07-06 18:54:54 -0600

HiHello gravatar image

how do i get the complex conjugate??

is the result of cvDFT complex???

IplImage * src_img = cvLoadImage("for_fft.jpg", 0);
IplImage * dst_inverse = cvCreateImage(cvGetSize(src_img), IPL_DEPTH_8U, src_img->nChannels);
IplImage * dst_freq = cvCreateImage(cvGetSize(src_img), IPL_DEPTH_8U, src_img->nChannels);
IplImage * dst_swap = cvCreateImage(cvGetSize(src_img), IPL_DEPTH_8U, src_img->nChannels);

//spatial: input, freq: frequency domain
CvMat *spatial = cvCreateMat(src_img->height, src_img->widthStep, CV_64FC2);
CvMat *freq = cvCreateMat(src_img->height, src_img->widthStep, CV_64FC2);

//DFT
for (i = 0; i < src_img->imageSize; i++) {
    spatial->data.db[i * 2] = (double)(unsigned char)src_img->imageData[i];
    spatial->data.db[i * 2 + 1];    //for complex 
}

cvDFT(spatial, freq, CV_DXT_FORWARD);//DFT

//print it out in log scale
double tmp = 0;
double max_f = INT_MIN;
double min_f = INT_MAX;

for (i = 0; i < src_img->imageSize; i++) {
    tmp = log10(1 + sqrt(SQUARE(freq->data.db[i * 2]) + SQUARE(freq->data.db[i * 2 + 1])));
    if (tmp < min_f)min_f = tmp;
    if (tmp > max_f) max_f = tmp;
}

for (i = 0; i < src_img->imageSize; i++) {
    dst_freq->imageData[i] = (unsigned char)(256 / (max_f - min_f)*log10(1 + sqrt(SQUARE(freq->data.db[i * 2]) + SQUARE(freq->data.db[i * 2 + 1]))))+5;
}

FreqShift(dst_freq, dst_swap);

cvDFT(freq, spatial, CV_DXT_INVERSE_SCALE);

for (i = 0; i < src_img->imageSize; i++) {
    dst_inverse->imageData[i] = (char)spatial->data.db[i * 2];
}

this is what i did 2D image dft

i want to get the complex conjugate what should i do ? I just start opencv 5 days ago. please let me know.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2016-07-06 19:12:13 -0600

Tetragramm gravatar image

First, you're using the old C API. You shouldn't do that if c++ is available.

Secondly, the mulSpectrums function should do what you need.

cvMulSpectrums( const CvArr* src1, const CvArr* src2, CvArr* dst, int flags );

The output of DFT is, by default CSS packed in a single channel matrix. If you pass the flag COMPLEX_OUTPUT, whatever the C API equivalent is, then you get a two channel matrix. Look at the documentation for DFT for more on that.

edit flag offensive delete link more

Comments

thanks for your advice! btw what is the difference between c API and c++ API? im beginer so, if you dont mind please give me some details.

HiHello gravatar imageHiHello ( 2016-07-06 19:25:15 -0600 )edit

The C API is for using the the C language, usually only used in old programs or special situations. C++ is the more modern language that OpenCV is written in. If you're just starting out, take a look at the basic tutorials HERE. Basically, there are different include files, different function names, and much more functionality. In addition, you don't have to manage your own memory, the Mat class creates and destroys it all automatically.

You can read all the documentation HERE, with links to all the tutorials and all the modules.

Tetragramm gravatar imageTetragramm ( 2016-07-06 19:37:32 -0600 )edit

Please @Tetragramm if you tell people to use the C++ interface, then link to the corresponding C++ function :D

StevenPuttemans gravatar imageStevenPuttemans ( 2016-07-07 02:27:15 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-07-06 18:54:54 -0600

Seen: 1,073 times

Last updated: Jul 06 '16