SourceXtractorPlusPlus  0.11
Please provide a description of the project.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CompactModelBase.icpp
Go to the documentation of this file.
1 /*
2  * CompactModelBase.icpp
3  *
4  * Created on: Aug 19, 2019
5  * Author: mschefer
6  */
7 
8 namespace ModelFitting {
9 
10 template<typename ImageType>
16  : ExtendedModel<ImageType>({}, x_scale, y_scale, rotation, width, height, x, y),
18 {
19  m_jacobian = Mat22(transform).GetTranspose();
20  m_inv_jacobian = m_jacobian.GetInverse();
21 }
22 
23 template<typename ImageType>
25  double s, c;
26 #ifdef _GNU_SOURCE
27  sincos(m_rotation->getValue(), &s, &c);
28 #else
29  s = sin(m_rotation->getValue());
30  c = cos(m_rotation->getValue());
31 #endif
32 
34  c, s,
35  -s, c);
36 
37  Mat22 scale(
38  1. / m_x_scale->getValue(), 0.0,
39  0.0, 1. / m_y_scale->getValue());
40 
41  return scale * rotation * m_inv_jacobian * pixel_scale;
42 }
43 
44 template<typename ImageType>
45 template<typename ModelEvaluator>
46 inline float CompactModelBase<ImageType>::samplePixel(const ModelEvaluator& model_eval, int x, int y, unsigned int subsampling) const {
47  double acc = 0.;
48  for (std::size_t ix=0; ix<subsampling; ++ix) {
49  float x_model = (x - 0.5 + (ix+1) * 1.0 / (subsampling+1));
50  for (std::size_t iy=0; iy<subsampling; ++iy) {
51  float y_model = (y - 0.5 + (iy+1) * 1.0 / (subsampling+1));
52  acc += model_eval.evaluateModel(x_model, y_model);
53  }
54  }
55 
56  return acc / (subsampling*subsampling);
57 }
58 
59 template<typename ImageType>
60 template<typename ModelEvaluator>
61 inline float CompactModelBase<ImageType>::adaptiveSamplePixel(const ModelEvaluator& model_eval, int x, int y, unsigned int max_subsampling, float threshold) const {
62  float value = samplePixel(model_eval, x,y, 1);
63  for (unsigned int i=2; i<=max_subsampling; i+=2) {
64  float newValue = samplePixel(model_eval, x,y, i);
65  float ratio = newValue / value;
66  if (ratio < threshold && ratio > 1.0 / threshold) {
67  value = newValue;
68  break;
69  }
70  value = newValue;
71  }
72 
73  return value;
74 }
75 
76 template<typename ImageType>
78 
79  float x_x = (size_x * 0.95f / 2.f - 1) * transform[0];
80  float x_y = (size_x * 0.95f / 2.f - 1) * transform[2];
81 
82  float y_x = (size_y * 0.95f / 2.f - 1) * transform[1];
83  float y_y = (size_y * 0.95f / 2.f - 1) * transform[3];
84 
85  float xy_x = x_x + y_x;
86  float xy_y = x_y + y_y;
87 
88  float d1 = (xy_x * x_y - xy_y * x_x) * (xy_x * x_y - xy_y * x_x) / ((xy_x - x_x) * (xy_x - x_x) + (xy_y - x_y) * (xy_y - x_y));
89  float d2 = (xy_x * y_y - xy_y * y_x) * (xy_x * y_y - xy_y * y_x) / ((xy_x - y_x) * (xy_x - y_x) + (xy_y - y_y) * (xy_y - y_y));
90 
91  return std::min(d1, d2);
92 }
93 
94 
95 }
float samplePixel(const ModelEvaluator &model_eval, int x, int y, unsigned int subsampling) const
constexpr double s
Mat22 GetTranspose() const
Definition: Mat22.h:73
double getMaxRadiusSqr(std::size_t size_x, std::size_t size_y, const Mat22 &transform) const
T min(T...args)
T sin(T...args)
m_rotation(rotation)
Mat22 getCombinedTransform(double pixel_scale) const
T cos(T...args)
float adaptiveSamplePixel(const ModelEvaluator &model_eval, int x, int y, unsigned int max_subsampling, float threshold=1.1) const
m_y_scale(y_scale)
Mat22 GetInverse() const
Definition: Mat22.h:58
m_x_scale(x_scale)
const double pixel_scale
Definition: TestImage.cpp:75
std::pair< double, double > transform(int x, int y, const std::array< double, 4 > &t)
CompactModelBase(std::shared_ptr< BasicParameter > x_scale, std::shared_ptr< BasicParameter > y_scale, std::shared_ptr< BasicParameter > rotation, double width, double height, std::shared_ptr< BasicParameter > x, std::shared_ptr< BasicParameter > y, std::tuple< double, double, double, double > transform)