LSST Applications g1653933729+a8ce1bb630,g171997e3ee+76e92115be,g1a997c3884+a8ce1bb630,g28da252d5a+4013ff5194,g2bbee38e9b+d6d0f9f6ae,g2bc492864f+d6d0f9f6ae,g2cdde0e794+ccb74358b7,g3156d2b45e+07302053f8,g347aa1857d+d6d0f9f6ae,g35bb328faa+a8ce1bb630,g3a166c0a6a+d6d0f9f6ae,g3e281a1b8c+130fae20e3,g4005a62e65+17cd334064,g414038480c+c9f68e2a12,g41af890bb2+3e1f62f438,g4e1a3235cc+9db7d56ad0,g7b55021d1b+7b623691d5,g80478fca09+334cc8d2bd,g82479be7b0+b568f6b267,g858d7b2824+37b39d8760,g9125e01d80+a8ce1bb630,ga5288a1d22+11cb34fefe,gae0086650b+a8ce1bb630,gb4ec7eb0ab+37b39d8760,gb58c049af0+d64f4d3760,gc081298178+284e133171,gc28159a63d+d6d0f9f6ae,gcf0d15dbbd+00fe2e0b07,gd6b7c0dfd1+8b62435e69,gda3e153d99+37b39d8760,gda6a2b7d83+00fe2e0b07,gdaeeff99f8+1711a396fd,gdd5a9049c5+23f3b3239a,ge2409df99d+5d9f551a54,ge33fd446bb+37b39d8760,ge79ae78c31+d6d0f9f6ae,gf0baf85859+2dea8344a2,gf5289d68f6+3777f3df5e,w.2024.41
LSST Data Management Base Package
Loading...
Searching...
No Matches
test_image.cc
Go to the documentation of this file.
1#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
2
3#include "doctest.h"
4
5#include <memory>
6
8#include "lsst/gauss2d/python/image.h"
9
10#include <pybind11/embed.h>
11
12namespace g2d = lsst::gauss2d;
13
14typedef g2d::python::Image<double> Image;
16typedef g2d::python::Image<bool> Mask;
17
18// Import numpy, otherwise all Image calls will segfault
19py::scoped_interpreter guard{};
20py::module_ numpy = py::module_::import("numpy");
21
22TEST_CASE("Image") {
23 size_t n_rows = 3, n_cols = 2;
24 std::shared_ptr<Image> image = std::make_shared<Image>(n_rows, n_cols);
25 Image zeros{n_rows, n_cols};
26 for (size_t row = 0; row < n_rows; ++row) {
27 for (size_t col = 0; col < n_cols; ++col) {
28 image->set_value(row, col, 0);
29 zeros.set_value(row, col, 0);
30 }
31 }
32 CHECK(*image == zeros);
33 CHECK(image->get_coordsys() == g2d::COORDS_DEFAULT);
34 CHECK(&(image->get_coordsys()) == &(g2d::COORDS_DEFAULT));
35 CHECK(image->get_n_cols() == n_cols);
36 CHECK(image->get_n_rows() == n_rows);
37 CHECK(image->size() == n_cols * n_rows);
38
39 image->set_value_unchecked(0, 0, 0);
40 CHECK(image->get_value_unchecked(0, 0) == 0);
41 image->add_value_unchecked(0, 0, 1);
42 CHECK(image->get_value_unchecked(0, 0) == 1);
43 CHECK(*image != zeros);
44 CHECK_THROWS_AS(image->get_value(0, n_cols), std::out_of_range);
45 CHECK_THROWS_AS(image->set_value(n_rows, 0, 1), std::out_of_range);
46 double& value = image->_get_value_unchecked(1, 1);
47 value = -1;
48 CHECK(image->get_value_unchecked(1, 1) == -1);
49}
50
51TEST_CASE("ImageArray") {
52 size_t n_rows = 3, n_cols = 2;
53 std::shared_ptr<Image> image = std::make_shared<Image>(n_rows, n_cols);
56
57 for (ImageArray::const_iterator it = arr.cbegin(); it != arr.cend(); ++it) {
58 CHECK(*it == image);
59 }
60 for (const auto& img : arr) {
61 CHECK(img == image);
62 }
63}
64
65TEST_CASE("Mask") {
66 auto image = Image(2, 2);
67 auto mask = Mask(2, 2);
68 mask.fill(false);
69 CHECK_EQ(mask.get_value_unchecked(0, 0), false);
70 mask._get_value_unchecked(1, 1) = true;
71 CHECK_EQ(mask.get_value_unchecked(1, 1), true);
72 CHECK_EQ(g2d::images_compatible<double, Image, bool, Mask>(image, mask), true);
73}
74
75TEST_CASE("Evaluate") {
76 auto gauss1 = std::make_shared<g2d::Gaussian>(nullptr, std::make_shared<g2d::Ellipse>(3, 6, 0));
77 auto gauss2 = std::make_shared<g2d::Gaussian>(nullptr, std::make_shared<g2d::Ellipse>(4, 8, 0));
78 auto gauss_conv = std::make_shared<g2d::ConvolvedGaussian>(gauss1, gauss2);
79 g2d::ConvolvedGaussians::Data data{gauss_conv, std::make_shared<g2d::ConvolvedGaussian>(gauss2, gauss1)};
80 auto gaussians_conv = std::make_shared<g2d::ConvolvedGaussians>(data);
81 auto output = g2d::make_gaussians_pixel<double, Image, g2d::python::Image<size_t>>(gaussians_conv,
82 nullptr, 5, 7);
83 CHECK_EQ(output->get_n_rows(), 5);
84}
char * data
Definition BaseRecord.cc:61
afw::table::Key< afw::table::Array< ImagePixelT > > image
afw::table::Key< afw::table::Array< MaskPixelT > > mask
An array of compatible Images.
Definition image.h:268
typename Data::const_iterator const_iterator
Definition image.h:279
Data::const_iterator cbegin() const noexcept
Definition image.h:284
Data::const_iterator cend() const noexcept
Definition image.h:285
#define CHECK(...)
Definition doctest.h:2969
#define TEST_CASE(name)
Definition doctest.h:2936
#define CHECK_THROWS_AS(expr,...)
Definition doctest.h:2972
#define CHECK_EQ(...)
Definition doctest.h:3017
int row
Definition CR.cc:145
int col
Definition CR.cc:144
g2d::python::Image< double > Image
Definition test_image.cc:14
g2d::ImageArray< double, Image > ImageArray
Definition test_image.cc:15
py::scoped_interpreter guard
Definition test_image.cc:19
g2d::python::Image< bool > Mask
Definition test_image.cc:16