//static void GradientsHdrComposition::logImage(imageType_t const & rCurrentImage_p, imageType_t & rResultImage_p) { int const nCols=rCurrentImage_p.Width(); int const nRows=rCurrentImage_p.Height(); int const nChannels=rCurrentImage_p.NumberOfChannels(); imageType_t::color_space colorSpace=rCurrentImage_p.ColorSpace(); if (&rCurrentImage_p != &rResultImage_p){ rResultImage_p.AllocateData(nCols,nRows, nChannels, colorSpace); } for(int channel=0;channel<nChannels;++channel){ for(int row=0;row<nRows;++row){ for(int col=0;col<nCols;++col){ realType_t val=rCurrentImage_p.Pixel(col,row,channel); if(val<=0.0) { rResultImage_p.Pixel(col,row,channel)= -1000; //this is just some value to identify extremes } else { val=std::log(val); rResultImage_p.Pixel(col,row,channel)=val; } } } } }
//static void GradientsBase::createLaplaceVonNeumannImage(imageType_t const & rDx_p, imageType_t const rDy_p, imageType_t &rResultImage_p) { AssertColImage(rDx_p); AssertColImage(rDy_p); int const nRowsX=rDx_p.Height(); #ifdef DEBUG int const nColsX=rDx_p.Width(); int const nRowsY=rDy_p.Height(); #endif int const nColsY=rDy_p.Width(); int const nRowsRes=nRowsX; int const nColsRes=nColsY; int const nChannels=rDx_p.NumberOfChannels(); imageType_t::color_space colorSpace=rDx_p.ColorSpace(); Assert(nRowsX>0 && nColsX>0); Assert(nRowsY>0 && nColsY>0); Assert(nRowsY+1==nRowsX && nColsY==nColsX+1); Assert(nChannels==rDy_p.NumberOfChannels()); //d2x, inner part rResultImage_p.AllocateData(nColsRes,nRowsRes,nChannels,colorSpace); for(int chan=0;chan<nChannels;++chan){ for(int row=0;row<nRowsRes;++row){ for(int col=1;col<nColsRes-1;++col){ rResultImage_p.Pixel(col,row,chan)=rDx_p.Pixel(col,row,chan)-rDx_p.Pixel(col-1,row,chan); } } //d2x, first and last column for(int row=0;row<nRowsRes;++row){ rResultImage_p.Pixel(0,row,chan)=rDx_p.Pixel(0,row,chan); rResultImage_p.Pixel(nColsRes-1,row,chan)=-rDx_p.Pixel(nColsRes-2,row,chan); } //d2y, inner part for(int row=1;row<nRowsRes-1;++row){ for(int col=0;col<nColsRes;++col){ rResultImage_p.Pixel(col,row,chan)+=rDy_p.Pixel(col,row,chan)-rDy_p.Pixel(col,row-1,chan); } } //d2y, first and last row for(int col=0;col<nColsRes;++col){ rResultImage_p.Pixel(col,0,chan)+=rDy_p.Pixel(col,0,chan); rResultImage_p.Pixel(col,nRowsRes-1,chan)-=rDy_p.Pixel(col,nRowsRes-2,chan); } } }
//static void GradientsBase::createDyImage(imageType_t const &rImage_p, imageType_t &rResultImage_p) { AssertColImage(rImage_p); int const nRows=rImage_p.Height(); int const nCols=rImage_p.Width(); int const nChannels=rImage_p.NumberOfChannels(); imageType_t::color_space colorSpace=rImage_p.ColorSpace(); rResultImage_p.AllocateData(nCols,nRows-1,nChannels,colorSpace); for(int chan=0;chan<nChannels;++chan){ for (int row=0;row<nRows-1;++row){ for(int col=0;col<nCols;++col){ rResultImage_p.Pixel(col,row,chan)=rImage_p.Pixel(col,row+1,chan)-rImage_p.Pixel(col,row,chan); } } } }
//static void GradientsHdrComposition::expImage(imageType_t const & rCurrentImage_p, imageType_t & rResultImage_p) { int const nCols=rCurrentImage_p.Width(); int const nRows=rCurrentImage_p.Height(); int const nChannels=rCurrentImage_p.NumberOfChannels(); imageType_t::color_space colorSpace=rCurrentImage_p.ColorSpace(); if (&rCurrentImage_p != &rResultImage_p){ rResultImage_p.AllocateData(nCols,nRows, nChannels, colorSpace); } for(int channel=0;channel<nChannels;++channel){ for(int row=0;row<nRows;++row){ for(int col=0;col<nCols;++col){ realType_t val=rCurrentImage_p.Pixel(col,row,channel); rResultImage_p.Pixel(col,row,channel)=std::exp(val); } } } }
//static void GradientsBase::solveImage(imageType_t const &rLaplaceImage_p, imageType_t &rSolution_p) { int const nRows=rLaplaceImage_p.Height(); int const nCols=rLaplaceImage_p.Width(); int const nChannels=rLaplaceImage_p.NumberOfChannels(); imageType_t::color_space colorSpace=rLaplaceImage_p.ColorSpace(); #ifdef USE_FFTW // adapted from http://www.umiacs.umd.edu/~aagrawal/software.html, AssertColImage(rLaplaceImage_p); // just in case we accidentally change this, because code below believes in double... Assert(typeid(realType_t)==typeid(double)); // check assumption of row major format Assert(rLaplaceImage_p.PixelAddress(0,0)+1==rLaplaceImage_p.PixelAddress(1,0)); rSolution_p.AllocateData(nCols,nRows,nChannels,colorSpace); rSolution_p.ResetSelections(); rSolution_p.Black(); #ifdef USE_THREADS // threaded version int const nElements=nRows*nCols; int const nThreads=Thread::NumberOfThreads(nElements); if(fftw_init_threads()==0){ throw Error("Problem initilizing threads"); } fftw_plan_with_nthreads(nThreads); #endif for(int chan=0;chan<nChannels;++chan){ TimeMessage startSolver(String("FFTW Solver, Channel ")+String(chan)); // FIXME see if fttw_allocate gives us something... imageType_t fcos(nCols,nRows); #if 0 // During experiment, the higher optimization did not give us anything except for an additional delay. May change later. fftw_plan pForward= fftw_plan_r2r_2d(nRows, nCols, const_cast<double *>(rLaplaceImage_p.PixelData(chan)), fcos.PixelData(), FFTW_REDFT10, FFTW_REDFT10, FFTW_MEASURE); fftw_plan pInverse = fftw_plan_r2r_2d(nRows, nCols, fcos.PixelData(), rSolution_p.PixelData(chan), FFTW_REDFT01, FFTW_REDFT01, FFTW_ESTIMATE); #else fftw_plan pForward= fftw_plan_r2r_2d(nRows, nCols, const_cast<double *>(rLaplaceImage_p.PixelData(chan)), fcos.PixelData(), FFTW_REDFT10, FFTW_REDFT10, FFTW_MEASURE); fftw_plan pInverse = fftw_plan_r2r_2d(nRows, nCols, fcos.PixelData(), rSolution_p.PixelData(chan), FFTW_REDFT01, FFTW_REDFT01, FFTW_ESTIMATE); #endif // find DCT fftw_execute(pForward); realType_t const pi=pcl::Pi(); for(int row = 0 ; row < nRows; ++row){ for(int col = 0 ; col < nCols; ++col){ fcos.Pixel(col,row) /= 2*cos(pi*col/( (double) nCols)) - 2 + 2*cos(pi*row/((double) nRows)) - 2; } } fcos.Pixel(0,0)=0.0; // Inverse DCT fftw_execute(pInverse); fftw_destroy_plan(pForward); fftw_destroy_plan(pInverse); } #endif #ifdef USE_PIFFT // use PI FFT based solver by Carlos Milovic F. rLaplaceImage_p.ResetSelections(); rSolution_p.AllocateData(nCols,nRows,nChannels,colorSpace); rSolution_p.ResetSelections(); // current solver handles only one channel per run. for(int chan=0;chan<nChannels;++chan){ TimeMessage startSolver(String("PIFFT Solver, Channel ")+String(chan)); imageType_t tmpImage(nCols,nRows); rLaplaceImage_p.SelectChannel(chan); tmpImage.Assign(rLaplaceImage_p); __SolvePoisson(tmpImage); rSolution_p.SelectChannel(chan); rSolution_p.Mov(tmpImage); } #endif }