test_volproc.cpp
Go to the documentation of this file.
1 /*
2 * ECVL - European Computer Vision Library
3 * Version: 0.3.4
4 * copyright (c) 2021, Università degli Studi di Modena e Reggio Emilia (UNIMORE), AImageLab
5 * Authors:
6 * Costantino Grana (costantino.grana@unimore.it)
7 * Federico Bolelli (federico.bolelli@unimore.it)
8 * Michele Cancilla (michele.cancilla@unimore.it)
9 * Laura Canalini (laura.canalini@unimore.it)
10 * Stefano Allegretti (stefano.allegretti@unimore.it)
11 * All rights reserved.
12 */
13 
14 #include <gmock/gmock.h>
15 #include <gtest/gtest.h>
16 
17 #include "ecvl/core.h"
18 
19 using namespace ecvl;
20 
21 namespace
22 {
23 class TCore : public ::testing::Test
24 {
25 protected:
26  Image out;
27 
28 #define ECVL_TUPLE(type, ...) \
29  Image g1_##type = Image({ 1, 1, 1 }, DataType::type, "xyc", ColorType::GRAY); \
30  View<DataType::type> g1_##type##_v; \
31  Image g1_spacing_##type = Image({ 1, 1, 1, 1 }, DataType::type, "xyzt", ColorType::GRAY, {1, 2, 3, 4}); \
32  View<DataType::type> g1_spacing_##type##_v; \
33  Image g2_##type = Image({ 2, 2, 1 }, DataType::type, "xyc", ColorType::GRAY); \
34  View<DataType::type> g2_##type##_v; \
35  Image rgb2_##type = Image({ 2, 2, 3 }, DataType::type, "xyc", ColorType::RGB); \
36  View<DataType::type> rgb2_##type##_v; \
37  Image rgb2_spacing_##type = Image({ 2, 2, 3, 1 }, DataType::type, "xyzt", ColorType::RGB, {2, 4, 7, 1}); \
38  View<DataType::type> rgb2_spacing_##type##_v;
39 
41 #undef ECVL_TUPLE
42 
43  void SetUp() override
44  {
45  out = Image();
46 
47 #define ECVL_TUPLE(type, ...) \
48  g1_##type##_v = g1_##type; \
49  g1_##type##_v({ 0,0,0 }) = 50; \
50  \
51  g1_spacing_##type##_v = g1_spacing_##type; \
52  g1_spacing_##type##_v({ 0,0,0,0 }) = 50; \
53  \
54  g2_##type##_v = g2_##type; \
55  g2_##type##_v({ 0,0,0 }) = 50; g2_##type##_v({ 1,0,0 }) = 32; \
56  g2_##type##_v({ 0,1,0 }) = 14; g2_##type##_v({ 1,1,0 }) = 60; \
57  \
58  rgb2_##type##_v = rgb2_##type; \
59  rgb2_##type##_v({ 0,0,0 }) = 50; rgb2_##type##_v({ 1,0,0 }) = 32; \
60  rgb2_##type##_v({ 0,1,0 }) = 14; rgb2_##type##_v({ 1,1,0 }) = 60; \
61  rgb2_##type##_v({ 0,0,1 }) = 50; rgb2_##type##_v({ 1,0,1 }) = 32; \
62  rgb2_##type##_v({ 0,1,1 }) = 14; rgb2_##type##_v({ 1,1,1 }) = 60; \
63  rgb2_##type##_v({ 0,0,2 }) = 50; rgb2_##type##_v({ 1,0,2 }) = 32; \
64  rgb2_##type##_v({ 0,1,2 }) = 14; rgb2_##type##_v({ 1,1,2 }) = 60; \
65  \
66  rgb2_spacing_##type##_v = rgb2_spacing_##type; \
67  rgb2_spacing_##type##_v({ 0,0,0,0 }) = 50; rgb2_spacing_##type##_v({ 1,0,0,0 }) = 32; \
68  rgb2_spacing_##type##_v({ 0,1,0,0 }) = 14; rgb2_spacing_##type##_v({ 1,1,0,0 }) = 60; \
69  rgb2_spacing_##type##_v({ 0,0,1,0 }) = 50; rgb2_spacing_##type##_v({ 1,0,1,0 }) = 32; \
70  rgb2_spacing_##type##_v({ 0,1,1,0 }) = 14; rgb2_spacing_##type##_v({ 1,1,1,0 }) = 60; \
71  rgb2_spacing_##type##_v({ 0,0,2,0 }) = 50; rgb2_spacing_##type##_v({ 1,0,2,0 }) = 32; \
72  rgb2_spacing_##type##_v({ 0,1,2,0 }) = 14; rgb2_spacing_##type##_v({ 1,1,2,0 }) = 60;
73 
75 #undef ECVL_TUPLE
76  }
77 };
78 
79 using VolProc = TCore;
80 
81 #define ECVL_TUPLE(type, ...) \
82 TEST_F(VolProc, SliceTimingCorrection##type) \
83 { \
84  EXPECT_THROW(SliceTimingCorrection(g1_##type, out), std::runtime_error); \
85  \
86  SliceTimingCorrection(g1_spacing_##type, out); \
87  View<DataType::float32> out_v(out); \
88  EXPECT_TRUE(out_v({ 0,0,0,0 }) == 50); \
89  EXPECT_THAT(out.dims_, testing::ElementsAre(1, 1, 1, 1)); \
90  \
91  SliceTimingCorrection(rgb2_spacing_##type, out); \
92  out_v = out; \
93  EXPECT_TRUE(out_v({ 0,0,0,0 }) == 50); EXPECT_TRUE(out_v({ 1,0,0,0 }) == 32); \
94  EXPECT_TRUE(out_v({ 0,0,1,0 }) == 50); EXPECT_TRUE(out_v({ 1,0,1,0 }) == 32); \
95  EXPECT_TRUE(out_v({ 0,0,2,0 }) == 50); EXPECT_TRUE(out_v({ 1,0,2,0 }) == 32); \
96  EXPECT_THAT(out.dims_, testing::ElementsAre(2, 2, 3, 1)); \
97 } \
98 \
99 TEST_F(VolProc, SliceTimingCorrectionSameDst##type) \
100 { \
101  EXPECT_THROW(SliceTimingCorrection(g1_##type, g1_##type), std::runtime_error); \
102  \
103  SliceTimingCorrection(g1_spacing_##type, g1_spacing_##type); \
104  View<DataType::float32> out_v(g1_spacing_##type); \
105  EXPECT_TRUE(out_v({ 0,0,0,0 }) == 50); \
106  EXPECT_THAT(g1_spacing_##type.dims_, testing::ElementsAre(1, 1, 1, 1)); \
107  \
108  SliceTimingCorrection(rgb2_spacing_##type, rgb2_spacing_##type); \
109  out_v = rgb2_spacing_##type; \
110  EXPECT_TRUE(out_v({ 0,0,0,0 }) == 50); EXPECT_TRUE(out_v({ 1,0,0,0 }) == 32); \
111  EXPECT_TRUE(out_v({ 0,0,1,0 }) == 50); EXPECT_TRUE(out_v({ 1,0,1,0 }) == 32); \
112  EXPECT_TRUE(out_v({ 0,0,2,0 }) == 50); EXPECT_TRUE(out_v({ 1,0,2,0 }) == 32); \
113  EXPECT_THAT(rgb2_spacing_##type.dims_, testing::ElementsAre(2, 2, 3, 1)); \
114 }
115 
117 #undef ECVL_TUPLE
118 } // namespace
Image class.
Definition: image.h:72