tesseract  4.0.0-1-g2a2b
linlsq.h File Reference
#include <cstdint>
#include "points.h"

Go to the source code of this file.

Classes

class  GenericVector< T >
 
class  LLSQ
 

Functions

template<typename T >
MedianOfCircularValues (T modulus, GenericVector< T > *v)
 

Function Documentation

◆ MedianOfCircularValues()

template<typename T >
T MedianOfCircularValues ( modulus,
GenericVector< T > *  v 
)

Definition at line 113 of file linlsq.h.

113  {
114  LLSQ stats;
115  T halfrange = static_cast<T>(modulus / 2);
116  int num_elements = v->size();
117  for (int i = 0; i < num_elements; ++i) {
118  stats.add((*v)[i], (*v)[i] + halfrange);
119  }
120  bool offset_needed = stats.y_variance() < stats.x_variance();
121  if (offset_needed) {
122  for (int i = 0; i < num_elements; ++i) {
123  (*v)[i] += halfrange;
124  }
125  }
126  int median_index = v->choose_nth_item(num_elements / 2);
127  if (offset_needed) {
128  for (int i = 0; i < num_elements; ++i) {
129  (*v)[i] -= halfrange;
130  }
131  }
132  return (*v)[median_index];
133 }
int size() const
Definition: genericvector.h:71
void add(double x, double y)
Definition: linlsq.cpp:48
Definition: linlsq.h:28
int choose_nth_item(int target_index)
double y_variance() const
Definition: linlsq.h:87
double x_variance() const
Definition: linlsq.h:81