comparison UnitTestsSources/ImageProcessingTests.cpp @ 2884:497a637366b4 db-changes

integration mainline->db-changes
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 12 Oct 2018 15:18:10 +0200
parents be1dbb1dcdd6
children 22524fd06225
comparison
equal deleted inserted replaced
1762:2b91363cc1d1 2884:497a637366b4
1 /** 1 /**
2 * Orthanc - A Lightweight, RESTful DICOM Store 2 * Orthanc - A Lightweight, RESTful DICOM Store
3 * Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
4 * Department, University Hospital of Liege, Belgium 4 * Department, University Hospital of Liege, Belgium
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium
5 * 6 *
6 * This program is free software: you can redistribute it and/or 7 * This program is free software: you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as 8 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation, either version 3 of the 9 * published by the Free Software Foundation, either version 3 of the
9 * License, or (at your option) any later version. 10 * License, or (at your option) any later version.
32 33
33 #include "PrecompiledHeadersUnitTests.h" 34 #include "PrecompiledHeadersUnitTests.h"
34 #include "gtest/gtest.h" 35 #include "gtest/gtest.h"
35 36
36 #include "../Core/DicomFormat/DicomImageInformation.h" 37 #include "../Core/DicomFormat/DicomImageInformation.h"
37 #include "../Core/Images/ImageBuffer.h" 38 #include "../Core/Images/Image.h"
38 #include "../Core/Images/ImageProcessing.h" 39 #include "../Core/Images/ImageProcessing.h"
40 #include "../Core/Images/ImageTraits.h"
41
42 #include <memory>
39 43
40 using namespace Orthanc; 44 using namespace Orthanc;
41 45
42 46
43 TEST(DicomImageInformation, ExtractPixelFormat1) 47 TEST(DicomImageInformation, ExtractPixelFormat1)
44 { 48 {
45 // Cardiac/MR* 49 // Cardiac/MR*
46 DicomMap m; 50 DicomMap m;
47 m.SetValue(DICOM_TAG_ROWS, "24"); 51 m.SetValue(DICOM_TAG_ROWS, "24", false);
48 m.SetValue(DICOM_TAG_COLUMNS, "16"); 52 m.SetValue(DICOM_TAG_COLUMNS, "16", false);
49 m.SetValue(DICOM_TAG_BITS_ALLOCATED, "16"); 53 m.SetValue(DICOM_TAG_BITS_ALLOCATED, "16", false);
50 m.SetValue(DICOM_TAG_SAMPLES_PER_PIXEL, "1"); 54 m.SetValue(DICOM_TAG_SAMPLES_PER_PIXEL, "1", false);
51 m.SetValue(DICOM_TAG_BITS_STORED, "12"); 55 m.SetValue(DICOM_TAG_BITS_STORED, "12", false);
52 m.SetValue(DICOM_TAG_HIGH_BIT, "11"); 56 m.SetValue(DICOM_TAG_HIGH_BIT, "11", false);
53 m.SetValue(DICOM_TAG_PIXEL_REPRESENTATION, "0"); 57 m.SetValue(DICOM_TAG_PIXEL_REPRESENTATION, "0", false);
54 m.SetValue(DICOM_TAG_PHOTOMETRIC_INTERPRETATION, "MONOCHROME2"); 58 m.SetValue(DICOM_TAG_PHOTOMETRIC_INTERPRETATION, "MONOCHROME2", false);
55 59
56 DicomImageInformation info(m); 60 DicomImageInformation info(m);
57 PixelFormat format; 61 PixelFormat format;
58 ASSERT_TRUE(info.ExtractPixelFormat(format)); 62 ASSERT_TRUE(info.ExtractPixelFormat(format, false));
59 ASSERT_EQ(PixelFormat_Grayscale16, format); 63 ASSERT_EQ(PixelFormat_Grayscale16, format);
60 } 64 }
61 65
62 66
63 TEST(DicomImageInformation, ExtractPixelFormat2) 67 TEST(DicomImageInformation, ExtractPixelFormat2)
64 { 68 {
65 // Delphine CT 69 // Delphine CT
66 DicomMap m; 70 DicomMap m;
67 m.SetValue(DICOM_TAG_ROWS, "24"); 71 m.SetValue(DICOM_TAG_ROWS, "24", false);
68 m.SetValue(DICOM_TAG_COLUMNS, "16"); 72 m.SetValue(DICOM_TAG_COLUMNS, "16", false);
69 m.SetValue(DICOM_TAG_BITS_ALLOCATED, "16"); 73 m.SetValue(DICOM_TAG_BITS_ALLOCATED, "16", false);
70 m.SetValue(DICOM_TAG_SAMPLES_PER_PIXEL, "1"); 74 m.SetValue(DICOM_TAG_SAMPLES_PER_PIXEL, "1", false);
71 m.SetValue(DICOM_TAG_BITS_STORED, "16"); 75 m.SetValue(DICOM_TAG_BITS_STORED, "16", false);
72 m.SetValue(DICOM_TAG_HIGH_BIT, "15"); 76 m.SetValue(DICOM_TAG_HIGH_BIT, "15", false);
73 m.SetValue(DICOM_TAG_PIXEL_REPRESENTATION, "1"); 77 m.SetValue(DICOM_TAG_PIXEL_REPRESENTATION, "1", false);
74 m.SetValue(DICOM_TAG_PHOTOMETRIC_INTERPRETATION, "MONOCHROME2"); 78 m.SetValue(DICOM_TAG_PHOTOMETRIC_INTERPRETATION, "MONOCHROME2", false);
75 79
76 DicomImageInformation info(m); 80 DicomImageInformation info(m);
77 PixelFormat format; 81 PixelFormat format;
78 ASSERT_TRUE(info.ExtractPixelFormat(format)); 82 ASSERT_TRUE(info.ExtractPixelFormat(format, false));
79 ASSERT_EQ(PixelFormat_SignedGrayscale16, format); 83 ASSERT_EQ(PixelFormat_SignedGrayscale16, format);
80 } 84 }
85
86
87
88 namespace
89 {
90 template <typename T>
91 class TestImageTraits : public ::testing::Test
92 {
93 private:
94 std::auto_ptr<Image> image_;
95
96 protected:
97 virtual void SetUp()
98 {
99 image_.reset(new Image(ImageTraits::PixelTraits::GetPixelFormat(), 7, 9, false));
100 }
101
102 virtual void TearDown()
103 {
104 image_.reset(NULL);
105 }
106
107 public:
108 typedef T ImageTraits;
109
110 ImageAccessor& GetImage()
111 {
112 return *image_;
113 }
114 };
115
116 template <typename T>
117 class TestIntegerImageTraits : public TestImageTraits<T>
118 {
119 };
120 }
121
122
123 typedef ::testing::Types<
124 ImageTraits<PixelFormat_Grayscale8>,
125 ImageTraits<PixelFormat_Grayscale16>,
126 ImageTraits<PixelFormat_SignedGrayscale16>
127 > IntegerFormats;
128 TYPED_TEST_CASE(TestIntegerImageTraits, IntegerFormats);
129
130 typedef ::testing::Types<
131 ImageTraits<PixelFormat_Grayscale8>,
132 ImageTraits<PixelFormat_Grayscale16>,
133 ImageTraits<PixelFormat_SignedGrayscale16>,
134 ImageTraits<PixelFormat_RGB24>,
135 ImageTraits<PixelFormat_BGRA32>
136 > AllFormats;
137 TYPED_TEST_CASE(TestImageTraits, AllFormats);
138
139
140 TYPED_TEST(TestImageTraits, SetZero)
141 {
142 ImageAccessor& image = this->GetImage();
143
144 memset(image.GetBuffer(), 128, image.GetHeight() * image.GetWidth());
145
146 switch (image.GetFormat())
147 {
148 case PixelFormat_Grayscale8:
149 case PixelFormat_Grayscale16:
150 case PixelFormat_SignedGrayscale16:
151 ImageProcessing::Set(image, 0);
152 break;
153
154 case PixelFormat_RGB24:
155 case PixelFormat_BGRA32:
156 ImageProcessing::Set(image, 0, 0, 0, 0);
157 break;
158
159 default:
160 ASSERT_TRUE(0);
161 }
162
163 typename TestFixture::ImageTraits::PixelType zero, value;
164 TestFixture::ImageTraits::PixelTraits::SetZero(zero);
165
166 for (unsigned int y = 0; y < image.GetHeight(); y++)
167 {
168 for (unsigned int x = 0; x < image.GetWidth(); x++)
169 {
170 TestFixture::ImageTraits::GetPixel(value, image, x, y);
171 ASSERT_TRUE(TestFixture::ImageTraits::PixelTraits::IsEqual(zero, value));
172 }
173 }
174 }
175
176
177 TYPED_TEST(TestIntegerImageTraits, SetZeroFloat)
178 {
179 ImageAccessor& image = this->GetImage();
180
181 memset(image.GetBuffer(), 128, image.GetHeight() * image.GetWidth());
182
183 unsigned int c = 0;
184 for (unsigned int y = 0; y < image.GetHeight(); y++)
185 {
186 for (unsigned int x = 0; x < image.GetWidth(); x++, c++)
187 {
188 TestFixture::ImageTraits::SetFloatPixel(image, c, x, y);
189 }
190 }
191
192 c = 0;
193 for (unsigned int y = 0; y < image.GetHeight(); y++)
194 {
195 for (unsigned int x = 0; x < image.GetWidth(); x++, c++)
196 {
197 ASSERT_FLOAT_EQ(c, TestFixture::ImageTraits::GetFloatPixel(image, x, y));
198 }
199 }
200 }