11 namespace ModelFitting {
13 template<
typename ImageType>
26 template<
typename ImageType>
44 return scale * rotation * m_inv_jacobian *
pixel_scale;
47 template<
typename ImageType>
48 template<
typename ModelEvaluator>
52 float x_model = (x - 0.5 + (ix+1) * 1.0 / (subsampling+1));
54 float y_model = (y - 0.5 + (iy+1) * 1.0 / (subsampling+1));
55 acc += model_eval.evaluateModel(x_model, y_model);
59 return acc / (subsampling*subsampling);
62 template<
typename ImageType>
63 template<
typename ModelEvaluator>
69 for (
unsigned int i=0; i<samples; i++) {
70 acc += model_eval.evaluateModel(
double(x) + distribution(generator),
double(y) + distribution(generator));
78 template<
typename ImageType>
79 template<
typename ModelEvaluator>
81 unsigned int steps[] = {1,3,5,7,11,15,23,31,47,63,95,127};
82 float value = samplePixel(model_eval, x,y, 1);
83 for (
unsigned int i=2; i < (
sizeof(steps)/
sizeof(steps[0])) && steps[i] <= max_subsampling; i++) {
84 float newValue = samplePixel(model_eval, x,y, steps[i] + (max_subsampling % 2));
86 double diff =
fabs(newValue - value);
87 if (diff <= threshold * value) {
98 template<
typename ImageType>
101 float x_x = (size_x * 0.95f / 2.f - 1) * transform[0];
102 float x_y = (size_x * 0.95f / 2.f - 1) * transform[2];
104 float y_x = (size_y * 0.95f / 2.f - 1) * transform[1];
105 float y_y = (size_y * 0.95f / 2.f - 1) * transform[3];
107 float xy_x = x_x + y_x;
108 float xy_y = x_y + y_y;
110 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));
111 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));
116 template<
typename ImageType>
127 acc += Traits::at(image,
x,
y);
132 double scale = flux / acc;
135 Traits::at(image,
x,
y) = Traits::at(image,
x,
y) * scale;
float samplePixel(const ModelEvaluator &model_eval, int x, int y, unsigned int subsampling) const
double getMaxRadiusSqr(std::size_t size_x, std::size_t size_y, const Mat22 &transform) const
Mat22 getCombinedTransform(double pixel_scale) const
float adaptiveSamplePixel(const ModelEvaluator &model_eval, int x, int y, unsigned int max_subsampling, float threshold=1.1) const
void renormalize(ImageType &image, double flux) const
float sampleStochastic(const ModelEvaluator &model_eval, int x, int y, unsigned int samples=100) const
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)