13template<
typename ImageType>
19 :
ExtendedModel<ImageType>({}, x_scale, y_scale, rotation, width, height, x, y),
20 m_x_scale(x_scale), m_y_scale(y_scale), m_rotation(rotation)
26template<
typename ImageType>
31#elif defined(_GNU_SOURCE)
49template<
typename ImageType>
50template<
typename ModelEvaluator>
54 float x_model = (x - 0.5 + (ix+1) * 1.0 / (subsampling+1));
56 float y_model = (y - 0.5 + (iy+1) * 1.0 / (subsampling+1));
57 acc += model_eval.evaluateModel(x_model, y_model);
61 return acc / (subsampling*subsampling);
64template<
typename ImageType>
65template<
typename ModelEvaluator>
71 for (
unsigned int i=0; i<samples; i++) {
72 acc += model_eval.evaluateModel(
double(x) + distribution(generator),
double(y) + distribution(generator));
80template<
typename ImageType>
81template<
typename ModelEvaluator>
83 unsigned int steps[] = {1,3,5,7,11,15,23,31,47,63,95,127};
85 for (
unsigned int i=2; i < (
sizeof(steps)/
sizeof(steps[0])) && steps[i] <= max_subsampling; i++) {
86 float newValue =
samplePixel(model_eval, x,y, steps[i] + (max_subsampling % 2));
88 double diff =
fabs(newValue - value);
89 if (diff <= threshold * value) {
101template<
typename ImageType>
103 double a = (x2-x1) * y1 - (y2-y1) * x1;
104 return a * a / ((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1));
107template<
typename ImageType>
112 double x = size_x * 0.95f / 2.f;
113 double y = size_y * 0.95f / 2.f;
128template<
typename ImageType>
132 int width = Traits::width(image);
133 int height = Traits::height(image);
137 for (
int y=0; y<height; y++) {
138 for (
int x=0; x<width; x++) {
139 acc += Traits::at(image, x, y);
144 double scale = flux / acc;
145 for (
int y=0; y<height; y++) {
146 for (
int x=0; x<width; x++) {
147 Traits::at(image, x, y) = Traits::at(image, x, y) * scale;
std::shared_ptr< BasicParameter > m_rotation
float samplePixel(const ModelEvaluator &model_eval, int x, int y, unsigned int subsampling) 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)
void renormalize(ImageType &image, double flux) const
std::shared_ptr< BasicParameter > m_y_scale
double getMaxRadiusSqr(std::size_t size_x, std::size_t size_y, const Mat22 &transform) const
std::shared_ptr< BasicParameter > m_x_scale
double computeSqrDistanceLineToOrigin(double x1, double y1, double x2, double y2) 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
float sampleStochastic(const ModelEvaluator &model_eval, int x, int y, unsigned int samples=100) const
ExtendedModel(std::vector< std::unique_ptr< ModelComponent > > &&component_list, std::shared_ptr< BasicParameter > x_scale, std::shared_ptr< BasicParameter > y_scale, std::shared_ptr< BasicParameter > rotation_angle, double width, double height, std::shared_ptr< BasicParameter > x, std::shared_ptr< BasicParameter > y)