-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathutilities.cpp
48 lines (43 loc) · 1.35 KB
/
utilities.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
* Copyright (c) 2011, Marc Lebrun <[email protected]>
* All rights reserved.
*
* This program is free software: you can use, modify and/or
* redistribute it under the terms of the GNU General Public
* License as published by the Free Software Foundation, either
* version 3 of the License, or (at your option) any later
* version. You should have received a copy of this license along
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @file utilities.cpp
* @brief Utilities functions
*
* @author Marc Lebrun <[email protected]>
**/
#include "utilities.h"
#include <math.h>
using namespace std;
/**
* @brief Compute PSNR and RMSE between img_1 and img_2
*
* @param img_1 : pointer to an allocated array of pixels.
* @param img_2 : pointer to an allocated array of pixels.
* @param psnr : will contain the PSNR
* @param rmse : will contain the RMSE
* @param size : size of both images
*
* @return none.
**/
void psnr_rmse(const float * img_1,
const float * img_2,
float * psnr,
float * rmse,
const unsigned size)
{
float tmp = 0.0f;
for (unsigned k = 0; k < size; k++)
tmp += (img_1[k] - img_2[k]) * (img_1[k] - img_2[k]);
(*rmse) = sqrtf(tmp / (float) size);
(*psnr) = 20.0f * log10f(255.0f / (*rmse));
}