void DeeleyOTF::process( BidomainArray2D *in, BidomainArray2D *out ) { const int cols = in->getCols(), rows = in->getRows(); const FFTWComplexArray *input = in->getFrequency(); // This must be executed before out->setFrequency()->getData() if (in == out) filterFFTW( input->getData(), out->setFrequency()->getData(), cols, rows, filter ); }
void MultiAdaptationCSF::process( BidomainArray2D *in, BidomainArray2D *out, BidomainArray2D *adaptationMap ) { const int cols = in->getCols(), rows = in->getRows(); assert( cols == adaptationMap->getCols() ); assert( rows == adaptationMap->getRows() ); const FFTWComplexArray *freqOriginal = in->getFrequency(); FFTWComplexArray freqFiltered( cols, rows ); FFTWArray2D spatialTemp( cols, rows ); fftwf_plan inverseFFT = fftwf_plan_dft_c2r_2d( rows, cols, freqFiltered.getData(), spatialTemp.getData(), FFTW_ESTIMATE ); // MEASURE would damage the data //NOT compatible with new Cygwin version of gcc. //pfs::Array2DImpl **filteredImage = new (pfs::Array2DImpl*)[adaptationLevelsCount]; // Results of filtering in spatial domain are stored there pfs::Array2DImpl **filteredImage = new pfs::Array2DImpl*[adaptationLevelsCount]; for( int i = 0; i < adaptationLevelsCount; i++ ) { // For each adaptation level filterFFTW( freqOriginal->getData(), freqFiltered.getData(), cols, rows, filters[i] ); // dumpPFS( "fft_image.pfs", freqFiltered, cols/2+1, rows, "Y" ); fftwf_execute(inverseFFT); // Copy to filteredImage and normalize filteredImage[i] = new pfs::Array2DImpl( cols, rows ); for( int pix = 0; pix < cols*rows; pix++ ) (*filteredImage[i])(pix) = spatialTemp(pix)/(cols*rows); // // Some debug info // char buf[100]; // sprintf( buf, "csf_filtered_%g.pfs", adaptationLevels[i] ); // dumpPFS( buf, filteredImage[i], "Y" ); std::cerr << "."; } std::cerr << "\n"; const pfs::Array2D *adaptationMapArray = adaptationMap->getSpatial(); pfs::Array2D *outA = out->setSpatial(); // output array // Linear intepolation between adaptation levels { int ind = 0; for( int ind = 0; ind < rows*cols; ind++ ) { float adapt = (*adaptationMapArray)( ind ); if( adapt < adaptationLevels[0] ) (*outA)(ind) = (*filteredImage[0])(ind); else if( adapt > adaptationLevels[adaptationLevelsCount-1] ) (*outA)(ind) = (*filteredImage[adaptationLevelsCount-1])(ind); else { // interpolate int l; for( l = 1; l < adaptationLevelsCount; l++ ) if(adapt <= adaptationLevels[l]) break; assert( l > 0 && l < adaptationLevelsCount ); (*outA)(ind) = (*filteredImage[l-1])(ind) + ((*filteredImage[l])(ind)-(*filteredImage[l-1])(ind))* (adapt-adaptationLevels[l-1])/(adaptationLevels[l]-adaptationLevels[l-1]); } } } // dumpPFS( "after_csf.pfs", in, "Y" ); // Clean up for( int i = 0; i < adaptationLevelsCount; i++ ) delete filteredImage[i]; delete[] filteredImage; fftwf_destroy_plan(inverseFFT); }