LSST Applications g0d97872fb5+4fd969bb9d,g1653933729+34a971ddd9,g28da252d5a+072f89fe25,g2bbee38e9b+a99b0ab4cd,g2bc492864f+a99b0ab4cd,g2ca4be77d2+c0e3b27cd8,g2cdde0e794+704103fe75,g3156d2b45e+6e87dc994a,g347aa1857d+a99b0ab4cd,g35bb328faa+34a971ddd9,g3a166c0a6a+a99b0ab4cd,g3e281a1b8c+8ec26ec694,g4005a62e65+ba0306790b,g414038480c+9ed5ed841a,g569e0e2b34+cb4faa46ad,g5a97de2502+520531a62c,g717e5f8c0f+29153700a5,g7ede599f99+367733290c,g80478fca09+17051a22cc,g82479be7b0+f2f1ea0a87,g858d7b2824+29153700a5,g8b782ad322+29153700a5,g8cd86fa7b1+05420e7f7d,g9125e01d80+34a971ddd9,ga5288a1d22+e7f674aaf3,gae0086650b+34a971ddd9,gae74b0b5c6+45ef5cdc51,gb58c049af0+ace264a4f2,gc28159a63d+a99b0ab4cd,gcf0d15dbbd+8051a81198,gda6a2b7d83+8051a81198,gdaeeff99f8+7774323b41,gdf4d240d4a+34a971ddd9,ge2409df99d+cb167bac99,ge33fd446bb+29153700a5,ge79ae78c31+a99b0ab4cd,gf0baf85859+890af219f9,gf5289d68f6+9faa5c5784,w.2024.36
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