annotate Core/Images/ImageProcessing.cpp @ 2018:300599489cab

USE_BOOST_LOCALE_BACKENDS
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 14 Jun 2016 15:51:00 +0200
parents 4d099fee5eca
children 7a969f235adf
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: 993
diff changeset
4 * Department, University Hospital of Liege, Belgium
853
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 *
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 * This program is free software: you can redistribute it and/or
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * modify it under the terms of the GNU General Public License as
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * published by the Free Software Foundation, either version 3 of the
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * License, or (at your option) any later version.
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 *
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * In addition, as a special exception, the copyright holders of this
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * program give permission to link the code of its release with the
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * that use the same license as the "OpenSSL" library), and distribute
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * the linked executables. You must obey the GNU General Public License
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * 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
17 * modify file(s) with this exception, you may extend this exception to
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * 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
19 * you do not wish to do so, delete this exception statement from your
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * version. If you delete this exception statement from all source files
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 * in the program, then also delete it here.
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 *
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 * This program is distributed in the hope that it will be useful, but
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 * WITHOUT ANY WARRANTY; without even the implied warranty of
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * General Public License for more details.
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 *
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 * You should have received a copy of the GNU General Public License
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 * along with this program. If not, see <http://www.gnu.org/licenses/>.
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 **/
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 #include "../PrecompiledHeaders.h"
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 #include "ImageProcessing.h"
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 #include "../OrthancException.h"
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
38 #include <boost/math/special_functions/round.hpp>
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
39
853
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 #include <cassert>
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 #include <string.h>
859
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
42 #include <limits>
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
43 #include <stdint.h>
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
44
853
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 namespace Orthanc
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 {
859
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
47 template <typename TargetType, typename SourceType>
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
48 static void ConvertInternal(ImageAccessor& target,
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
49 const ImageAccessor& source)
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
50 {
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
51 const TargetType minValue = std::numeric_limits<TargetType>::min();
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
52 const TargetType maxValue = std::numeric_limits<TargetType>::max();
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
53
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
54 for (unsigned int y = 0; y < source.GetHeight(); y++)
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
55 {
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
56 TargetType* t = reinterpret_cast<TargetType*>(target.GetRow(y));
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
57 const SourceType* s = reinterpret_cast<const SourceType*>(source.GetConstRow(y));
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
58
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
59 for (unsigned int x = 0; x < source.GetWidth(); x++, t++, s++)
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
60 {
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
61 if (static_cast<int32_t>(*s) < static_cast<int32_t>(minValue))
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
62 {
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
63 *t = minValue;
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
64 }
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
65 else if (static_cast<int32_t>(*s) > static_cast<int32_t>(maxValue))
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
66 {
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
67 *t = maxValue;
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
68 }
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
69 else
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
70 {
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
71 *t = static_cast<TargetType>(*s);
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
72 }
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
73 }
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
74 }
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
75 }
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
76
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
77
1993
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1992
diff changeset
78 template <typename SourceType>
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1992
diff changeset
79 static void ConvertGrayscaleToFloat(ImageAccessor& target,
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1992
diff changeset
80 const ImageAccessor& source)
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1992
diff changeset
81 {
1994
4d099fee5eca ImageProcessing::Set for float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1993
diff changeset
82 assert(sizeof(float) == 4);
4d099fee5eca ImageProcessing::Set for float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1993
diff changeset
83
1993
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1992
diff changeset
84 for (unsigned int y = 0; y < source.GetHeight(); y++)
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1992
diff changeset
85 {
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1992
diff changeset
86 float* t = reinterpret_cast<float*>(target.GetRow(y));
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1992
diff changeset
87 const SourceType* s = reinterpret_cast<const SourceType*>(source.GetConstRow(y));
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1992
diff changeset
88
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1992
diff changeset
89 for (unsigned int x = 0; x < source.GetWidth(); x++, t++, s++)
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1992
diff changeset
90 {
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1992
diff changeset
91 *t = static_cast<float>(*s);
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1992
diff changeset
92 }
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1992
diff changeset
93 }
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1992
diff changeset
94 }
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1992
diff changeset
95
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1992
diff changeset
96
993
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
97 template <typename TargetType>
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
98 static void ConvertColorToGrayscale(ImageAccessor& target,
1993
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1992
diff changeset
99 const ImageAccessor& source)
993
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
100 {
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
101 assert(source.GetFormat() == PixelFormat_RGB24);
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
102
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
103 const TargetType minValue = std::numeric_limits<TargetType>::min();
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
104 const TargetType maxValue = std::numeric_limits<TargetType>::max();
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
105
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
106 for (unsigned int y = 0; y < source.GetHeight(); y++)
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
107 {
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
108 TargetType* t = reinterpret_cast<TargetType*>(target.GetRow(y));
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
109 const uint8_t* s = reinterpret_cast<const uint8_t*>(source.GetConstRow(y));
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
110
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
111 for (unsigned int x = 0; x < source.GetWidth(); x++, t++, s += 3)
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
112 {
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
113 // Y = 0.2126 R + 0.7152 G + 0.0722 B
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
114 int32_t v = (2126 * static_cast<int32_t>(s[0]) +
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
115 7152 * static_cast<int32_t>(s[1]) +
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
116 0722 * static_cast<int32_t>(s[2])) / 1000;
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
117
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
118 if (static_cast<int32_t>(v) < static_cast<int32_t>(minValue))
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
119 {
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
120 *t = minValue;
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
121 }
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
122 else if (static_cast<int32_t>(v) > static_cast<int32_t>(maxValue))
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
123 {
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
124 *t = maxValue;
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
125 }
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
126 else
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
127 {
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
128 *t = static_cast<TargetType>(v);
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
129 }
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
130 }
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
131 }
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
132 }
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
133
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
134
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
135 template <typename PixelType>
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
136 static void SetInternal(ImageAccessor& image,
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
137 int64_t constant)
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
138 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
139 for (unsigned int y = 0; y < image.GetHeight(); y++)
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
140 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
141 PixelType* p = reinterpret_cast<PixelType*>(image.GetRow(y));
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
142
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
143 for (unsigned int x = 0; x < image.GetWidth(); x++, p++)
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
144 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
145 *p = static_cast<PixelType>(constant);
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
146 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
147 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
148 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
149
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
150
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
151 template <typename PixelType>
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
152 static void GetMinMaxValueInternal(PixelType& minValue,
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
153 PixelType& maxValue,
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
154 const ImageAccessor& source)
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
155 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
156 // Deal with the special case of empty image
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
157 if (source.GetWidth() == 0 ||
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
158 source.GetHeight() == 0)
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
159 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
160 minValue = 0;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
161 maxValue = 0;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
162 return;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
163 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
164
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
165 minValue = std::numeric_limits<PixelType>::max();
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
166 maxValue = std::numeric_limits<PixelType>::min();
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
167
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
168 for (unsigned int y = 0; y < source.GetHeight(); y++)
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
169 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
170 const PixelType* p = reinterpret_cast<const PixelType*>(source.GetConstRow(y));
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
171
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
172 for (unsigned int x = 0; x < source.GetWidth(); x++, p++)
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
173 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
174 if (*p < minValue)
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
175 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
176 minValue = *p;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
177 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
178
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
179 if (*p > maxValue)
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
180 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
181 maxValue = *p;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
182 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
183 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
184 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
185 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
186
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
187
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
188
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
189 template <typename PixelType>
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
190 static void AddConstantInternal(ImageAccessor& image,
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
191 int64_t constant)
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
192 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
193 if (constant == 0)
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
194 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
195 return;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
196 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
197
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
198 const int64_t minValue = std::numeric_limits<PixelType>::min();
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
199 const int64_t maxValue = std::numeric_limits<PixelType>::max();
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
200
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
201 for (unsigned int y = 0; y < image.GetHeight(); y++)
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
202 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
203 PixelType* p = reinterpret_cast<PixelType*>(image.GetRow(y));
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
204
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
205 for (unsigned int x = 0; x < image.GetWidth(); x++, p++)
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
206 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
207 int64_t v = static_cast<int64_t>(*p) + constant;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
208
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
209 if (v > maxValue)
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
210 {
876
e21d1a5f5934 fix msvc warnings
jodogne
parents: 863
diff changeset
211 *p = std::numeric_limits<PixelType>::max();
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
212 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
213 else if (v < minValue)
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
214 {
876
e21d1a5f5934 fix msvc warnings
jodogne
parents: 863
diff changeset
215 *p = std::numeric_limits<PixelType>::min();
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
216 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
217 else
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
218 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
219 *p = static_cast<PixelType>(v);
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
220 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
221 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
222 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
223 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
224
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
225
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
226
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
227 template <typename PixelType>
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
228 void MultiplyConstantInternal(ImageAccessor& image,
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
229 float factor)
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
230 {
1334
7f0aa3c0f659 code improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
231 if (std::abs(factor - 1.0f) <= std::numeric_limits<float>::epsilon())
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
232 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
233 return;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
234 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
235
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
236 const int64_t minValue = std::numeric_limits<PixelType>::min();
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
237 const int64_t maxValue = std::numeric_limits<PixelType>::max();
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
238
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
239 for (unsigned int y = 0; y < image.GetHeight(); y++)
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
240 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
241 PixelType* p = reinterpret_cast<PixelType*>(image.GetRow(y));
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
242
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
243 for (unsigned int x = 0; x < image.GetWidth(); x++, p++)
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
244 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
245 int64_t v = boost::math::llround(static_cast<float>(*p) * factor);
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
246
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
247 if (v > maxValue)
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
248 {
876
e21d1a5f5934 fix msvc warnings
jodogne
parents: 863
diff changeset
249 *p = std::numeric_limits<PixelType>::max();
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
250 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
251 else if (v < minValue)
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
252 {
876
e21d1a5f5934 fix msvc warnings
jodogne
parents: 863
diff changeset
253 *p = std::numeric_limits<PixelType>::min();
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
254 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
255 else
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
256 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
257 *p = static_cast<PixelType>(v);
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
258 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
259 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
260 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
261 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
262
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
263
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
264 template <typename PixelType>
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
265 void ShiftScaleInternal(ImageAccessor& image,
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
266 float offset,
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
267 float scaling)
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
268 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
269 const float minValue = static_cast<float>(std::numeric_limits<PixelType>::min());
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
270 const float maxValue = static_cast<float>(std::numeric_limits<PixelType>::max());
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
271
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
272 for (unsigned int y = 0; y < image.GetHeight(); y++)
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
273 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
274 PixelType* p = reinterpret_cast<PixelType*>(image.GetRow(y));
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
275
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
276 for (unsigned int x = 0; x < image.GetWidth(); x++, p++)
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
277 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
278 float v = (static_cast<float>(*p) + offset) * scaling;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
279
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
280 if (v > maxValue)
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
281 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
282 *p = std::numeric_limits<PixelType>::max();
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
283 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
284 else if (v < minValue)
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
285 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
286 *p = std::numeric_limits<PixelType>::min();
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
287 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
288 else
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
289 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
290 *p = static_cast<PixelType>(boost::math::iround(v));
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
291 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
292 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
293 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
294 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
295
859
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
296
853
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
297 void ImageProcessing::Copy(ImageAccessor& target,
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
298 const ImageAccessor& source)
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
299 {
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
300 if (target.GetWidth() != source.GetWidth() ||
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
301 target.GetHeight() != source.GetHeight())
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
302 {
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
303 throw OrthancException(ErrorCode_IncompatibleImageSize);
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
304 }
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
305
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
306 if (target.GetFormat() != source.GetFormat())
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
307 {
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
308 throw OrthancException(ErrorCode_IncompatibleImageFormat);
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
309 }
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
310
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
311 unsigned int lineSize = GetBytesPerPixel(source.GetFormat()) * source.GetWidth();
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
312
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
313 assert(source.GetPitch() >= lineSize && target.GetPitch() >= lineSize);
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
314
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
315 for (unsigned int y = 0; y < source.GetHeight(); y++)
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
316 {
854
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
317 memcpy(target.GetRow(y), source.GetConstRow(y), lineSize);
853
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
318 }
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
319 }
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
320
854
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
321
853
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
322 void ImageProcessing::Convert(ImageAccessor& target,
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
323 const ImageAccessor& source)
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
324 {
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
325 if (target.GetWidth() != source.GetWidth() ||
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
326 target.GetHeight() != source.GetHeight())
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
327 {
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
328 throw OrthancException(ErrorCode_IncompatibleImageSize);
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
329 }
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
330
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
331 if (source.GetFormat() == target.GetFormat())
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
332 {
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
333 Copy(target, source);
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
334 return;
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
335 }
854
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
336
859
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
337 if (target.GetFormat() == PixelFormat_Grayscale16 &&
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
338 source.GetFormat() == PixelFormat_Grayscale8)
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
339 {
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
340 ConvertInternal<uint16_t, uint8_t>(target, source);
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
341 return;
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
342 }
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
343
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
344 if (target.GetFormat() == PixelFormat_SignedGrayscale16 &&
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
345 source.GetFormat() == PixelFormat_Grayscale8)
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
346 {
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
347 ConvertInternal<int16_t, uint8_t>(target, source);
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
348 return;
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
349 }
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
350
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
351 if (target.GetFormat() == PixelFormat_Grayscale8 &&
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
352 source.GetFormat() == PixelFormat_Grayscale16)
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
353 {
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
354 ConvertInternal<uint8_t, uint16_t>(target, source);
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
355 return;
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
356 }
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
357
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
358 if (target.GetFormat() == PixelFormat_SignedGrayscale16 &&
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
359 source.GetFormat() == PixelFormat_Grayscale16)
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
360 {
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
361 ConvertInternal<int16_t, uint16_t>(target, source);
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
362 return;
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
363 }
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
364
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
365 if (target.GetFormat() == PixelFormat_Grayscale8 &&
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
366 source.GetFormat() == PixelFormat_SignedGrayscale16)
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
367 {
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
368 ConvertInternal<uint8_t, int16_t>(target, source);
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
369 return;
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
370 }
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
371
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
372 if (target.GetFormat() == PixelFormat_Grayscale16 &&
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
373 source.GetFormat() == PixelFormat_SignedGrayscale16)
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
374 {
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
375 ConvertInternal<uint16_t, int16_t>(target, source);
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
376 return;
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
377 }
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
378
993
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
379 if (target.GetFormat() == PixelFormat_Grayscale8 &&
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
380 source.GetFormat() == PixelFormat_RGB24)
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
381 {
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
382 ConvertColorToGrayscale<uint8_t>(target, source);
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
383 return;
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
384 }
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
385
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
386 if (target.GetFormat() == PixelFormat_Grayscale16 &&
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
387 source.GetFormat() == PixelFormat_RGB24)
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
388 {
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
389 ConvertColorToGrayscale<uint16_t>(target, source);
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
390 return;
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
391 }
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
392
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
393 if (target.GetFormat() == PixelFormat_SignedGrayscale16 &&
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
394 source.GetFormat() == PixelFormat_RGB24)
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
395 {
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
396 ConvertColorToGrayscale<int16_t>(target, source);
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
397 return;
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
398 }
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
399
1993
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1992
diff changeset
400 if (target.GetFormat() == PixelFormat_Float32 &&
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1992
diff changeset
401 source.GetFormat() == PixelFormat_Grayscale8)
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1992
diff changeset
402 {
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1992
diff changeset
403 ConvertGrayscaleToFloat<uint8_t>(target, source);
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1992
diff changeset
404 return;
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1992
diff changeset
405 }
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1992
diff changeset
406
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1992
diff changeset
407 if (target.GetFormat() == PixelFormat_Float32 &&
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1992
diff changeset
408 source.GetFormat() == PixelFormat_Grayscale16)
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1992
diff changeset
409 {
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1992
diff changeset
410 ConvertGrayscaleToFloat<uint16_t>(target, source);
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1992
diff changeset
411 return;
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1992
diff changeset
412 }
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1992
diff changeset
413
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1992
diff changeset
414 if (target.GetFormat() == PixelFormat_Float32 &&
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1992
diff changeset
415 source.GetFormat() == PixelFormat_SignedGrayscale16)
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1992
diff changeset
416 {
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1992
diff changeset
417 ConvertGrayscaleToFloat<int16_t>(target, source);
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1992
diff changeset
418 return;
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1992
diff changeset
419 }
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1992
diff changeset
420
1610
2dff2bdffdb8 font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1608
diff changeset
421 if (target.GetFormat() == PixelFormat_Grayscale8 &&
2dff2bdffdb8 font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1608
diff changeset
422 source.GetFormat() == PixelFormat_RGBA32)
2dff2bdffdb8 font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1608
diff changeset
423 {
2dff2bdffdb8 font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1608
diff changeset
424 for (unsigned int y = 0; y < source.GetHeight(); y++)
2dff2bdffdb8 font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1608
diff changeset
425 {
2dff2bdffdb8 font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1608
diff changeset
426 const uint8_t* p = reinterpret_cast<const uint8_t*>(source.GetConstRow(y));
2dff2bdffdb8 font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1608
diff changeset
427 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y));
2dff2bdffdb8 font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1608
diff changeset
428 for (unsigned int x = 0; x < source.GetWidth(); x++, q++)
2dff2bdffdb8 font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1608
diff changeset
429 {
2dff2bdffdb8 font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1608
diff changeset
430 *q = static_cast<uint8_t>((2126 * static_cast<uint32_t>(p[0]) +
2dff2bdffdb8 font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1608
diff changeset
431 7152 * static_cast<uint32_t>(p[1]) +
2dff2bdffdb8 font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1608
diff changeset
432 0722 * static_cast<uint32_t>(p[2])) / 10000);
2dff2bdffdb8 font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1608
diff changeset
433 p += 4;
2dff2bdffdb8 font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1608
diff changeset
434 }
2dff2bdffdb8 font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1608
diff changeset
435 }
2dff2bdffdb8 font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1608
diff changeset
436
2dff2bdffdb8 font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1608
diff changeset
437 return;
2dff2bdffdb8 font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1608
diff changeset
438 }
2dff2bdffdb8 font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1608
diff changeset
439
1608
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
440 if (target.GetFormat() == PixelFormat_RGB24 &&
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
441 source.GetFormat() == PixelFormat_RGBA32)
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
442 {
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
443 for (unsigned int y = 0; y < source.GetHeight(); y++)
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
444 {
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
445 const uint8_t* p = reinterpret_cast<const uint8_t*>(source.GetConstRow(y));
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
446 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y));
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
447 for (unsigned int x = 0; x < source.GetWidth(); x++)
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
448 {
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
449 q[0] = p[0];
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
450 q[1] = p[1];
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
451 q[2] = p[2];
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
452 p += 4;
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
453 q += 3;
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
454 }
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
455 }
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
456
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
457 return;
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
458 }
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
459
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
460 if (target.GetFormat() == PixelFormat_RGBA32 &&
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
461 source.GetFormat() == PixelFormat_RGB24)
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
462 {
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
463 for (unsigned int y = 0; y < source.GetHeight(); y++)
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
464 {
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
465 const uint8_t* p = reinterpret_cast<const uint8_t*>(source.GetConstRow(y));
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
466 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y));
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
467 for (unsigned int x = 0; x < source.GetWidth(); x++)
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
468 {
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
469 q[0] = p[0];
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
470 q[1] = p[1];
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
471 q[2] = p[2];
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
472 q[3] = 255; // Set the alpha channel to full opacity
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
473 p += 3;
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
474 q += 4;
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
475 }
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
476 }
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
477
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
478 return;
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
479 }
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
480
1992
9161e3ef0d17 new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
481 if (target.GetFormat() == PixelFormat_RGB24 &&
9161e3ef0d17 new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
482 source.GetFormat() == PixelFormat_Grayscale8)
9161e3ef0d17 new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
483 {
9161e3ef0d17 new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
484 for (unsigned int y = 0; y < source.GetHeight(); y++)
9161e3ef0d17 new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
485 {
9161e3ef0d17 new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
486 const uint8_t* p = reinterpret_cast<const uint8_t*>(source.GetConstRow(y));
9161e3ef0d17 new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
487 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y));
9161e3ef0d17 new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
488 for (unsigned int x = 0; x < source.GetWidth(); x++)
9161e3ef0d17 new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
489 {
9161e3ef0d17 new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
490 q[0] = *p;
9161e3ef0d17 new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
491 q[1] = *p;
9161e3ef0d17 new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
492 q[2] = *p;
9161e3ef0d17 new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
493 p += 1;
9161e3ef0d17 new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
494 q += 3;
9161e3ef0d17 new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
495 }
9161e3ef0d17 new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
496 }
9161e3ef0d17 new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
497
9161e3ef0d17 new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
498 return;
9161e3ef0d17 new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
499 }
9161e3ef0d17 new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
500
9161e3ef0d17 new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
501 if (target.GetFormat() == PixelFormat_RGBA32 &&
9161e3ef0d17 new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
502 source.GetFormat() == PixelFormat_Grayscale8)
9161e3ef0d17 new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
503 {
9161e3ef0d17 new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
504 for (unsigned int y = 0; y < source.GetHeight(); y++)
9161e3ef0d17 new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
505 {
9161e3ef0d17 new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
506 const uint8_t* p = reinterpret_cast<const uint8_t*>(source.GetConstRow(y));
9161e3ef0d17 new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
507 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y));
9161e3ef0d17 new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
508 for (unsigned int x = 0; x < source.GetWidth(); x++)
9161e3ef0d17 new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
509 {
9161e3ef0d17 new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
510 q[0] = *p;
9161e3ef0d17 new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
511 q[1] = *p;
9161e3ef0d17 new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
512 q[2] = *p;
9161e3ef0d17 new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
513 q[3] = 255;
9161e3ef0d17 new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
514 p += 1;
9161e3ef0d17 new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
515 q += 4;
9161e3ef0d17 new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
516 }
9161e3ef0d17 new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
517 }
9161e3ef0d17 new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
518
9161e3ef0d17 new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
519 return;
9161e3ef0d17 new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
520 }
9161e3ef0d17 new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
521
854
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
522 throw OrthancException(ErrorCode_NotImplemented);
853
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
523 }
854
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
524
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
525
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
526
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
527 void ImageProcessing::Set(ImageAccessor& image,
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
528 int64_t value)
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
529 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
530 switch (image.GetFormat())
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
531 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
532 case PixelFormat_Grayscale8:
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
533 SetInternal<uint8_t>(image, value);
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
534 return;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
535
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
536 case PixelFormat_Grayscale16:
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
537 SetInternal<uint16_t>(image, value);
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
538 return;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
539
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
540 case PixelFormat_SignedGrayscale16:
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
541 SetInternal<int16_t>(image, value);
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
542 return;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
543
1994
4d099fee5eca ImageProcessing::Set for float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1993
diff changeset
544 case PixelFormat_Float32:
4d099fee5eca ImageProcessing::Set for float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1993
diff changeset
545 assert(sizeof(float) == 4);
4d099fee5eca ImageProcessing::Set for float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1993
diff changeset
546 SetInternal<float>(image, value);
4d099fee5eca ImageProcessing::Set for float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1993
diff changeset
547 return;
4d099fee5eca ImageProcessing::Set for float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1993
diff changeset
548
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
549 default:
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
550 throw OrthancException(ErrorCode_NotImplemented);
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
551 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
552 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
553
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
554
854
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
555 void ImageProcessing::ShiftRight(ImageAccessor& image,
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
556 unsigned int shift)
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
557 {
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
558 if (image.GetWidth() == 0 ||
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
559 image.GetHeight() == 0 ||
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
560 shift == 0)
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
561 {
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
562 // Nothing to do
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
563 return;
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
564 }
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
565
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
566 throw OrthancException(ErrorCode_NotImplemented);
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
567 }
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
568
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
569
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
570 void ImageProcessing::GetMinMaxValue(int64_t& minValue,
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
571 int64_t& maxValue,
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
572 const ImageAccessor& image)
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
573 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
574 switch (image.GetFormat())
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
575 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
576 case PixelFormat_Grayscale8:
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
577 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
578 uint8_t a, b;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
579 GetMinMaxValueInternal<uint8_t>(a, b, image);
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
580 minValue = a;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
581 maxValue = b;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
582 break;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
583 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
584
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
585 case PixelFormat_Grayscale16:
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
586 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
587 uint16_t a, b;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
588 GetMinMaxValueInternal<uint16_t>(a, b, image);
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
589 minValue = a;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
590 maxValue = b;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
591 break;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
592 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
593
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
594 case PixelFormat_SignedGrayscale16:
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
595 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
596 int16_t a, b;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
597 GetMinMaxValueInternal<int16_t>(a, b, image);
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
598 minValue = a;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
599 maxValue = b;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
600 break;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
601 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
602
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
603 default:
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
604 throw OrthancException(ErrorCode_NotImplemented);
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
605 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
606 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
607
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
608
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
609
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
610 void ImageProcessing::AddConstant(ImageAccessor& image,
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
611 int64_t value)
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
612 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
613 switch (image.GetFormat())
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
614 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
615 case PixelFormat_Grayscale8:
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
616 AddConstantInternal<uint8_t>(image, value);
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
617 return;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
618
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
619 case PixelFormat_Grayscale16:
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
620 AddConstantInternal<uint16_t>(image, value);
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
621 return;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
622
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
623 case PixelFormat_SignedGrayscale16:
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
624 AddConstantInternal<int16_t>(image, value);
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
625 return;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
626
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
627 default:
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
628 throw OrthancException(ErrorCode_NotImplemented);
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
629 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
630 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
631
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
632
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
633 void ImageProcessing::MultiplyConstant(ImageAccessor& image,
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
634 float factor)
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
635 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
636 switch (image.GetFormat())
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
637 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
638 case PixelFormat_Grayscale8:
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
639 MultiplyConstantInternal<uint8_t>(image, factor);
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
640 return;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
641
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
642 case PixelFormat_Grayscale16:
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
643 MultiplyConstantInternal<uint16_t>(image, factor);
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
644 return;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
645
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
646 case PixelFormat_SignedGrayscale16:
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
647 MultiplyConstantInternal<int16_t>(image, factor);
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
648 return;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
649
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
650 default:
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
651 throw OrthancException(ErrorCode_NotImplemented);
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
652 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
653 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
654
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
655
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
656 void ImageProcessing::ShiftScale(ImageAccessor& image,
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
657 float offset,
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
658 float scaling)
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
659 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
660 switch (image.GetFormat())
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
661 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
662 case PixelFormat_Grayscale8:
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
663 ShiftScaleInternal<uint8_t>(image, offset, scaling);
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
664 return;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
665
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
666 case PixelFormat_Grayscale16:
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
667 ShiftScaleInternal<uint16_t>(image, offset, scaling);
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
668 return;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
669
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
670 case PixelFormat_SignedGrayscale16:
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
671 ShiftScaleInternal<int16_t>(image, offset, scaling);
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
672 return;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
673
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
674 default:
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
675 throw OrthancException(ErrorCode_NotImplemented);
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
676 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
677 }
853
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
678 }