mse.cpp
Go to the documentation of this file.
1 #include "mse.h"
2 
3 #include <cmath>
4 
5 #include <SimoxUtility/algorithm/string.h>
6 
8 
10 {
11  double
13  {
14  //ARMARX_INFO << "Begin MSE";
15  //auto start = std::chrono::high_resolution_clock::now();
16  double sum = 0;
17 
18  //TODO: check shapes have same size
19  //ARMARX_INFO << "One";
20  if (p1 != nullptr && p2 != nullptr)
21  {
22  p1->getShortName();
23  }
24  else
25  {
26  if (p1 == nullptr)
27  {
28  ARMARX_INFO << "P1 is nullptr";
29  }
30  else
31  {
32  ARMARX_INFO << "P2 is Nullpointer";
33  }
34  }
35  //ARMARX_INFO << "Two";
36 
37  //return 0;
38 
39  std::vector<unsigned char> first_image = p1->getDataAsVector();
40  std::vector<unsigned char> second_image = p2->getDataAsVector();
41  int size = first_image.size();
42 
43  //ARMARX_INFO << "Image size: " << std::to_string(int(first_image.size()));
44  //ARMARX_INFO << "Image size: " << std::to_string(int(second_image.size()));
45  ARMARX_CHECK(first_image.size() == second_image.size());
46 
47  //auto start = std::chrono::high_resolution_clock::now();
48  int rolling_number = 1; //TODO: make sure that no elements will be left over
49 
50  for (int i = 0; i < int(first_image.size()); i += rolling_number)
51  {
52  //loop unrolling to shorten the needed computation time:
53  sum += std::pow(first_image.at(i) - second_image.at(i), 2);
54  /*
55  sum += std::pow(first_image.at(i + 1) - second_image.at(i + 1), 2);
56  sum += std::pow(first_image.at(i + 2) - second_image.at(i + 2), 2);
57  sum += std::pow(first_image.at(i + 3) - second_image.at(i + 3), 2);
58  */
59  }
60 
61 
62  //auto end = std::chrono::high_resolution_clock::now();
63  //auto additional = std::chrono::duration_cast<std::chrono::microseconds>(end - start);
64  //ARMARX_INFO << "Time with unroll factor " << rolling_number << " MSE: " << std::to_string(additional.count());
65  first_image.clear();
66  second_image.clear();
67 
68  //ARMARX_INFO << "MSE is: " << std::to_string(sum / size);
69 
70  return sum / (size);
71  }
72 
73 } // namespace armarx::aron::similarity
mse.h
armarx::aron::similarity::mse::compute_similarity
double compute_similarity(const aron::data::NDArrayPtr p1, const aron::data::NDArrayPtr p2)
Definition: mse.cpp:12
armarx::aron::similarity
Definition: cosine.cpp:9
armarx::aron::data::NDArrayPtr
std::shared_ptr< NDArray > NDArrayPtr
Definition: NDArray.h:46
ARMARX_CHECK
#define ARMARX_CHECK(expression)
Shortcut for ARMARX_CHECK_EXPRESSION.
Definition: ExpressionException.h:82
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:181
Logging.h