pixel3f *Image::createEdges(float stylization) { pixel3f *gaussianE = createGaussian(SIGMA); pixel3f *gaussianR = createGaussian(sqrtf(1.6) * SIGMA); for (int i = 0; i < _width * _height; i++) { // Difference of gaussians mapped to a smoothed step function. float dog = gaussianE[i].L - TAU * gaussianR[i].L; gaussianE[i].L = dog > 0.0f ? 100.0f : 100.0f * (1.0f + tanhf(stylization * dog)); } delete[] gaussianR; return gaussianE; }
void MainWidgetTFM::filterFFT(){ for (int pulsing = 0; pulsing < numElements; pulsing++) { if(pulsing % 10 == 0) qDebug() << "filtering: " << ((float)pulsing) * 100.0/((float)numElements) << "%"; for (int element = 0; element < numElements; element++) { // copy the array to fftw_complex structure, could be a faster way e.g. memcpy for (int i = 0; i < sampleSize; i++) { in[i][0] = m_data[index3d(i,element,pulsing)]; in[i][1] = 0; } //for (int i = 0; i < 100; i++) std::cout << i << ": " << in[i][0] << std::endl; /* FFT */ fftw_plan my_plan = fftw_plan_dft_1d(sampleSize, in, out, FFTW_FORWARD, FFTW_ESTIMATE); fftw_execute(my_plan); for (int i = 0; i < sampleSize; i++) { out[i][0] /= (float)sampleSize; out[i][1] /= (float)sampleSize; //std::cout << i << ": " << out[i][0] << " , " << out[i][1] << "i" << std::endl; } for (int i = 0; i < sampleSize; i++) { //magnitude[i] = sqrt(out[i][0]*out[i][0] + out[i][1]*out[i][1]); //std::cout << i << ": " << magnitude[i] << std::endl; //outfile << to_string(magnitude[i]) << endl; } //int peak_frequency = 0; //double peak_val = 0.0; //for(int i = 0; i < 500; i++){ // //std::cout << i << ": " << magnitude[i] << std::endl; // if(magnitude[i] > peak_val){ // std::cout << "new peak : " << i << std::endl; // peak_val = magnitude[i]; // peak_frequency = i; // } //} //std::cout << "peak_frequency(index) : " << peak_frequency << std::endl; //float time_period = 1.0 / peak_frequency; fftw_destroy_plan(my_plan); /* FILTERING */ // Create gaussian filter vector // f(x; sig, c) = e ^ ( -(x-c)^2 / 2*sig^2 ) //float sigma, c; //createGaussian(70, 200); createGaussian(); double weight = 2.0; for (int i = 0; i < sampleSize; i++) { out[i][0] = out[i][0] * gaussFilter[i] * weight; out[i][1] = out[i][1] * gaussFilter[i] * weight; } for (int i = 500; i < sampleSize; i++) { //out[i][0] = 0.0; //out[i][1] = 0.0; } /* INVERSE FFT */ // To check that there's no existing data for (int i = 0; i < sampleSize; i++) { in[i][0] = 0; in[i][1] = 0; } my_plan = fftw_plan_dft_1d(sampleSize, out, in, FFTW_BACKWARD, FFTW_ESTIMATE); fftw_execute(my_plan); //for (int i = 0; i < 100; i++) std::cout << i << ": " << in[i][0] << std::endl; //for (int i = 0; i < sampleSize; i++) std::cout << i << ": " << in[i][0] << " , " << in[i][1] << "i" << std::endl; fftw_destroy_plan(my_plan); // multiply output by 2 (why?) for (int i = 0; i < sampleSize; i++) { in[i][0] *= 2.0; in[i][1] *= 2.0; //qDebug() << in[i][0]; //qDebug() << in[i][1]; } // Calc absolute value and put back into array for (int i = 0; i < sampleSize; i++) { //m_filtered_data_ri[element][i][0] = (in[i][0]);//(float) //m_filtered_data_ri[element][i][1] = (in[i][1]);//(float) m_filtered_data_ri[index3d(i,element,pulsing)*2] = (in[i][0]);//(float) m_filtered_data_ri[index3d(i,element,pulsing)*2+1] = (in[i][1]);//(float) } } } // calculate in seconds, using sampling rate //time_period = time_period / samplingRate; //std::cout << "test" << std::endl; //float frequency = 1 / time_period; //std::cout << "peak frequency : " << frequency << std::endl; }