SourceXtractorPlusPlus 1.0.3
SourceXtractor++, the next generation SExtractor
Loading...
Searching...
No Matches
CompactExponentialModel.icpp
Go to the documentation of this file.
1/*
2 * CompactExponentialModel.icpp
3 *
4 * Created on: Aug 19, 2019
5 * Author: mschefer
6 */
7
8namespace ModelFitting {
9
10template<typename ImageType>
23
24template<typename ImageType>
25double CompactExponentialModel<ImageType>::getValue(double x, double y) const {
27 model_eval.transform = getCombinedTransform(1.0);
28 model_eval.i0 = m_i0->getValue();
29 model_eval.k = m_k->getValue();
30 model_eval.max_r_sqr = 1e30;
31
32 auto area_correction = (1.0 / fabs(m_jacobian[0] * m_jacobian[3] - m_jacobian[1] * m_jacobian[2]));
33 return model_eval.evaluateModel(x, y) * area_correction;
34}
35
36template<typename ImageType>
38 using Traits = ImageTraits<ImageType>;
39
40 if (size_x % 2 == 0 || size_y % 2 == 0) {
41 throw Elements::Exception() << "Rasterized image dimensions must be odd numbers "
42 << "but got (" << size_x << ',' << size_y << ")";
43 }
44
45 // Add a 4 pixels border to prevent cropping from Lanczos resize
46 ImageType image = Traits::factory(size_x+8, size_y+8);
47
48 auto combined_tranform = getCombinedTransform(pixel_scale);
49
52 model_eval.i0 = m_i0->getValue();
53 model_eval.k = m_k->getValue();
54 model_eval.max_r_sqr = getMaxRadiusSqr(size_x, size_y, combined_tranform);
55
56 float area_correction = (1.0 / fabs(m_jacobian[0] * m_jacobian[3] - m_jacobian[1] * m_jacobian[2])) * pixel_scale * pixel_scale;
57
58 for (int y = 0; y < (int)size_y; ++y) {
59 int dy = y - size_y / 2;
60 for (int x = 0; x < (int)size_x; ++x) {
61 int dx = x - size_x / 2;
62 if (dx * dx + dy * dy < m_sharp_radius_squared) {
63 Traits::at(image, x+4, y+4) = adaptiveSamplePixel(model_eval, dx, dy, 7, 0.01) * area_correction;
64 } else {
65 Traits::at(image, x+4, y+4) = model_eval.evaluateModel(dx, dy) * area_correction;
66 }
67 }
68 }
69
70 renormalize(image, m_flux->getValue());
71
72 return image;
73}
74
75}
76
const double pixel_scale
Definition TestImage.cpp:74
std::shared_ptr< BasicParameter > m_k
std::shared_ptr< BasicParameter > m_i0
CompactExponentialModel(double sharp_radius, std::shared_ptr< BasicParameter > i0, std::shared_ptr< BasicParameter > k, 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::shared_ptr< BasicParameter > flux, std::tuple< double, double, double, double > transform)
double getValue(double x, double y) const override
std::shared_ptr< BasicParameter > m_flux
ImageType getRasterizedImage(double pixel_scale, std::size_t size_x, std::size_t size_y) const override
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
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
T fabs(T... args)
T transform(T... args)