LSST Applications g0f08755f38+82efc23009,g12f32b3c4e+e7bdf1200e,g1653933729+a8ce1bb630,g1a0ca8cf93+50eff2b06f,g28da252d5a+52db39f6a5,g2bbee38e9b+37c5a29d61,g2bc492864f+37c5a29d61,g2cdde0e794+c05ff076ad,g3156d2b45e+41e33cbcdc,g347aa1857d+37c5a29d61,g35bb328faa+a8ce1bb630,g3a166c0a6a+37c5a29d61,g3e281a1b8c+fb992f5633,g414038480c+7f03dfc1b0,g41af890bb2+11b950c980,g5fbc88fb19+17cd334064,g6b1c1869cb+12dd639c9a,g781aacb6e4+a8ce1bb630,g80478fca09+72e9651da0,g82479be7b0+04c31367b4,g858d7b2824+82efc23009,g9125e01d80+a8ce1bb630,g9726552aa6+8047e3811d,ga5288a1d22+e532dc0a0b,gae0086650b+a8ce1bb630,gb58c049af0+d64f4d3760,gc28159a63d+37c5a29d61,gcf0d15dbbd+2acd6d4d48,gd7358e8bfb+778a810b6e,gda3e153d99+82efc23009,gda6a2b7d83+2acd6d4d48,gdaeeff99f8+1711a396fd,ge2409df99d+6b12de1076,ge79ae78c31+37c5a29d61,gf0baf85859+d0a5978c5a,gf3967379c6+4954f8c433,gfb92a5be7c+82efc23009,gfec2e1e490+2aaed99252,w.2024.46
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