annotate UnitTestsSources/ImageProcessingTests.cpp @ 3461:7fc9dd4882ec

merge
author Alain Mazy <alain@mazy.be>
date Tue, 09 Jul 2019 10:30:44 +0200
parents e0841192d7d0
children 46cf170ba121
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
853
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
1900
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1612
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
1288
6e7e5ed91c2d upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1207
diff changeset
4 * Department, University Hospital of Liege, Belgium
3060
4e43e67f8ecf preparing for 2019
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2924
diff changeset
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium
853
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU General Public License as
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * published by the Free Software Foundation, either version 3 of the
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * License, or (at your option) any later version.
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * In addition, as a special exception, the copyright holders of this
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * program give permission to link the code of its release with the
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * that use the same license as the "OpenSSL" library), and distribute
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * the linked executables. You must obey the GNU General Public License
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * in all respects for all of the code used other than "OpenSSL". If you
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * modify file(s) with this exception, you may extend this exception to
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * your version of the file(s), but you are not obligated to do so. If
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * you do not wish to do so, delete this exception statement from your
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 * version. If you delete this exception statement from all source files
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 * in the program, then also delete it here.
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 *
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 * This program is distributed in the hope that it will be useful, but
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * WITHOUT ANY WARRANTY; without even the implied warranty of
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 * General Public License for more details.
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 *
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 * You should have received a copy of the GNU General Public License
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 * along with this program. If not, see <http://www.gnu.org/licenses/>.
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 **/
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 #include "PrecompiledHeadersUnitTests.h"
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 #include "gtest/gtest.h"
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36
855
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
37 #include "../Core/DicomFormat/DicomImageInformation.h"
2487
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
38 #include "../Core/Images/Image.h"
1612
96582230ddcb Core/ImageFormats folder renamed as Core/Images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
39 #include "../Core/Images/ImageProcessing.h"
2487
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
40 #include "../Core/Images/ImageTraits.h"
3366
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3365
diff changeset
41 #include "../Core/OrthancException.h"
2487
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
42
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
43 #include <memory>
853
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 using namespace Orthanc;
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47
855
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
48 TEST(DicomImageInformation, ExtractPixelFormat1)
853
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 {
855
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
50 // Cardiac/MR*
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
51 DicomMap m;
2007
655489d9165d DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1905
diff changeset
52 m.SetValue(DICOM_TAG_ROWS, "24", false);
655489d9165d DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1905
diff changeset
53 m.SetValue(DICOM_TAG_COLUMNS, "16", false);
655489d9165d DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1905
diff changeset
54 m.SetValue(DICOM_TAG_BITS_ALLOCATED, "16", false);
655489d9165d DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1905
diff changeset
55 m.SetValue(DICOM_TAG_SAMPLES_PER_PIXEL, "1", false);
655489d9165d DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1905
diff changeset
56 m.SetValue(DICOM_TAG_BITS_STORED, "12", false);
655489d9165d DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1905
diff changeset
57 m.SetValue(DICOM_TAG_HIGH_BIT, "11", false);
655489d9165d DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1905
diff changeset
58 m.SetValue(DICOM_TAG_PIXEL_REPRESENTATION, "0", false);
655489d9165d DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1905
diff changeset
59 m.SetValue(DICOM_TAG_PHOTOMETRIC_INTERPRETATION, "MONOCHROME2", false);
855
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
60
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
61 DicomImageInformation info(m);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
62 PixelFormat format;
1905
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
63 ASSERT_TRUE(info.ExtractPixelFormat(format, false));
855
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
64 ASSERT_EQ(PixelFormat_Grayscale16, format);
853
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 }
855
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
66
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
67
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
68 TEST(DicomImageInformation, ExtractPixelFormat2)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
69 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
70 // Delphine CT
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
71 DicomMap m;
2007
655489d9165d DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1905
diff changeset
72 m.SetValue(DICOM_TAG_ROWS, "24", false);
655489d9165d DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1905
diff changeset
73 m.SetValue(DICOM_TAG_COLUMNS, "16", false);
655489d9165d DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1905
diff changeset
74 m.SetValue(DICOM_TAG_BITS_ALLOCATED, "16", false);
655489d9165d DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1905
diff changeset
75 m.SetValue(DICOM_TAG_SAMPLES_PER_PIXEL, "1", false);
655489d9165d DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1905
diff changeset
76 m.SetValue(DICOM_TAG_BITS_STORED, "16", false);
655489d9165d DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1905
diff changeset
77 m.SetValue(DICOM_TAG_HIGH_BIT, "15", false);
655489d9165d DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1905
diff changeset
78 m.SetValue(DICOM_TAG_PIXEL_REPRESENTATION, "1", false);
655489d9165d DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1905
diff changeset
79 m.SetValue(DICOM_TAG_PHOTOMETRIC_INTERPRETATION, "MONOCHROME2", false);
855
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
80
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
81 DicomImageInformation info(m);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
82 PixelFormat format;
1905
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
83 ASSERT_TRUE(info.ExtractPixelFormat(format, false));
855
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
84 ASSERT_EQ(PixelFormat_SignedGrayscale16, format);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
85 }
2487
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
86
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
87
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
88
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
89 namespace
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
90 {
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
91 template <typename T>
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
92 class TestImageTraits : public ::testing::Test
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
93 {
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
94 private:
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
95 std::auto_ptr<Image> image_;
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
96
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
97 protected:
2924
22524fd06225 macros ORTHANC_OVERRIDE and ORTHANC_FINAL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
98 virtual void SetUp() ORTHANC_OVERRIDE
2487
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
99 {
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
100 image_.reset(new Image(ImageTraits::PixelTraits::GetPixelFormat(), 7, 9, false));
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
101 }
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
102
2924
22524fd06225 macros ORTHANC_OVERRIDE and ORTHANC_FINAL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
103 virtual void TearDown() ORTHANC_OVERRIDE
2487
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
104 {
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
105 image_.reset(NULL);
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
106 }
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
107
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
108 public:
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
109 typedef T ImageTraits;
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
110
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
111 ImageAccessor& GetImage()
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
112 {
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
113 return *image_;
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
114 }
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
115 };
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
116
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
117 template <typename T>
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
118 class TestIntegerImageTraits : public TestImageTraits<T>
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
119 {
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
120 };
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
121 }
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
122
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
123
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
124 typedef ::testing::Types<
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
125 ImageTraits<PixelFormat_Grayscale8>,
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
126 ImageTraits<PixelFormat_Grayscale16>,
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
127 ImageTraits<PixelFormat_SignedGrayscale16>
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
128 > IntegerFormats;
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
129 TYPED_TEST_CASE(TestIntegerImageTraits, IntegerFormats);
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
130
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
131 typedef ::testing::Types<
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
132 ImageTraits<PixelFormat_Grayscale8>,
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
133 ImageTraits<PixelFormat_Grayscale16>,
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
134 ImageTraits<PixelFormat_SignedGrayscale16>,
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
135 ImageTraits<PixelFormat_RGB24>,
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
136 ImageTraits<PixelFormat_BGRA32>
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
137 > AllFormats;
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
138 TYPED_TEST_CASE(TestImageTraits, AllFormats);
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
139
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
140
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
141 TYPED_TEST(TestImageTraits, SetZero)
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
142 {
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
143 ImageAccessor& image = this->GetImage();
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
144
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
145 memset(image.GetBuffer(), 128, image.GetHeight() * image.GetWidth());
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
146
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
147 switch (image.GetFormat())
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
148 {
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
149 case PixelFormat_Grayscale8:
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
150 case PixelFormat_Grayscale16:
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
151 case PixelFormat_SignedGrayscale16:
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
152 ImageProcessing::Set(image, 0);
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
153 break;
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
154
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
155 case PixelFormat_RGB24:
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
156 case PixelFormat_BGRA32:
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
157 ImageProcessing::Set(image, 0, 0, 0, 0);
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
158 break;
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
159
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
160 default:
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
161 ASSERT_TRUE(0);
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
162 }
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
163
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
164 typename TestFixture::ImageTraits::PixelType zero, value;
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
165 TestFixture::ImageTraits::PixelTraits::SetZero(zero);
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
166
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
167 for (unsigned int y = 0; y < image.GetHeight(); y++)
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
168 {
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
169 for (unsigned int x = 0; x < image.GetWidth(); x++)
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
170 {
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
171 TestFixture::ImageTraits::GetPixel(value, image, x, y);
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
172 ASSERT_TRUE(TestFixture::ImageTraits::PixelTraits::IsEqual(zero, value));
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
173 }
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
174 }
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
175 }
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
176
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
177
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
178 TYPED_TEST(TestIntegerImageTraits, SetZeroFloat)
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
179 {
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
180 ImageAccessor& image = this->GetImage();
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
181
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
182 memset(image.GetBuffer(), 128, image.GetHeight() * image.GetWidth());
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
183
3258
6f652c7bfc85 ImageProcessing::FillPolygon
Alain Mazy <alain@mazy.be>
parents: 3060
diff changeset
184 float c = 0.0f;
2487
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
185 for (unsigned int y = 0; y < image.GetHeight(); y++)
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
186 {
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
187 for (unsigned int x = 0; x < image.GetWidth(); x++, c++)
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
188 {
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
189 TestFixture::ImageTraits::SetFloatPixel(image, c, x, y);
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
190 }
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
191 }
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
192
3260
345f86fd1ac3 fix (shame on me for not testing)
Alain Mazy <alain@mazy.be>
parents: 3258
diff changeset
193 c = 0.0f;
2487
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
194 for (unsigned int y = 0; y < image.GetHeight(); y++)
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
195 {
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
196 for (unsigned int x = 0; x < image.GetWidth(); x++, c++)
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
197 {
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
198 ASSERT_FLOAT_EQ(c, TestFixture::ImageTraits::GetFloatPixel(image, x, y));
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
199 }
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
200 }
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
201 }
3258
6f652c7bfc85 ImageProcessing::FillPolygon
Alain Mazy <alain@mazy.be>
parents: 3060
diff changeset
202
6f652c7bfc85 ImageProcessing::FillPolygon
Alain Mazy <alain@mazy.be>
parents: 3060
diff changeset
203 TYPED_TEST(TestIntegerImageTraits, FillPolygon)
6f652c7bfc85 ImageProcessing::FillPolygon
Alain Mazy <alain@mazy.be>
parents: 3060
diff changeset
204 {
6f652c7bfc85 ImageProcessing::FillPolygon
Alain Mazy <alain@mazy.be>
parents: 3060
diff changeset
205 ImageAccessor& image = this->GetImage();
6f652c7bfc85 ImageProcessing::FillPolygon
Alain Mazy <alain@mazy.be>
parents: 3060
diff changeset
206
6f652c7bfc85 ImageProcessing::FillPolygon
Alain Mazy <alain@mazy.be>
parents: 3060
diff changeset
207 ImageProcessing::Set(image, 128);
6f652c7bfc85 ImageProcessing::FillPolygon
Alain Mazy <alain@mazy.be>
parents: 3060
diff changeset
208
6f652c7bfc85 ImageProcessing::FillPolygon
Alain Mazy <alain@mazy.be>
parents: 3060
diff changeset
209 // draw a triangle
6f652c7bfc85 ImageProcessing::FillPolygon
Alain Mazy <alain@mazy.be>
parents: 3060
diff changeset
210 std::vector<ImageProcessing::ImagePoint> points;
6f652c7bfc85 ImageProcessing::FillPolygon
Alain Mazy <alain@mazy.be>
parents: 3060
diff changeset
211 points.push_back(ImageProcessing::ImagePoint(1,1));
6f652c7bfc85 ImageProcessing::FillPolygon
Alain Mazy <alain@mazy.be>
parents: 3060
diff changeset
212 points.push_back(ImageProcessing::ImagePoint(1,5));
6f652c7bfc85 ImageProcessing::FillPolygon
Alain Mazy <alain@mazy.be>
parents: 3060
diff changeset
213 points.push_back(ImageProcessing::ImagePoint(5,5));
6f652c7bfc85 ImageProcessing::FillPolygon
Alain Mazy <alain@mazy.be>
parents: 3060
diff changeset
214
6f652c7bfc85 ImageProcessing::FillPolygon
Alain Mazy <alain@mazy.be>
parents: 3060
diff changeset
215 Orthanc::ImageProcessing::FillPolygon(image, points, 255);
6f652c7bfc85 ImageProcessing::FillPolygon
Alain Mazy <alain@mazy.be>
parents: 3060
diff changeset
216
6f652c7bfc85 ImageProcessing::FillPolygon
Alain Mazy <alain@mazy.be>
parents: 3060
diff changeset
217 // outside polygon
6f652c7bfc85 ImageProcessing::FillPolygon
Alain Mazy <alain@mazy.be>
parents: 3060
diff changeset
218 ASSERT_FLOAT_EQ(128, TestFixture::ImageTraits::GetFloatPixel(image, 0, 0));
6f652c7bfc85 ImageProcessing::FillPolygon
Alain Mazy <alain@mazy.be>
parents: 3060
diff changeset
219 ASSERT_FLOAT_EQ(128, TestFixture::ImageTraits::GetFloatPixel(image, 0, 6));
6f652c7bfc85 ImageProcessing::FillPolygon
Alain Mazy <alain@mazy.be>
parents: 3060
diff changeset
220 ASSERT_FLOAT_EQ(128, TestFixture::ImageTraits::GetFloatPixel(image, 6, 6));
6f652c7bfc85 ImageProcessing::FillPolygon
Alain Mazy <alain@mazy.be>
parents: 3060
diff changeset
221 ASSERT_FLOAT_EQ(128, TestFixture::ImageTraits::GetFloatPixel(image, 6, 0));
6f652c7bfc85 ImageProcessing::FillPolygon
Alain Mazy <alain@mazy.be>
parents: 3060
diff changeset
222
3431
e0841192d7d0 improved FillPolygon
Alain Mazy <alain@mazy.be>
parents: 3366
diff changeset
223 ASSERT_FLOAT_EQ(255, TestFixture::ImageTraits::GetFloatPixel(image, 1, 1));
3258
6f652c7bfc85 ImageProcessing::FillPolygon
Alain Mazy <alain@mazy.be>
parents: 3060
diff changeset
224 ASSERT_FLOAT_EQ(255, TestFixture::ImageTraits::GetFloatPixel(image, 1, 2));
3431
e0841192d7d0 improved FillPolygon
Alain Mazy <alain@mazy.be>
parents: 3366
diff changeset
225 ASSERT_FLOAT_EQ(255, TestFixture::ImageTraits::GetFloatPixel(image, 1, 5));
3258
6f652c7bfc85 ImageProcessing::FillPolygon
Alain Mazy <alain@mazy.be>
parents: 3060
diff changeset
226 ASSERT_FLOAT_EQ(255, TestFixture::ImageTraits::GetFloatPixel(image, 2, 4));
3431
e0841192d7d0 improved FillPolygon
Alain Mazy <alain@mazy.be>
parents: 3366
diff changeset
227 ASSERT_FLOAT_EQ(255, TestFixture::ImageTraits::GetFloatPixel(image, 5, 5));
3258
6f652c7bfc85 ImageProcessing::FillPolygon
Alain Mazy <alain@mazy.be>
parents: 3060
diff changeset
228 }
3365
9345710bbf12 check limits in fillpolygon
Alain Mazy <alain@mazy.be>
parents: 3260
diff changeset
229
3366
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3365
diff changeset
230 TYPED_TEST(TestIntegerImageTraits, FillPolygonLargerThanImage)
3365
9345710bbf12 check limits in fillpolygon
Alain Mazy <alain@mazy.be>
parents: 3260
diff changeset
231 {
9345710bbf12 check limits in fillpolygon
Alain Mazy <alain@mazy.be>
parents: 3260
diff changeset
232 ImageAccessor& image = this->GetImage();
9345710bbf12 check limits in fillpolygon
Alain Mazy <alain@mazy.be>
parents: 3260
diff changeset
233
9345710bbf12 check limits in fillpolygon
Alain Mazy <alain@mazy.be>
parents: 3260
diff changeset
234 ImageProcessing::Set(image, 0);
9345710bbf12 check limits in fillpolygon
Alain Mazy <alain@mazy.be>
parents: 3260
diff changeset
235
9345710bbf12 check limits in fillpolygon
Alain Mazy <alain@mazy.be>
parents: 3260
diff changeset
236 std::vector<ImageProcessing::ImagePoint> points;
9345710bbf12 check limits in fillpolygon
Alain Mazy <alain@mazy.be>
parents: 3260
diff changeset
237 points.push_back(ImageProcessing::ImagePoint(0, 0));
9345710bbf12 check limits in fillpolygon
Alain Mazy <alain@mazy.be>
parents: 3260
diff changeset
238 points.push_back(ImageProcessing::ImagePoint(image.GetWidth(),0));
9345710bbf12 check limits in fillpolygon
Alain Mazy <alain@mazy.be>
parents: 3260
diff changeset
239 points.push_back(ImageProcessing::ImagePoint(image.GetWidth(),image.GetHeight()));
9345710bbf12 check limits in fillpolygon
Alain Mazy <alain@mazy.be>
parents: 3260
diff changeset
240 points.push_back(ImageProcessing::ImagePoint(0,image.GetHeight()));
9345710bbf12 check limits in fillpolygon
Alain Mazy <alain@mazy.be>
parents: 3260
diff changeset
241
9345710bbf12 check limits in fillpolygon
Alain Mazy <alain@mazy.be>
parents: 3260
diff changeset
242 ASSERT_THROW(Orthanc::ImageProcessing::FillPolygon(image, points, 255), Orthanc::OrthancException);
9345710bbf12 check limits in fillpolygon
Alain Mazy <alain@mazy.be>
parents: 3260
diff changeset
243 }
9345710bbf12 check limits in fillpolygon
Alain Mazy <alain@mazy.be>
parents: 3260
diff changeset
244
9345710bbf12 check limits in fillpolygon
Alain Mazy <alain@mazy.be>
parents: 3260
diff changeset
245 TYPED_TEST(TestIntegerImageTraits, FillPolygonFullImage)
9345710bbf12 check limits in fillpolygon
Alain Mazy <alain@mazy.be>
parents: 3260
diff changeset
246 {
9345710bbf12 check limits in fillpolygon
Alain Mazy <alain@mazy.be>
parents: 3260
diff changeset
247 ImageAccessor& image = this->GetImage();
9345710bbf12 check limits in fillpolygon
Alain Mazy <alain@mazy.be>
parents: 3260
diff changeset
248
9345710bbf12 check limits in fillpolygon
Alain Mazy <alain@mazy.be>
parents: 3260
diff changeset
249 ImageProcessing::Set(image, 0);
9345710bbf12 check limits in fillpolygon
Alain Mazy <alain@mazy.be>
parents: 3260
diff changeset
250
9345710bbf12 check limits in fillpolygon
Alain Mazy <alain@mazy.be>
parents: 3260
diff changeset
251 std::vector<ImageProcessing::ImagePoint> points;
9345710bbf12 check limits in fillpolygon
Alain Mazy <alain@mazy.be>
parents: 3260
diff changeset
252 points.push_back(ImageProcessing::ImagePoint(0, 0));
9345710bbf12 check limits in fillpolygon
Alain Mazy <alain@mazy.be>
parents: 3260
diff changeset
253 points.push_back(ImageProcessing::ImagePoint(image.GetWidth() - 1,0));
9345710bbf12 check limits in fillpolygon
Alain Mazy <alain@mazy.be>
parents: 3260
diff changeset
254 points.push_back(ImageProcessing::ImagePoint(image.GetWidth() - 1,image.GetHeight() - 1));
9345710bbf12 check limits in fillpolygon
Alain Mazy <alain@mazy.be>
parents: 3260
diff changeset
255 points.push_back(ImageProcessing::ImagePoint(0,image.GetHeight() - 1));
9345710bbf12 check limits in fillpolygon
Alain Mazy <alain@mazy.be>
parents: 3260
diff changeset
256
9345710bbf12 check limits in fillpolygon
Alain Mazy <alain@mazy.be>
parents: 3260
diff changeset
257 Orthanc::ImageProcessing::FillPolygon(image, points, 255);
9345710bbf12 check limits in fillpolygon
Alain Mazy <alain@mazy.be>
parents: 3260
diff changeset
258
3431
e0841192d7d0 improved FillPolygon
Alain Mazy <alain@mazy.be>
parents: 3366
diff changeset
259 ASSERT_FLOAT_EQ(255, TestFixture::ImageTraits::GetFloatPixel(image, 0, 0));
e0841192d7d0 improved FillPolygon
Alain Mazy <alain@mazy.be>
parents: 3366
diff changeset
260 ASSERT_FLOAT_EQ(255, TestFixture::ImageTraits::GetFloatPixel(image, image.GetWidth() - 1, image.GetHeight() - 1));
3365
9345710bbf12 check limits in fillpolygon
Alain Mazy <alain@mazy.be>
parents: 3260
diff changeset
261 }