tesseract  5.0.0-alpha-619-ge9db
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 112 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];
LLSQ::add
void add(double x, double y)
Definition: linlsq.cpp:45
LLSQ
Definition: linlsq.h:27
LLSQ::y_variance
double y_variance() const
Definition: linlsq.h:86
GenericVector::choose_nth_item
int choose_nth_item(int target_index)
Definition: genericvector.h:289
GenericVector::size
int size() const
Definition: genericvector.h:71
LLSQ::x_variance
double x_variance() const
Definition: linlsq.h:80