tesseract 4.1.1
Loading...
Searching...
No Matches
linlsq.h File Reference
#include <cstdint>
#include "points.h"

Go to the source code of this file.

Classes

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:72
int choose_nth_item(int target_index)
Definition: linlsq.h:28
double y_variance() const
Definition: linlsq.h:87
double x_variance() const
Definition: linlsq.h:81
void add(double x, double y)
Definition: linlsq.cpp:48