Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct BufferPSNR // Optimized GPU versions
- { // Data allocations are very expensive on GPU. Use a buffer to solve: allocate once reuse later.
- gpu::GpuMat gI1, gI2, gs, t1,t2;
- gpu::GpuMat buf;
- };
- double getPSNR_GPU(const Mat& I1, const Mat& I2)
- {
- gpu::GpuMat gI1, gI2, gs, t1,t2;
- gI1.upload(I1);
- gI2.upload(I2);
- gI1.convertTo(t1, CV_32F);
- gI2.convertTo(t2, CV_32F);
- gpu::absdiff(t1.reshape(1), t2.reshape(1), gs);
- gpu::multiply(gs, gs, gs);
- Scalar s = gpu::sum(gs);
- double sse = s.val[0] + s.val[1] + s.val[2];
- if( sse <= 1e-10) // for small values return zero
- return 0;
- else
- {
- double mse =sse /(double)(gI1.channels() * I1.total());
- double psnr = 10.0*log10((255*255)/mse);
- return psnr;
- }
- }
Add Comment
Please, Sign In to add comment