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