/** * \file FFToperations.cpp * \brief operations involving FFT Copyright 2007-2013 IMP Inventors. All rights reserved. */ #include "IMP/em2d/FFToperations.h" #include "IMP/log.h" #include "IMP/Pointer.h" IMPEM2D_BEGIN_NAMESPACE void get_autocorrelation2d_no_preprocessing(const cv::Mat &M, cv::Mat &corr) { IMP_LOG_VERBOSE( "Computing 2D autocorrelation no preprocessing" <(i,j) = (-1) *m.at(i,j); } else { roiA.at(i,j) = m.at(i,j); } } } cv::Mat imag_temp(dftSize,m.type(),cv::Scalar::all(0.0)); // Merge and dft cv::Mat temp,TEMP; cv::Mat imgs[]= { real_temp,imag_temp }; cv::merge(imgs,2,temp); cv::dft(temp, TEMP,cv::DFT_COMPLEX_OUTPUT,m.rows); // Real and imaginary // recover real part from the first channel // both source and destination matrices must be allocateda int rows = temp.rows; int cols= temp.cols; cv::Mat TEMP_1st_channel(rows,cols,m.type()); // real cv::Mat TEMP_2nd_channel(rows,cols,m.type()); // imag cv::Mat output[] = { TEMP_1st_channel,TEMP_2nd_channel }; const int fromTo[] = { 0,0 , 1,1 };// see mixChannels help, continuous numbers cv::mixChannels(&TEMP,1,output,2, fromTo, 2); // resize the output arrays if needed real.create(m.rows,m.cols, m.type()); imag.create(m.rows,m.cols, m.type()); TEMP_1st_channel(cv::Rect(0, 0, real.cols,real.rows)).copyTo(real); TEMP_2nd_channel(cv::Rect(0, 0, imag.cols,imag.rows)).copyTo(imag); } void do_matrix_to_image_flip(cv::Mat &m) { int half_rows = m.rows/2; int half_columns = m.cols/2; int new_i,new_j; for (int i=0;i=half_rows) { new_i=i-half_rows; } else { new_i=i+half_rows; } new_j=j+half_columns; std::swap(m.at(i,j),m.at(new_i,new_j)); } } } IMPEM2D_END_NAMESPACE