Mercurial > hg > orthanc
annotate OrthancFramework/Sources/Images/ImageProcessing.cpp @ 4104:d5c09b5f882f
publishing Orthanc::Semaphore in shared library
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 06 Jul 2020 11:45:39 +0200 |
parents | 26efd0404d97 |
children | bf7b9edf6b81 |
rev | line source |
---|---|
853 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
1900 | 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 |
3640
94f4a18a79cc
upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3600
diff
changeset
|
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium |
853 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU General Public License as | |
9 * published by the Free Software Foundation, either version 3 of the | |
10 * License, or (at your option) any later version. | |
11 * | |
12 * In addition, as a special exception, the copyright holders of this | |
13 * program give permission to link the code of its release with the | |
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
15 * that use the same license as the "OpenSSL" library), and distribute | |
16 * the linked executables. You must obey the GNU General Public License | |
17 * in all respects for all of the code used other than "OpenSSL". If you | |
18 * modify file(s) with this exception, you may extend this exception to | |
19 * your version of the file(s), but you are not obligated to do so. If | |
20 * you do not wish to do so, delete this exception statement from your | |
21 * version. If you delete this exception statement from all source files | |
22 * in the program, then also delete it here. | |
3227 | 23 * |
853 | 24 * This program is distributed in the hope that it will be useful, but |
25 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
27 * General Public License for more details. | |
28 * | |
29 * You should have received a copy of the GNU General Public License | |
30 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
31 **/ | |
32 | |
33 | |
34 #include "../PrecompiledHeaders.h" | |
35 #include "ImageProcessing.h" | |
36 | |
3502
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
37 #include "Image.h" |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
38 #include "ImageTraits.h" |
2489
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
39 #include "PixelTraits.h" |
2895 | 40 #include "../OrthancException.h" |
853 | 41 |
3585
113a9643e8bb
Suppressed a few warnings when building with emscripten (clang) + numeric truncation warnings
Benjamin Golinvaux <bgo@osimis.io>
parents:
3565
diff
changeset
|
42 #ifdef __EMSCRIPTEN__ |
113a9643e8bb
Suppressed a few warnings when building with emscripten (clang) + numeric truncation warnings
Benjamin Golinvaux <bgo@osimis.io>
parents:
3565
diff
changeset
|
43 /* |
3682
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
44 Avoid this error: |
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
45 ----------------- |
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
46 .../boost/math/special_functions/round.hpp:118:12: warning: implicit conversion from 'std::__2::numeric_limits<long long>::type' (aka 'long long') to 'float' changes value from 9223372036854775807 to 9223372036854775808 [-Wimplicit-int-float-conversion] |
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
47 .../mnt/c/osi/dev/orthanc/Core/Images/ImageProcessing.cpp:333:28: note: in instantiation of function template specialization 'boost::math::llround<float>' requested here |
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
48 .../mnt/c/osi/dev/orthanc/Core/Images/ImageProcessing.cpp:1006:9: note: in instantiation of function template specialization 'Orthanc::MultiplyConstantInternal<unsigned char, true>' requested here |
3585
113a9643e8bb
Suppressed a few warnings when building with emscripten (clang) + numeric truncation warnings
Benjamin Golinvaux <bgo@osimis.io>
parents:
3565
diff
changeset
|
49 */ |
113a9643e8bb
Suppressed a few warnings when building with emscripten (clang) + numeric truncation warnings
Benjamin Golinvaux <bgo@osimis.io>
parents:
3565
diff
changeset
|
50 #pragma GCC diagnostic ignored "-Wimplicit-int-float-conversion" |
113a9643e8bb
Suppressed a few warnings when building with emscripten (clang) + numeric truncation warnings
Benjamin Golinvaux <bgo@osimis.io>
parents:
3565
diff
changeset
|
51 #endif |
113a9643e8bb
Suppressed a few warnings when building with emscripten (clang) + numeric truncation warnings
Benjamin Golinvaux <bgo@osimis.io>
parents:
3565
diff
changeset
|
52 |
863 | 53 #include <boost/math/special_functions/round.hpp> |
54 | |
853 | 55 #include <cassert> |
56 #include <string.h> | |
859
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
57 #include <limits> |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
58 #include <stdint.h> |
3258 | 59 #include <algorithm> |
859
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
60 |
853 | 61 namespace Orthanc |
62 { | |
4056 | 63 void ImageProcessing::ImagePoint::ClipTo(int32_t minX, int32_t maxX, int32_t minY, int32_t maxY) |
64 { | |
65 x_ = std::max(minX, std::min(maxX, x_)); | |
66 y_ = std::max(minY, std::min(maxY, y_)); | |
67 } | |
68 | |
3265
59a184cbb596
ImagePoint::Set + GetDistanceTo
Alain Mazy <alain@mazy.be>
parents:
3259
diff
changeset
|
69 double ImageProcessing::ImagePoint::GetDistanceTo(const ImagePoint& other) const |
59a184cbb596
ImagePoint::Set + GetDistanceTo
Alain Mazy <alain@mazy.be>
parents:
3259
diff
changeset
|
70 { |
59a184cbb596
ImagePoint::Set + GetDistanceTo
Alain Mazy <alain@mazy.be>
parents:
3259
diff
changeset
|
71 double dx = (double)(other.GetX() - GetX()); |
59a184cbb596
ImagePoint::Set + GetDistanceTo
Alain Mazy <alain@mazy.be>
parents:
3259
diff
changeset
|
72 double dy = (double)(other.GetY() - GetY()); |
59a184cbb596
ImagePoint::Set + GetDistanceTo
Alain Mazy <alain@mazy.be>
parents:
3259
diff
changeset
|
73 return sqrt(dx * dx + dy * dy); |
59a184cbb596
ImagePoint::Set + GetDistanceTo
Alain Mazy <alain@mazy.be>
parents:
3259
diff
changeset
|
74 } |
59a184cbb596
ImagePoint::Set + GetDistanceTo
Alain Mazy <alain@mazy.be>
parents:
3259
diff
changeset
|
75 |
3565
2999a6e9456b
ImageProcessing::ImagePoint::GetDistanceToLine
Alain Mazy <alain@mazy.be>
parents:
3550
diff
changeset
|
76 double ImageProcessing::ImagePoint::GetDistanceToLine(double a, double b, double c) const // where ax + by + c = 0 is the equation of the line |
2999a6e9456b
ImageProcessing::ImagePoint::GetDistanceToLine
Alain Mazy <alain@mazy.be>
parents:
3550
diff
changeset
|
77 { |
2999a6e9456b
ImageProcessing::ImagePoint::GetDistanceToLine
Alain Mazy <alain@mazy.be>
parents:
3550
diff
changeset
|
78 return std::abs(a * static_cast<double>(GetX()) + b * static_cast<double>(GetY()) + c) / pow(a * a + b * b, 0.5); |
2999a6e9456b
ImageProcessing::ImagePoint::GetDistanceToLine
Alain Mazy <alain@mazy.be>
parents:
3550
diff
changeset
|
79 } |
2999a6e9456b
ImageProcessing::ImagePoint::GetDistanceToLine
Alain Mazy <alain@mazy.be>
parents:
3550
diff
changeset
|
80 |
859
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
81 template <typename TargetType, typename SourceType> |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
82 static void ConvertInternal(ImageAccessor& target, |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
83 const ImageAccessor& source) |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
84 { |
3525
8c66c9c2257b
fix ImageProcessing::ShiftScale() on float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3505
diff
changeset
|
85 // WARNING - "::min()" should be replaced by "::lowest()" if |
8c66c9c2257b
fix ImageProcessing::ShiftScale() on float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3505
diff
changeset
|
86 // dealing with float or double (which is not the case so far) |
8c66c9c2257b
fix ImageProcessing::ShiftScale() on float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3505
diff
changeset
|
87 assert(sizeof(TargetType) <= 2); // Safeguard to remember about "float/double" |
859
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
88 const TargetType minValue = std::numeric_limits<TargetType>::min(); |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
89 const TargetType maxValue = std::numeric_limits<TargetType>::max(); |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
90 |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
91 const unsigned int width = source.GetWidth(); |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
92 const unsigned int height = source.GetHeight(); |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
93 |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
94 for (unsigned int y = 0; y < height; y++) |
859
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
95 { |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
96 TargetType* t = reinterpret_cast<TargetType*>(target.GetRow(y)); |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
97 const SourceType* s = reinterpret_cast<const SourceType*>(source.GetConstRow(y)); |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
98 |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
99 for (unsigned int x = 0; x < width; x++, t++, s++) |
859
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
100 { |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
101 if (static_cast<int32_t>(*s) < static_cast<int32_t>(minValue)) |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
102 { |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
103 *t = minValue; |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
104 } |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
105 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
|
106 { |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
107 *t = maxValue; |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
108 } |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
109 else |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
110 { |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
111 *t = static_cast<TargetType>(*s); |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
112 } |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
113 } |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
114 } |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
115 } |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
116 |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
117 |
1993
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
118 template <typename SourceType> |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
119 static void ConvertGrayscaleToFloat(ImageAccessor& target, |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
120 const ImageAccessor& source) |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
121 { |
1994
4d099fee5eca
ImageProcessing::Set for float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1993
diff
changeset
|
122 assert(sizeof(float) == 4); |
4d099fee5eca
ImageProcessing::Set for float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1993
diff
changeset
|
123 |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
124 const unsigned int width = source.GetWidth(); |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
125 const unsigned int height = source.GetHeight(); |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
126 |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
127 for (unsigned int y = 0; y < height; y++) |
1993
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
128 { |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
129 float* t = reinterpret_cast<float*>(target.GetRow(y)); |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
130 const SourceType* s = reinterpret_cast<const SourceType*>(source.GetConstRow(y)); |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
131 |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
132 for (unsigned int x = 0; x < width; x++, t++, s++) |
1993
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
133 { |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
134 *t = static_cast<float>(*s); |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
135 } |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
136 } |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
137 } |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
138 |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
139 |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
140 template <PixelFormat TargetFormat> |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
141 static void ConvertFloatToGrayscale(ImageAccessor& target, |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
142 const ImageAccessor& source) |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
143 { |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
144 typedef typename PixelTraits<TargetFormat>::PixelType TargetType; |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
145 |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
146 assert(sizeof(float) == 4); |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
147 |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
148 const unsigned int width = source.GetWidth(); |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
149 const unsigned int height = source.GetHeight(); |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
150 |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
151 for (unsigned int y = 0; y < height; y++) |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
152 { |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
153 TargetType* q = reinterpret_cast<TargetType*>(target.GetRow(y)); |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
154 const float* p = reinterpret_cast<const float*>(source.GetConstRow(y)); |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
155 |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
156 for (unsigned int x = 0; x < width; x++, p++, q++) |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
157 { |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
158 PixelTraits<TargetFormat>::FloatToPixel(*q, *p); |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
159 } |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
160 } |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
161 } |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
162 |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
163 |
993
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
164 template <typename TargetType> |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
165 static void ConvertColorToGrayscale(ImageAccessor& target, |
1993
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
166 const ImageAccessor& source) |
993
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
167 { |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
168 assert(source.GetFormat() == PixelFormat_RGB24); |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
169 |
3525
8c66c9c2257b
fix ImageProcessing::ShiftScale() on float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3505
diff
changeset
|
170 // WARNING - "::min()" should be replaced by "::lowest()" if |
8c66c9c2257b
fix ImageProcessing::ShiftScale() on float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3505
diff
changeset
|
171 // dealing with float or double (which is not the case so far) |
8c66c9c2257b
fix ImageProcessing::ShiftScale() on float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3505
diff
changeset
|
172 assert(sizeof(TargetType) <= 2); // Safeguard to remember about "float/double" |
993
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
173 const TargetType minValue = std::numeric_limits<TargetType>::min(); |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
174 const TargetType maxValue = std::numeric_limits<TargetType>::max(); |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
175 |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
176 const unsigned int width = source.GetWidth(); |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
177 const unsigned int height = source.GetHeight(); |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
178 |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
179 for (unsigned int y = 0; y < height; y++) |
993
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
180 { |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
181 TargetType* t = reinterpret_cast<TargetType*>(target.GetRow(y)); |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
182 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
|
183 |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
184 for (unsigned int x = 0; x < width; x++, t++, s += 3) |
993
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
185 { |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
186 // 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
|
187 int32_t v = (2126 * static_cast<int32_t>(s[0]) + |
3499
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
188 7152 * static_cast<int32_t>(s[1]) + |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
189 0722 * static_cast<int32_t>(s[2])) / 10000; |
993
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
190 |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
191 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
|
192 { |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
193 *t = minValue; |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
194 } |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
195 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
|
196 { |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
197 *t = maxValue; |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
198 } |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
199 else |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
200 { |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
201 *t = static_cast<TargetType>(v); |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
202 } |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
203 } |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
204 } |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
205 } |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
206 |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
207 |
2902
e80b38fb22c6
fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
208 static void MemsetZeroInternal(ImageAccessor& image) |
3227 | 209 { |
2902
e80b38fb22c6
fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
210 const unsigned int height = image.GetHeight(); |
e80b38fb22c6
fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
211 const size_t lineSize = image.GetBytesPerPixel() * image.GetWidth(); |
e80b38fb22c6
fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
212 const size_t pitch = image.GetPitch(); |
e80b38fb22c6
fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
213 |
e80b38fb22c6
fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
214 uint8_t *p = reinterpret_cast<uint8_t*>(image.GetBuffer()); |
e80b38fb22c6
fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
215 |
e80b38fb22c6
fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
216 for (unsigned int y = 0; y < height; y++) |
e80b38fb22c6
fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
217 { |
e80b38fb22c6
fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
218 memset(p, 0, lineSize); |
e80b38fb22c6
fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
219 p += pitch; |
e80b38fb22c6
fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
220 } |
e80b38fb22c6
fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
221 } |
e80b38fb22c6
fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
222 |
e80b38fb22c6
fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
223 |
863 | 224 template <typename PixelType> |
225 static void SetInternal(ImageAccessor& image, | |
226 int64_t constant) | |
227 { | |
2902
e80b38fb22c6
fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
228 if (constant == 0 && |
e80b38fb22c6
fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
229 (image.GetFormat() == PixelFormat_Grayscale8 || |
e80b38fb22c6
fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
230 image.GetFormat() == PixelFormat_Grayscale16 || |
e80b38fb22c6
fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
231 image.GetFormat() == PixelFormat_Grayscale32 || |
e80b38fb22c6
fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
232 image.GetFormat() == PixelFormat_Grayscale64 || |
e80b38fb22c6
fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
233 image.GetFormat() == PixelFormat_SignedGrayscale16)) |
863 | 234 { |
2902
e80b38fb22c6
fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
235 MemsetZeroInternal(image); |
e80b38fb22c6
fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
236 } |
e80b38fb22c6
fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
237 else |
e80b38fb22c6
fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
238 { |
e80b38fb22c6
fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
239 const unsigned int width = image.GetWidth(); |
e80b38fb22c6
fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
240 const unsigned int height = image.GetHeight(); |
863 | 241 |
2902
e80b38fb22c6
fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
242 for (unsigned int y = 0; y < height; y++) |
863 | 243 { |
2902
e80b38fb22c6
fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
244 PixelType* p = reinterpret_cast<PixelType*>(image.GetRow(y)); |
e80b38fb22c6
fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
245 |
e80b38fb22c6
fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
246 for (unsigned int x = 0; x < width; x++, p++) |
e80b38fb22c6
fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
247 { |
e80b38fb22c6
fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
248 *p = static_cast<PixelType>(constant); |
e80b38fb22c6
fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
249 } |
863 | 250 } |
251 } | |
252 } | |
253 | |
254 | |
255 template <typename PixelType> | |
256 static void GetMinMaxValueInternal(PixelType& minValue, | |
257 PixelType& maxValue, | |
3525
8c66c9c2257b
fix ImageProcessing::ShiftScale() on float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3505
diff
changeset
|
258 const ImageAccessor& source, |
8c66c9c2257b
fix ImageProcessing::ShiftScale() on float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3505
diff
changeset
|
259 const PixelType LowestValue = std::numeric_limits<PixelType>::min()) |
863 | 260 { |
261 // Deal with the special case of empty image | |
262 if (source.GetWidth() == 0 || | |
263 source.GetHeight() == 0) | |
264 { | |
265 minValue = 0; | |
266 maxValue = 0; | |
267 return; | |
268 } | |
269 | |
270 minValue = std::numeric_limits<PixelType>::max(); | |
3525
8c66c9c2257b
fix ImageProcessing::ShiftScale() on float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3505
diff
changeset
|
271 maxValue = LowestValue; |
863 | 272 |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
273 const unsigned int height = source.GetHeight(); |
2482
509041cb57db
speedup by truncating instead of rounding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
274 const unsigned int width = source.GetWidth(); |
509041cb57db
speedup by truncating instead of rounding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
275 |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
276 for (unsigned int y = 0; y < height; y++) |
863 | 277 { |
278 const PixelType* p = reinterpret_cast<const PixelType*>(source.GetConstRow(y)); | |
279 | |
2482
509041cb57db
speedup by truncating instead of rounding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
280 for (unsigned int x = 0; x < width; x++, p++) |
863 | 281 { |
282 if (*p < minValue) | |
283 { | |
284 minValue = *p; | |
285 } | |
286 | |
287 if (*p > maxValue) | |
288 { | |
289 maxValue = *p; | |
290 } | |
291 } | |
292 } | |
293 } | |
294 | |
295 | |
296 | |
297 template <typename PixelType> | |
298 static void AddConstantInternal(ImageAccessor& image, | |
299 int64_t constant) | |
300 { | |
301 if (constant == 0) | |
302 { | |
303 return; | |
304 } | |
305 | |
3525
8c66c9c2257b
fix ImageProcessing::ShiftScale() on float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3505
diff
changeset
|
306 // WARNING - "::min()" should be replaced by "::lowest()" if |
8c66c9c2257b
fix ImageProcessing::ShiftScale() on float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3505
diff
changeset
|
307 // dealing with float or double (which is not the case so far) |
8c66c9c2257b
fix ImageProcessing::ShiftScale() on float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3505
diff
changeset
|
308 assert(sizeof(PixelType) <= 2); // Safeguard to remember about "float/double" |
863 | 309 const int64_t minValue = std::numeric_limits<PixelType>::min(); |
310 const int64_t maxValue = std::numeric_limits<PixelType>::max(); | |
311 | |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
312 const unsigned int width = image.GetWidth(); |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
313 const unsigned int height = image.GetHeight(); |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
314 |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
315 for (unsigned int y = 0; y < height; y++) |
863 | 316 { |
317 PixelType* p = reinterpret_cast<PixelType*>(image.GetRow(y)); | |
318 | |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
319 for (unsigned int x = 0; x < width; x++, p++) |
863 | 320 { |
321 int64_t v = static_cast<int64_t>(*p) + constant; | |
322 | |
323 if (v > maxValue) | |
324 { | |
876 | 325 *p = std::numeric_limits<PixelType>::max(); |
863 | 326 } |
327 else if (v < minValue) | |
328 { | |
876 | 329 *p = std::numeric_limits<PixelType>::min(); |
863 | 330 } |
331 else | |
332 { | |
333 *p = static_cast<PixelType>(v); | |
334 } | |
335 } | |
336 } | |
337 } | |
338 | |
339 | |
340 | |
2488
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
341 template <typename PixelType, |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
342 bool UseRound> |
2489
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
343 static void MultiplyConstantInternal(ImageAccessor& image, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
344 float factor) |
863 | 345 { |
1334 | 346 if (std::abs(factor - 1.0f) <= std::numeric_limits<float>::epsilon()) |
863 | 347 { |
348 return; | |
349 } | |
350 | |
3525
8c66c9c2257b
fix ImageProcessing::ShiftScale() on float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3505
diff
changeset
|
351 // WARNING - "::min()" should be replaced by "::lowest()" if |
8c66c9c2257b
fix ImageProcessing::ShiftScale() on float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3505
diff
changeset
|
352 // dealing with float or double (which is not the case so far) |
8c66c9c2257b
fix ImageProcessing::ShiftScale() on float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3505
diff
changeset
|
353 assert(sizeof(PixelType) <= 2); // Safeguard to remember about "float/double" |
863 | 354 const int64_t minValue = std::numeric_limits<PixelType>::min(); |
355 const int64_t maxValue = std::numeric_limits<PixelType>::max(); | |
356 | |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
357 const unsigned int width = image.GetWidth(); |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
358 const unsigned int height = image.GetHeight(); |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
359 |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
360 for (unsigned int y = 0; y < height; y++) |
863 | 361 { |
362 PixelType* p = reinterpret_cast<PixelType*>(image.GetRow(y)); | |
363 | |
2482
509041cb57db
speedup by truncating instead of rounding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
364 for (unsigned int x = 0; x < width; x++, p++) |
863 | 365 { |
2488
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
366 int64_t v; |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
367 if (UseRound) |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
368 { |
4065
d6362b2c4b61
export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4056
diff
changeset
|
369 assert(sizeof(long long) == sizeof(int64_t)); |
2488
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
370 // The "round" operation is very costly |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
371 v = boost::math::llround(static_cast<float>(*p) * factor); |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
372 } |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
373 else |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
374 { |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
375 v = static_cast<int64_t>(static_cast<float>(*p) * factor); |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
376 } |
863 | 377 |
378 if (v > maxValue) | |
379 { | |
876 | 380 *p = std::numeric_limits<PixelType>::max(); |
863 | 381 } |
382 else if (v < minValue) | |
383 { | |
876 | 384 *p = std::numeric_limits<PixelType>::min(); |
863 | 385 } |
386 else | |
387 { | |
388 *p = static_cast<PixelType>(v); | |
389 } | |
390 } | |
391 } | |
392 } | |
393 | |
394 | |
3682
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
395 // Computes "a * x + b" at each pixel => Note that this is not the |
4080
f18eaade6153
simplification in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4079
diff
changeset
|
396 // same convention as in "ShiftScale()", but it is the convention of |
f18eaade6153
simplification in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4079
diff
changeset
|
397 // "ShiftScale2()" |
3682
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
398 template <typename TargetType, |
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
399 typename SourceType, |
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
400 bool UseRound, |
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
401 bool Invert> |
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
402 static void ShiftScaleInternal(ImageAccessor& target, |
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
403 const ImageAccessor& source, |
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
404 float a, |
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
405 float b, |
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
406 const TargetType LowestValue) |
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
407 // This function can be applied inplace (source == target) |
863 | 408 { |
3682
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
409 if (source.GetWidth() != target.GetWidth() || |
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
410 source.GetHeight() != target.GetHeight()) |
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
411 { |
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
412 throw OrthancException(ErrorCode_IncompatibleImageSize); |
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
413 } |
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
414 |
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
415 if (&source == &target && |
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
416 source.GetFormat() != target.GetFormat()) |
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
417 { |
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
418 throw OrthancException(ErrorCode_IncompatibleImageFormat); |
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
419 } |
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
420 |
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
421 const TargetType minPixelValue = LowestValue; |
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
422 const TargetType maxPixelValue = std::numeric_limits<TargetType>::max(); |
3525
8c66c9c2257b
fix ImageProcessing::ShiftScale() on float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3505
diff
changeset
|
423 const float minFloatValue = static_cast<float>(LowestValue); |
8c66c9c2257b
fix ImageProcessing::ShiftScale() on float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3505
diff
changeset
|
424 const float maxFloatValue = static_cast<float>(maxPixelValue); |
863 | 425 |
3682
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
426 const unsigned int height = target.GetHeight(); |
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
427 const unsigned int width = target.GetWidth(); |
2482
509041cb57db
speedup by truncating instead of rounding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
428 |
509041cb57db
speedup by truncating instead of rounding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
429 for (unsigned int y = 0; y < height; y++) |
863 | 430 { |
3682
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
431 TargetType* p = reinterpret_cast<TargetType*>(target.GetRow(y)); |
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
432 const SourceType* q = reinterpret_cast<const SourceType*>(source.GetRow(y)); |
863 | 433 |
3682
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
434 for (unsigned int x = 0; x < width; x++, p++, q++) |
863 | 435 { |
3682
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
436 float v = a * static_cast<float>(*q) + b; |
863 | 437 |
3505
b2d4dd16dae8
removed C++11 primitive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3504
diff
changeset
|
438 if (v >= maxFloatValue) |
863 | 439 { |
2482
509041cb57db
speedup by truncating instead of rounding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
440 *p = maxPixelValue; |
863 | 441 } |
3505
b2d4dd16dae8
removed C++11 primitive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3504
diff
changeset
|
442 else if (v <= minFloatValue) |
863 | 443 { |
2482
509041cb57db
speedup by truncating instead of rounding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
444 *p = minPixelValue; |
863 | 445 } |
2488
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
446 else if (UseRound) |
4065
d6362b2c4b61
export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4056
diff
changeset
|
447 { |
2488
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
448 // The "round" operation is very costly |
4065
d6362b2c4b61
export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4056
diff
changeset
|
449 assert(sizeof(TargetType) < sizeof(int)); |
3682
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
450 *p = static_cast<TargetType>(boost::math::iround(v)); |
2488
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
451 } |
863 | 452 else |
453 { | |
3682
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
454 *p = static_cast<TargetType>(std::floor(v)); |
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
455 } |
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
456 |
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
457 if (Invert) |
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
458 { |
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
459 *p = maxPixelValue - *p; |
863 | 460 } |
461 } | |
462 } | |
463 } | |
464 | |
3545 | 465 template <typename PixelType> |
466 static void ShiftRightInternal(ImageAccessor& image, | |
467 unsigned int shift) | |
468 { | |
469 const unsigned int height = image.GetHeight(); | |
470 const unsigned int width = image.GetWidth(); | |
471 | |
472 for (unsigned int y = 0; y < height; y++) | |
473 { | |
474 PixelType* p = reinterpret_cast<PixelType*>(image.GetRow(y)); | |
475 | |
476 for (unsigned int x = 0; x < width; x++, p++) | |
477 { | |
478 *p = *p >> shift; | |
479 } | |
480 } | |
481 } | |
482 | |
483 template <typename PixelType> | |
484 static void ShiftLeftInternal(ImageAccessor& image, | |
485 unsigned int shift) | |
486 { | |
487 const unsigned int height = image.GetHeight(); | |
488 const unsigned int width = image.GetWidth(); | |
489 | |
490 for (unsigned int y = 0; y < height; y++) | |
491 { | |
492 PixelType* p = reinterpret_cast<PixelType*>(image.GetRow(y)); | |
493 | |
494 for (unsigned int x = 0; x < width; x++, p++) | |
495 { | |
496 *p = *p << shift; | |
497 } | |
498 } | |
499 } | |
859
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
500 |
853 | 501 void ImageProcessing::Copy(ImageAccessor& target, |
502 const ImageAccessor& source) | |
503 { | |
504 if (target.GetWidth() != source.GetWidth() || | |
505 target.GetHeight() != source.GetHeight()) | |
506 { | |
507 throw OrthancException(ErrorCode_IncompatibleImageSize); | |
508 } | |
509 | |
510 if (target.GetFormat() != source.GetFormat()) | |
511 { | |
512 throw OrthancException(ErrorCode_IncompatibleImageFormat); | |
513 } | |
514 | |
2902
e80b38fb22c6
fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
515 unsigned int lineSize = source.GetBytesPerPixel() * source.GetWidth(); |
853 | 516 |
517 assert(source.GetPitch() >= lineSize && target.GetPitch() >= lineSize); | |
518 | |
519 for (unsigned int y = 0; y < source.GetHeight(); y++) | |
520 { | |
854
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
521 memcpy(target.GetRow(y), source.GetConstRow(y), lineSize); |
853 | 522 } |
523 } | |
524 | |
3600
4066998150ef
/instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents:
3585
diff
changeset
|
525 template <typename TargetType, typename SourceType> |
4066998150ef
/instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents:
3585
diff
changeset
|
526 static void ApplyWindowingInternal(ImageAccessor& target, |
4066998150ef
/instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents:
3585
diff
changeset
|
527 const ImageAccessor& source, |
4066998150ef
/instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents:
3585
diff
changeset
|
528 float windowCenter, |
4066998150ef
/instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents:
3585
diff
changeset
|
529 float windowWidth, |
4066998150ef
/instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents:
3585
diff
changeset
|
530 float rescaleSlope, |
4066998150ef
/instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents:
3585
diff
changeset
|
531 float rescaleIntercept, |
4066998150ef
/instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents:
3585
diff
changeset
|
532 bool invert) |
4066998150ef
/instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents:
3585
diff
changeset
|
533 { |
3682
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
534 assert(sizeof(SourceType) == source.GetBytesPerPixel() && |
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
535 sizeof(TargetType) == target.GetBytesPerPixel()); |
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
536 |
3600
4066998150ef
/instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents:
3585
diff
changeset
|
537 // WARNING - "::min()" should be replaced by "::lowest()" if |
4066998150ef
/instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents:
3585
diff
changeset
|
538 // dealing with float or double (which is not the case so far) |
4066998150ef
/instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents:
3585
diff
changeset
|
539 assert(sizeof(TargetType) <= 2); // Safeguard to remember about "float/double" |
4066998150ef
/instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents:
3585
diff
changeset
|
540 const TargetType minTargetValue = std::numeric_limits<TargetType>::min(); |
4066998150ef
/instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents:
3585
diff
changeset
|
541 const TargetType maxTargetValue = std::numeric_limits<TargetType>::max(); |
4066998150ef
/instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents:
3585
diff
changeset
|
542 const float maxFloatValue = static_cast<float>(maxTargetValue); |
3682
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
543 |
3600
4066998150ef
/instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents:
3585
diff
changeset
|
544 const float windowIntercept = windowCenter - windowWidth / 2.0f; |
4066998150ef
/instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents:
3585
diff
changeset
|
545 const float windowSlope = (maxFloatValue + 1.0f) / windowWidth; |
4066998150ef
/instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents:
3585
diff
changeset
|
546 |
3682
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
547 const float a = rescaleSlope * windowSlope; |
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
548 const float b = (rescaleIntercept - windowIntercept) * windowSlope; |
3600
4066998150ef
/instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents:
3585
diff
changeset
|
549 |
3682
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
550 if (invert) |
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
551 { |
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
552 ShiftScaleInternal<TargetType, SourceType, false, true>(target, source, a, b, minTargetValue); |
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
553 } |
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
554 else |
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
555 { |
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
556 ShiftScaleInternal<TargetType, SourceType, false, false>(target, source, a, b, minTargetValue); |
3600
4066998150ef
/instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents:
3585
diff
changeset
|
557 } |
4066998150ef
/instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents:
3585
diff
changeset
|
558 } |
854
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
559 |
3683
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3682
diff
changeset
|
560 void ImageProcessing::ApplyWindowing_Deprecated(ImageAccessor& target, |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3682
diff
changeset
|
561 const ImageAccessor& source, |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3682
diff
changeset
|
562 float windowCenter, |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3682
diff
changeset
|
563 float windowWidth, |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3682
diff
changeset
|
564 float rescaleSlope, |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3682
diff
changeset
|
565 float rescaleIntercept, |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3682
diff
changeset
|
566 bool invert) |
3548
e1ce68692069
ImageProcessing::ApplyWindowing
Alain Mazy <alain@mazy.be>
parents:
3547
diff
changeset
|
567 { |
e1ce68692069
ImageProcessing::ApplyWindowing
Alain Mazy <alain@mazy.be>
parents:
3547
diff
changeset
|
568 if (target.GetWidth() != source.GetWidth() || |
e1ce68692069
ImageProcessing::ApplyWindowing
Alain Mazy <alain@mazy.be>
parents:
3547
diff
changeset
|
569 target.GetHeight() != source.GetHeight()) |
e1ce68692069
ImageProcessing::ApplyWindowing
Alain Mazy <alain@mazy.be>
parents:
3547
diff
changeset
|
570 { |
e1ce68692069
ImageProcessing::ApplyWindowing
Alain Mazy <alain@mazy.be>
parents:
3547
diff
changeset
|
571 throw OrthancException(ErrorCode_IncompatibleImageSize); |
e1ce68692069
ImageProcessing::ApplyWindowing
Alain Mazy <alain@mazy.be>
parents:
3547
diff
changeset
|
572 } |
e1ce68692069
ImageProcessing::ApplyWindowing
Alain Mazy <alain@mazy.be>
parents:
3547
diff
changeset
|
573 |
3600
4066998150ef
/instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents:
3585
diff
changeset
|
574 switch (source.GetFormat()) |
3548
e1ce68692069
ImageProcessing::ApplyWindowing
Alain Mazy <alain@mazy.be>
parents:
3547
diff
changeset
|
575 { |
3600
4066998150ef
/instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents:
3585
diff
changeset
|
576 case Orthanc::PixelFormat_Float32: |
3548
e1ce68692069
ImageProcessing::ApplyWindowing
Alain Mazy <alain@mazy.be>
parents:
3547
diff
changeset
|
577 { |
3600
4066998150ef
/instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents:
3585
diff
changeset
|
578 switch (target.GetFormat()) |
3548
e1ce68692069
ImageProcessing::ApplyWindowing
Alain Mazy <alain@mazy.be>
parents:
3547
diff
changeset
|
579 { |
3682
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
580 case Orthanc::PixelFormat_Grayscale8: |
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
581 ApplyWindowingInternal<uint8_t, float>(target, source, windowCenter, windowWidth, rescaleSlope, rescaleIntercept, invert); |
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
582 break; |
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
583 case Orthanc::PixelFormat_Grayscale16: |
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
584 ApplyWindowingInternal<uint16_t, float>(target, source, windowCenter, windowWidth, rescaleSlope, rescaleIntercept, invert); |
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
585 break; |
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
586 default: |
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
587 throw OrthancException(ErrorCode_NotImplemented); |
3548
e1ce68692069
ImageProcessing::ApplyWindowing
Alain Mazy <alain@mazy.be>
parents:
3547
diff
changeset
|
588 } |
3600
4066998150ef
/instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents:
3585
diff
changeset
|
589 };break; |
4066998150ef
/instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents:
3585
diff
changeset
|
590 case Orthanc::PixelFormat_Grayscale8: |
4066998150ef
/instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents:
3585
diff
changeset
|
591 { |
4066998150ef
/instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents:
3585
diff
changeset
|
592 switch (target.GetFormat()) |
3548
e1ce68692069
ImageProcessing::ApplyWindowing
Alain Mazy <alain@mazy.be>
parents:
3547
diff
changeset
|
593 { |
3682
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
594 case Orthanc::PixelFormat_Grayscale8: |
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
595 ApplyWindowingInternal<uint8_t, uint8_t>(target, source, windowCenter, windowWidth, rescaleSlope, rescaleIntercept, invert); |
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
596 break; |
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
597 case Orthanc::PixelFormat_Grayscale16: |
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
598 ApplyWindowingInternal<uint16_t, uint8_t>(target, source, windowCenter, windowWidth, rescaleSlope, rescaleIntercept, invert); |
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
599 break; |
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
600 default: |
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
601 throw OrthancException(ErrorCode_NotImplemented); |
3548
e1ce68692069
ImageProcessing::ApplyWindowing
Alain Mazy <alain@mazy.be>
parents:
3547
diff
changeset
|
602 } |
3600
4066998150ef
/instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents:
3585
diff
changeset
|
603 };break; |
4066998150ef
/instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents:
3585
diff
changeset
|
604 case Orthanc::PixelFormat_Grayscale16: |
4066998150ef
/instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents:
3585
diff
changeset
|
605 { |
4066998150ef
/instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents:
3585
diff
changeset
|
606 switch (target.GetFormat()) |
3548
e1ce68692069
ImageProcessing::ApplyWindowing
Alain Mazy <alain@mazy.be>
parents:
3547
diff
changeset
|
607 { |
3682
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
608 case Orthanc::PixelFormat_Grayscale8: |
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
609 ApplyWindowingInternal<uint8_t, uint16_t>(target, source, windowCenter, windowWidth, rescaleSlope, rescaleIntercept, invert); |
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
610 break; |
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
611 case Orthanc::PixelFormat_Grayscale16: |
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
612 ApplyWindowingInternal<uint16_t, uint16_t>(target, source, windowCenter, windowWidth, rescaleSlope, rescaleIntercept, invert); |
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
613 break; |
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
614 default: |
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
615 throw OrthancException(ErrorCode_NotImplemented); |
3548
e1ce68692069
ImageProcessing::ApplyWindowing
Alain Mazy <alain@mazy.be>
parents:
3547
diff
changeset
|
616 } |
3600
4066998150ef
/instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents:
3585
diff
changeset
|
617 };break; |
4066998150ef
/instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents:
3585
diff
changeset
|
618 default: |
4066998150ef
/instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents:
3585
diff
changeset
|
619 throw OrthancException(ErrorCode_NotImplemented); |
3548
e1ce68692069
ImageProcessing::ApplyWindowing
Alain Mazy <alain@mazy.be>
parents:
3547
diff
changeset
|
620 } |
e1ce68692069
ImageProcessing::ApplyWindowing
Alain Mazy <alain@mazy.be>
parents:
3547
diff
changeset
|
621 } |
e1ce68692069
ImageProcessing::ApplyWindowing
Alain Mazy <alain@mazy.be>
parents:
3547
diff
changeset
|
622 |
e1ce68692069
ImageProcessing::ApplyWindowing
Alain Mazy <alain@mazy.be>
parents:
3547
diff
changeset
|
623 |
853 | 624 void ImageProcessing::Convert(ImageAccessor& target, |
625 const ImageAccessor& source) | |
626 { | |
627 if (target.GetWidth() != source.GetWidth() || | |
628 target.GetHeight() != source.GetHeight()) | |
629 { | |
630 throw OrthancException(ErrorCode_IncompatibleImageSize); | |
631 } | |
632 | |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
633 const unsigned int width = source.GetWidth(); |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
634 const unsigned int height = source.GetHeight(); |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
635 |
853 | 636 if (source.GetFormat() == target.GetFormat()) |
637 { | |
638 Copy(target, source); | |
639 return; | |
640 } | |
854
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
641 |
859
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
642 if (target.GetFormat() == PixelFormat_Grayscale16 && |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
643 source.GetFormat() == PixelFormat_Grayscale8) |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
644 { |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
645 ConvertInternal<uint16_t, uint8_t>(target, source); |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
646 return; |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
647 } |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
648 |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
649 if (target.GetFormat() == PixelFormat_SignedGrayscale16 && |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
650 source.GetFormat() == PixelFormat_Grayscale8) |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
651 { |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
652 ConvertInternal<int16_t, uint8_t>(target, source); |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
653 return; |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
654 } |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
655 |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
656 if (target.GetFormat() == PixelFormat_Grayscale8 && |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
657 source.GetFormat() == PixelFormat_Grayscale16) |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
658 { |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
659 ConvertInternal<uint8_t, uint16_t>(target, source); |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
660 return; |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
661 } |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
662 |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
663 if (target.GetFormat() == PixelFormat_SignedGrayscale16 && |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
664 source.GetFormat() == PixelFormat_Grayscale16) |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
665 { |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
666 ConvertInternal<int16_t, uint16_t>(target, source); |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
667 return; |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
668 } |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
669 |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
670 if (target.GetFormat() == PixelFormat_Grayscale8 && |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
671 source.GetFormat() == PixelFormat_SignedGrayscale16) |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
672 { |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
673 ConvertInternal<uint8_t, int16_t>(target, source); |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
674 return; |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
675 } |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
676 |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
677 if (target.GetFormat() == PixelFormat_Grayscale16 && |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
678 source.GetFormat() == PixelFormat_SignedGrayscale16) |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
679 { |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
680 ConvertInternal<uint16_t, int16_t>(target, source); |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
681 return; |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
682 } |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
683 |
993
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
684 if (target.GetFormat() == PixelFormat_Grayscale8 && |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
685 source.GetFormat() == PixelFormat_RGB24) |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
686 { |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
687 ConvertColorToGrayscale<uint8_t>(target, source); |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
688 return; |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
689 } |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
690 |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
691 if (target.GetFormat() == PixelFormat_Grayscale16 && |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
692 source.GetFormat() == PixelFormat_RGB24) |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
693 { |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
694 ConvertColorToGrayscale<uint16_t>(target, source); |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
695 return; |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
696 } |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
697 |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
698 if (target.GetFormat() == PixelFormat_SignedGrayscale16 && |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
699 source.GetFormat() == PixelFormat_RGB24) |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
700 { |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
701 ConvertColorToGrayscale<int16_t>(target, source); |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
702 return; |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
703 } |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
704 |
1993
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
705 if (target.GetFormat() == PixelFormat_Float32 && |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
706 source.GetFormat() == PixelFormat_Grayscale8) |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
707 { |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
708 ConvertGrayscaleToFloat<uint8_t>(target, source); |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
709 return; |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
710 } |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
711 |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
712 if (target.GetFormat() == PixelFormat_Float32 && |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
713 source.GetFormat() == PixelFormat_Grayscale16) |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
714 { |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
715 ConvertGrayscaleToFloat<uint16_t>(target, source); |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
716 return; |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
717 } |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
718 |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
719 if (target.GetFormat() == PixelFormat_Float32 && |
2415
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
720 source.GetFormat() == PixelFormat_Grayscale32) |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
721 { |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
722 ConvertGrayscaleToFloat<uint32_t>(target, source); |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
723 return; |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
724 } |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
725 |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
726 if (target.GetFormat() == PixelFormat_Float32 && |
1993
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
727 source.GetFormat() == PixelFormat_SignedGrayscale16) |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
728 { |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
729 ConvertGrayscaleToFloat<int16_t>(target, source); |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
730 return; |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
731 } |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
732 |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
733 |
1610
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
734 if (target.GetFormat() == PixelFormat_Grayscale8 && |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
735 source.GetFormat() == PixelFormat_RGBA32) |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
736 { |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
737 for (unsigned int y = 0; y < height; y++) |
1610
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
738 { |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
739 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
|
740 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y)); |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
741 for (unsigned int x = 0; x < width; x++, q++) |
1610
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
742 { |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
743 *q = static_cast<uint8_t>((2126 * static_cast<uint32_t>(p[0]) + |
3499
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
744 7152 * static_cast<uint32_t>(p[1]) + |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
745 0722 * static_cast<uint32_t>(p[2])) / 10000); |
1610
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
746 p += 4; |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
747 } |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
748 } |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
749 |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
750 return; |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
751 } |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
752 |
2840
f4c232bba1eb
bgra32 to grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2783
diff
changeset
|
753 if (target.GetFormat() == PixelFormat_Grayscale8 && |
f4c232bba1eb
bgra32 to grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2783
diff
changeset
|
754 source.GetFormat() == PixelFormat_BGRA32) |
f4c232bba1eb
bgra32 to grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2783
diff
changeset
|
755 { |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
756 for (unsigned int y = 0; y < height; y++) |
2840
f4c232bba1eb
bgra32 to grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2783
diff
changeset
|
757 { |
f4c232bba1eb
bgra32 to grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2783
diff
changeset
|
758 const uint8_t* p = reinterpret_cast<const uint8_t*>(source.GetConstRow(y)); |
f4c232bba1eb
bgra32 to grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2783
diff
changeset
|
759 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y)); |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
760 for (unsigned int x = 0; x < width; x++, q++) |
2840
f4c232bba1eb
bgra32 to grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2783
diff
changeset
|
761 { |
f4c232bba1eb
bgra32 to grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2783
diff
changeset
|
762 *q = static_cast<uint8_t>((2126 * static_cast<uint32_t>(p[2]) + |
3499
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
763 7152 * static_cast<uint32_t>(p[1]) + |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
764 0722 * static_cast<uint32_t>(p[0])) / 10000); |
2840
f4c232bba1eb
bgra32 to grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2783
diff
changeset
|
765 p += 4; |
f4c232bba1eb
bgra32 to grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2783
diff
changeset
|
766 } |
f4c232bba1eb
bgra32 to grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2783
diff
changeset
|
767 } |
f4c232bba1eb
bgra32 to grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2783
diff
changeset
|
768 |
f4c232bba1eb
bgra32 to grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2783
diff
changeset
|
769 return; |
f4c232bba1eb
bgra32 to grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2783
diff
changeset
|
770 } |
f4c232bba1eb
bgra32 to grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2783
diff
changeset
|
771 |
1608
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
772 if (target.GetFormat() == PixelFormat_RGB24 && |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
773 source.GetFormat() == PixelFormat_RGBA32) |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
774 { |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
775 for (unsigned int y = 0; y < height; y++) |
1608
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
776 { |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
777 const uint8_t* p = reinterpret_cast<const uint8_t*>(source.GetConstRow(y)); |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
778 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y)); |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
779 for (unsigned int x = 0; x < width; x++) |
1608
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
780 { |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
781 q[0] = p[0]; |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
782 q[1] = p[1]; |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
783 q[2] = p[2]; |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
784 p += 4; |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
785 q += 3; |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
786 } |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
787 } |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
788 |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
789 return; |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
790 } |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
791 |
2252
002b94046c69
colorspace conversion from BGRA32 to RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
792 if (target.GetFormat() == PixelFormat_RGB24 && |
002b94046c69
colorspace conversion from BGRA32 to RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
793 source.GetFormat() == PixelFormat_BGRA32) |
002b94046c69
colorspace conversion from BGRA32 to RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
794 { |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
795 for (unsigned int y = 0; y < height; y++) |
2252
002b94046c69
colorspace conversion from BGRA32 to RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
796 { |
002b94046c69
colorspace conversion from BGRA32 to RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
797 const uint8_t* p = reinterpret_cast<const uint8_t*>(source.GetConstRow(y)); |
002b94046c69
colorspace conversion from BGRA32 to RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
798 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y)); |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
799 for (unsigned int x = 0; x < width; x++) |
2252
002b94046c69
colorspace conversion from BGRA32 to RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
800 { |
002b94046c69
colorspace conversion from BGRA32 to RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
801 q[0] = p[2]; |
002b94046c69
colorspace conversion from BGRA32 to RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
802 q[1] = p[1]; |
002b94046c69
colorspace conversion from BGRA32 to RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
803 q[2] = p[0]; |
002b94046c69
colorspace conversion from BGRA32 to RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
804 p += 4; |
002b94046c69
colorspace conversion from BGRA32 to RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
805 q += 3; |
002b94046c69
colorspace conversion from BGRA32 to RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
806 } |
002b94046c69
colorspace conversion from BGRA32 to RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
807 } |
002b94046c69
colorspace conversion from BGRA32 to RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
808 |
002b94046c69
colorspace conversion from BGRA32 to RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
809 return; |
002b94046c69
colorspace conversion from BGRA32 to RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
810 } |
002b94046c69
colorspace conversion from BGRA32 to RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
811 |
1608
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
812 if (target.GetFormat() == PixelFormat_RGBA32 && |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
813 source.GetFormat() == PixelFormat_RGB24) |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
814 { |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
815 for (unsigned int y = 0; y < height; y++) |
1608
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
816 { |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
817 const uint8_t* p = reinterpret_cast<const uint8_t*>(source.GetConstRow(y)); |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
818 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y)); |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
819 for (unsigned int x = 0; x < width; x++) |
1608
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
820 { |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
821 q[0] = p[0]; |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
822 q[1] = p[1]; |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
823 q[2] = p[2]; |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
824 q[3] = 255; // Set the alpha channel to full opacity |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
825 p += 3; |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
826 q += 4; |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
827 } |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
828 } |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
829 |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
830 return; |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
831 } |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
832 |
1992
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
833 if (target.GetFormat() == PixelFormat_RGB24 && |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
834 source.GetFormat() == PixelFormat_Grayscale8) |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
835 { |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
836 for (unsigned int y = 0; y < height; y++) |
1992
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
837 { |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
838 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
|
839 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y)); |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
840 for (unsigned int x = 0; x < width; x++) |
1992
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
841 { |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
842 q[0] = *p; |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
843 q[1] = *p; |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
844 q[2] = *p; |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
845 p += 1; |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
846 q += 3; |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
847 } |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
848 } |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
849 |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
850 return; |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
851 } |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
852 |
2650 | 853 if ((target.GetFormat() == PixelFormat_RGBA32 || |
854 target.GetFormat() == PixelFormat_BGRA32) && | |
1992
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
855 source.GetFormat() == PixelFormat_Grayscale8) |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
856 { |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
857 for (unsigned int y = 0; y < height; y++) |
1992
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
858 { |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
859 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
|
860 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y)); |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
861 for (unsigned int x = 0; x < width; x++) |
1992
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
862 { |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
863 q[0] = *p; |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
864 q[1] = *p; |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
865 q[2] = *p; |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
866 q[3] = 255; |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
867 p += 1; |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
868 q += 4; |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
869 } |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
870 } |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
871 |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
872 return; |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
873 } |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
874 |
2100
1554fc153a93
conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2089
diff
changeset
|
875 if (target.GetFormat() == PixelFormat_BGRA32 && |
2495
cd7b854dbc05
convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2491
diff
changeset
|
876 source.GetFormat() == PixelFormat_Grayscale16) |
cd7b854dbc05
convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2491
diff
changeset
|
877 { |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
878 for (unsigned int y = 0; y < height; y++) |
2495
cd7b854dbc05
convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2491
diff
changeset
|
879 { |
cd7b854dbc05
convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2491
diff
changeset
|
880 const uint16_t* p = reinterpret_cast<const uint16_t*>(source.GetConstRow(y)); |
cd7b854dbc05
convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2491
diff
changeset
|
881 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y)); |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
882 for (unsigned int x = 0; x < width; x++) |
2495
cd7b854dbc05
convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2491
diff
changeset
|
883 { |
cd7b854dbc05
convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2491
diff
changeset
|
884 uint8_t value = (*p < 256 ? *p : 255); |
cd7b854dbc05
convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2491
diff
changeset
|
885 q[0] = value; |
cd7b854dbc05
convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2491
diff
changeset
|
886 q[1] = value; |
cd7b854dbc05
convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2491
diff
changeset
|
887 q[2] = value; |
cd7b854dbc05
convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2491
diff
changeset
|
888 q[3] = 255; |
cd7b854dbc05
convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2491
diff
changeset
|
889 p += 1; |
cd7b854dbc05
convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2491
diff
changeset
|
890 q += 4; |
cd7b854dbc05
convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2491
diff
changeset
|
891 } |
cd7b854dbc05
convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2491
diff
changeset
|
892 } |
cd7b854dbc05
convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2491
diff
changeset
|
893 |
cd7b854dbc05
convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2491
diff
changeset
|
894 return; |
cd7b854dbc05
convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2491
diff
changeset
|
895 } |
cd7b854dbc05
convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2491
diff
changeset
|
896 |
cd7b854dbc05
convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2491
diff
changeset
|
897 if (target.GetFormat() == PixelFormat_BGRA32 && |
2496
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
898 source.GetFormat() == PixelFormat_SignedGrayscale16) |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
899 { |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
900 for (unsigned int y = 0; y < height; y++) |
2496
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
901 { |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
902 const int16_t* p = reinterpret_cast<const int16_t*>(source.GetConstRow(y)); |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
903 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y)); |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
904 for (unsigned int x = 0; x < width; x++) |
2496
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
905 { |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
906 uint8_t value; |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
907 if (*p < 0) |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
908 { |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
909 value = 0; |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
910 } |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
911 else if (*p > 255) |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
912 { |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
913 value = 255; |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
914 } |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
915 else |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
916 { |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
917 value = static_cast<uint8_t>(*p); |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
918 } |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
919 |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
920 q[0] = value; |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
921 q[1] = value; |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
922 q[2] = value; |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
923 q[3] = 255; |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
924 p += 1; |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
925 q += 4; |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
926 } |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
927 } |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
928 |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
929 return; |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
930 } |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
931 |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
932 if (target.GetFormat() == PixelFormat_BGRA32 && |
2100
1554fc153a93
conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2089
diff
changeset
|
933 source.GetFormat() == PixelFormat_RGB24) |
1554fc153a93
conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2089
diff
changeset
|
934 { |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
935 for (unsigned int y = 0; y < height; y++) |
2100
1554fc153a93
conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2089
diff
changeset
|
936 { |
1554fc153a93
conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2089
diff
changeset
|
937 const uint8_t* p = reinterpret_cast<const uint8_t*>(source.GetConstRow(y)); |
1554fc153a93
conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2089
diff
changeset
|
938 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y)); |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
939 for (unsigned int x = 0; x < width; x++) |
2100
1554fc153a93
conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2089
diff
changeset
|
940 { |
1554fc153a93
conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2089
diff
changeset
|
941 q[0] = p[2]; |
1554fc153a93
conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2089
diff
changeset
|
942 q[1] = p[1]; |
1554fc153a93
conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2089
diff
changeset
|
943 q[2] = p[0]; |
1554fc153a93
conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2089
diff
changeset
|
944 q[3] = 255; |
1554fc153a93
conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2089
diff
changeset
|
945 p += 3; |
1554fc153a93
conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2089
diff
changeset
|
946 q += 4; |
1554fc153a93
conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2089
diff
changeset
|
947 } |
1554fc153a93
conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2089
diff
changeset
|
948 } |
1554fc153a93
conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2089
diff
changeset
|
949 |
1554fc153a93
conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2089
diff
changeset
|
950 return; |
1554fc153a93
conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2089
diff
changeset
|
951 } |
1554fc153a93
conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2089
diff
changeset
|
952 |
3547
dabe17e23e23
Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents:
3545
diff
changeset
|
953 if ((target.GetFormat() == PixelFormat_BGRA32 && |
dabe17e23e23
Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents:
3545
diff
changeset
|
954 source.GetFormat() == PixelFormat_RGBA32) |
dabe17e23e23
Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents:
3545
diff
changeset
|
955 || (target.GetFormat() == PixelFormat_RGBA32 && |
dabe17e23e23
Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents:
3545
diff
changeset
|
956 source.GetFormat() == PixelFormat_BGRA32)) |
dabe17e23e23
Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents:
3545
diff
changeset
|
957 { |
dabe17e23e23
Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents:
3545
diff
changeset
|
958 for (unsigned int y = 0; y < height; y++) |
dabe17e23e23
Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents:
3545
diff
changeset
|
959 { |
dabe17e23e23
Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents:
3545
diff
changeset
|
960 const uint8_t* p = reinterpret_cast<const uint8_t*>(source.GetConstRow(y)); |
dabe17e23e23
Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents:
3545
diff
changeset
|
961 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y)); |
dabe17e23e23
Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents:
3545
diff
changeset
|
962 for (unsigned int x = 0; x < width; x++) |
dabe17e23e23
Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents:
3545
diff
changeset
|
963 { |
dabe17e23e23
Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents:
3545
diff
changeset
|
964 q[0] = p[2]; |
dabe17e23e23
Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents:
3545
diff
changeset
|
965 q[1] = p[1]; |
dabe17e23e23
Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents:
3545
diff
changeset
|
966 q[2] = p[0]; |
dabe17e23e23
Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents:
3545
diff
changeset
|
967 q[3] = p[3]; |
dabe17e23e23
Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents:
3545
diff
changeset
|
968 p += 4; |
dabe17e23e23
Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents:
3545
diff
changeset
|
969 q += 4; |
dabe17e23e23
Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents:
3545
diff
changeset
|
970 } |
dabe17e23e23
Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents:
3545
diff
changeset
|
971 } |
dabe17e23e23
Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents:
3545
diff
changeset
|
972 |
dabe17e23e23
Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents:
3545
diff
changeset
|
973 return; |
dabe17e23e23
Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents:
3545
diff
changeset
|
974 } |
dabe17e23e23
Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents:
3545
diff
changeset
|
975 |
2423
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
976 if (target.GetFormat() == PixelFormat_RGB24 && |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
977 source.GetFormat() == PixelFormat_RGB48) |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
978 { |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
979 for (unsigned int y = 0; y < height; y++) |
2423
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
980 { |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
981 const uint16_t* p = reinterpret_cast<const uint16_t*>(source.GetConstRow(y)); |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
982 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y)); |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
983 for (unsigned int x = 0; x < width; x++) |
2423
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
984 { |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
985 q[0] = p[0] >> 8; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
986 q[1] = p[1] >> 8; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
987 q[2] = p[2] >> 8; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
988 p += 3; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
989 q += 3; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
990 } |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
991 } |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
992 |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
993 return; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
994 } |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
995 |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
996 if (target.GetFormat() == PixelFormat_Grayscale16 && |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
997 source.GetFormat() == PixelFormat_Float32) |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
998 { |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
999 ConvertFloatToGrayscale<PixelFormat_Grayscale16>(target, source); |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
1000 return; |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
1001 } |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
1002 |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
1003 if (target.GetFormat() == PixelFormat_Grayscale8 && |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
1004 source.GetFormat() == PixelFormat_Float32) |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
1005 { |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
1006 ConvertFloatToGrayscale<PixelFormat_Grayscale8>(target, source); |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
1007 return; |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
1008 } |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
1009 |
854
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1010 throw OrthancException(ErrorCode_NotImplemented); |
853 | 1011 } |
854
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1012 |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1013 |
863 | 1014 |
1015 void ImageProcessing::Set(ImageAccessor& image, | |
1016 int64_t value) | |
1017 { | |
1018 switch (image.GetFormat()) | |
1019 { | |
3499
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1020 case PixelFormat_Grayscale8: |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1021 SetInternal<uint8_t>(image, value); |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1022 return; |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1023 |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1024 case PixelFormat_Grayscale16: |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1025 SetInternal<uint16_t>(image, value); |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1026 return; |
863 | 1027 |
3499
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1028 case PixelFormat_Grayscale32: |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1029 SetInternal<uint32_t>(image, value); |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1030 return; |
863 | 1031 |
3499
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1032 case PixelFormat_Grayscale64: |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1033 SetInternal<uint64_t>(image, value); |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1034 return; |
2415
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
1035 |
3499
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1036 case PixelFormat_SignedGrayscale16: |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1037 SetInternal<int16_t>(image, value); |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1038 return; |
2645
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2496
diff
changeset
|
1039 |
3499
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1040 case PixelFormat_Float32: |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1041 assert(sizeof(float) == 4); |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1042 SetInternal<float>(image, value); |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1043 return; |
863 | 1044 |
3499
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1045 case PixelFormat_RGBA32: |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1046 case PixelFormat_BGRA32: |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1047 case PixelFormat_RGB24: |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1048 { |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1049 uint8_t v = static_cast<uint8_t>(value); |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1050 Set(image, v, v, v, v); // Use the color version |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1051 return; |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1052 } |
1994
4d099fee5eca
ImageProcessing::Set for float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1993
diff
changeset
|
1053 |
3499
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1054 default: |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1055 throw OrthancException(ErrorCode_NotImplemented); |
863 | 1056 } |
1057 } | |
1058 | |
1059 | |
2089
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
1060 void ImageProcessing::Set(ImageAccessor& image, |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
1061 uint8_t red, |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
1062 uint8_t green, |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
1063 uint8_t blue, |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
1064 uint8_t alpha) |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
1065 { |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
1066 uint8_t p[4]; |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
1067 unsigned int size; |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
1068 |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
1069 switch (image.GetFormat()) |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
1070 { |
3499
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1071 case PixelFormat_RGBA32: |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1072 p[0] = red; |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1073 p[1] = green; |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1074 p[2] = blue; |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1075 p[3] = alpha; |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1076 size = 4; |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1077 break; |
2089
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
1078 |
3499
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1079 case PixelFormat_BGRA32: |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1080 p[0] = blue; |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1081 p[1] = green; |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1082 p[2] = red; |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1083 p[3] = alpha; |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1084 size = 4; |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1085 break; |
2089
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
1086 |
3499
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1087 case PixelFormat_RGB24: |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1088 p[0] = red; |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1089 p[1] = green; |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1090 p[2] = blue; |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1091 size = 3; |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1092 break; |
2089
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
1093 |
3499
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1094 default: |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1095 throw OrthancException(ErrorCode_NotImplemented); |
3227 | 1096 } |
2089
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
1097 |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
1098 const unsigned int width = image.GetWidth(); |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
1099 const unsigned int height = image.GetHeight(); |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
1100 |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
1101 for (unsigned int y = 0; y < height; y++) |
2089
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
1102 { |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
1103 uint8_t* q = reinterpret_cast<uint8_t*>(image.GetRow(y)); |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
1104 |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
1105 for (unsigned int x = 0; x < width; x++) |
2089
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
1106 { |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
1107 for (unsigned int i = 0; i < size; i++) |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
1108 { |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
1109 q[i] = p[i]; |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
1110 } |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
1111 |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
1112 q += size; |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
1113 } |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
1114 } |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
1115 } |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
1116 |
3547
dabe17e23e23
Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents:
3545
diff
changeset
|
1117 void ImageProcessing::Set(ImageAccessor& image, |
3548
e1ce68692069
ImageProcessing::ApplyWindowing
Alain Mazy <alain@mazy.be>
parents:
3547
diff
changeset
|
1118 uint8_t red, |
e1ce68692069
ImageProcessing::ApplyWindowing
Alain Mazy <alain@mazy.be>
parents:
3547
diff
changeset
|
1119 uint8_t green, |
e1ce68692069
ImageProcessing::ApplyWindowing
Alain Mazy <alain@mazy.be>
parents:
3547
diff
changeset
|
1120 uint8_t blue, |
e1ce68692069
ImageProcessing::ApplyWindowing
Alain Mazy <alain@mazy.be>
parents:
3547
diff
changeset
|
1121 ImageAccessor& alpha) |
3547
dabe17e23e23
Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents:
3545
diff
changeset
|
1122 { |
dabe17e23e23
Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents:
3545
diff
changeset
|
1123 uint8_t p[4]; |
dabe17e23e23
Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents:
3545
diff
changeset
|
1124 |
dabe17e23e23
Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents:
3545
diff
changeset
|
1125 if (alpha.GetWidth() != image.GetWidth() || alpha.GetHeight() != image.GetHeight()) |
dabe17e23e23
Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents:
3545
diff
changeset
|
1126 { |
dabe17e23e23
Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents:
3545
diff
changeset
|
1127 throw OrthancException(ErrorCode_IncompatibleImageSize); |
dabe17e23e23
Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents:
3545
diff
changeset
|
1128 } |
dabe17e23e23
Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents:
3545
diff
changeset
|
1129 |
dabe17e23e23
Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents:
3545
diff
changeset
|
1130 if (alpha.GetFormat() != PixelFormat_Grayscale8) |
dabe17e23e23
Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents:
3545
diff
changeset
|
1131 { |
dabe17e23e23
Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents:
3545
diff
changeset
|
1132 throw OrthancException(ErrorCode_NotImplemented); |
dabe17e23e23
Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents:
3545
diff
changeset
|
1133 } |
dabe17e23e23
Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents:
3545
diff
changeset
|
1134 |
dabe17e23e23
Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents:
3545
diff
changeset
|
1135 switch (image.GetFormat()) |
dabe17e23e23
Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents:
3545
diff
changeset
|
1136 { |
dabe17e23e23
Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents:
3545
diff
changeset
|
1137 case PixelFormat_RGBA32: |
dabe17e23e23
Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents:
3545
diff
changeset
|
1138 p[0] = red; |
dabe17e23e23
Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents:
3545
diff
changeset
|
1139 p[1] = green; |
dabe17e23e23
Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents:
3545
diff
changeset
|
1140 p[2] = blue; |
dabe17e23e23
Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents:
3545
diff
changeset
|
1141 break; |
dabe17e23e23
Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents:
3545
diff
changeset
|
1142 |
dabe17e23e23
Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents:
3545
diff
changeset
|
1143 case PixelFormat_BGRA32: |
dabe17e23e23
Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents:
3545
diff
changeset
|
1144 p[0] = blue; |
dabe17e23e23
Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents:
3545
diff
changeset
|
1145 p[1] = green; |
dabe17e23e23
Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents:
3545
diff
changeset
|
1146 p[2] = red; |
dabe17e23e23
Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents:
3545
diff
changeset
|
1147 break; |
dabe17e23e23
Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents:
3545
diff
changeset
|
1148 |
dabe17e23e23
Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents:
3545
diff
changeset
|
1149 default: |
dabe17e23e23
Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents:
3545
diff
changeset
|
1150 throw OrthancException(ErrorCode_NotImplemented); |
dabe17e23e23
Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents:
3545
diff
changeset
|
1151 } |
dabe17e23e23
Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents:
3545
diff
changeset
|
1152 |
dabe17e23e23
Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents:
3545
diff
changeset
|
1153 const unsigned int width = image.GetWidth(); |
dabe17e23e23
Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents:
3545
diff
changeset
|
1154 const unsigned int height = image.GetHeight(); |
dabe17e23e23
Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents:
3545
diff
changeset
|
1155 |
dabe17e23e23
Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents:
3545
diff
changeset
|
1156 for (unsigned int y = 0; y < height; y++) |
dabe17e23e23
Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents:
3545
diff
changeset
|
1157 { |
dabe17e23e23
Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents:
3545
diff
changeset
|
1158 uint8_t* q = reinterpret_cast<uint8_t*>(image.GetRow(y)); |
dabe17e23e23
Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents:
3545
diff
changeset
|
1159 uint8_t* a = reinterpret_cast<uint8_t*>(alpha.GetRow(y)); |
dabe17e23e23
Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents:
3545
diff
changeset
|
1160 |
dabe17e23e23
Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents:
3545
diff
changeset
|
1161 for (unsigned int x = 0; x < width; x++) |
dabe17e23e23
Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents:
3545
diff
changeset
|
1162 { |
dabe17e23e23
Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents:
3545
diff
changeset
|
1163 for (unsigned int i = 0; i < 3; i++) |
dabe17e23e23
Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents:
3545
diff
changeset
|
1164 { |
dabe17e23e23
Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents:
3545
diff
changeset
|
1165 q[i] = p[i]; |
dabe17e23e23
Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents:
3545
diff
changeset
|
1166 } |
dabe17e23e23
Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents:
3545
diff
changeset
|
1167 q[3] = *a; |
dabe17e23e23
Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents:
3545
diff
changeset
|
1168 q += 4; |
dabe17e23e23
Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents:
3545
diff
changeset
|
1169 ++a; |
dabe17e23e23
Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents:
3545
diff
changeset
|
1170 } |
dabe17e23e23
Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents:
3545
diff
changeset
|
1171 } |
dabe17e23e23
Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents:
3545
diff
changeset
|
1172 } |
dabe17e23e23
Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents:
3545
diff
changeset
|
1173 |
2089
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
1174 |
854
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1175 void ImageProcessing::ShiftRight(ImageAccessor& image, |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1176 unsigned int shift) |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1177 { |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1178 if (image.GetWidth() == 0 || |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1179 image.GetHeight() == 0 || |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1180 shift == 0) |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1181 { |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1182 // Nothing to do |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1183 return; |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1184 } |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1185 |
3545 | 1186 switch (image.GetFormat()) |
1187 { | |
1188 case PixelFormat_Grayscale8: | |
1189 { | |
1190 ShiftRightInternal<uint8_t>(image, shift); | |
1191 break; | |
1192 } | |
1193 | |
1194 case PixelFormat_Grayscale16: | |
1195 { | |
1196 ShiftRightInternal<uint16_t>(image, shift); | |
1197 break; | |
1198 } | |
3682
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1199 default: |
3545 | 1200 throw OrthancException(ErrorCode_NotImplemented); |
1201 } | |
854
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1202 } |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1203 |
3545 | 1204 void ImageProcessing::ShiftLeft(ImageAccessor& image, |
1205 unsigned int shift) | |
1206 { | |
1207 if (image.GetWidth() == 0 || | |
1208 image.GetHeight() == 0 || | |
1209 shift == 0) | |
1210 { | |
1211 // Nothing to do | |
1212 return; | |
1213 } | |
1214 | |
1215 switch (image.GetFormat()) | |
1216 { | |
1217 case PixelFormat_Grayscale8: | |
1218 { | |
1219 ShiftLeftInternal<uint8_t>(image, shift); | |
1220 break; | |
1221 } | |
1222 | |
1223 case PixelFormat_Grayscale16: | |
1224 { | |
1225 ShiftLeftInternal<uint16_t>(image, shift); | |
1226 break; | |
1227 } | |
3682
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1228 default: |
3545 | 1229 throw OrthancException(ErrorCode_NotImplemented); |
1230 } | |
1231 } | |
863 | 1232 |
2415
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
1233 void ImageProcessing::GetMinMaxIntegerValue(int64_t& minValue, |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
1234 int64_t& maxValue, |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
1235 const ImageAccessor& image) |
863 | 1236 { |
1237 switch (image.GetFormat()) | |
1238 { | |
3499
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1239 case PixelFormat_Grayscale8: |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1240 { |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1241 uint8_t a, b; |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1242 GetMinMaxValueInternal<uint8_t>(a, b, image); |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1243 minValue = a; |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1244 maxValue = b; |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1245 break; |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1246 } |
863 | 1247 |
3499
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1248 case PixelFormat_Grayscale16: |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1249 { |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1250 uint16_t a, b; |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1251 GetMinMaxValueInternal<uint16_t>(a, b, image); |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1252 minValue = a; |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1253 maxValue = b; |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1254 break; |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1255 } |
863 | 1256 |
3499
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1257 case PixelFormat_Grayscale32: |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1258 { |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1259 uint32_t a, b; |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1260 GetMinMaxValueInternal<uint32_t>(a, b, image); |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1261 minValue = a; |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1262 maxValue = b; |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1263 break; |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1264 } |
2415
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
1265 |
3499
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1266 case PixelFormat_SignedGrayscale16: |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1267 { |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1268 int16_t a, b; |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1269 GetMinMaxValueInternal<int16_t>(a, b, image); |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1270 minValue = a; |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1271 maxValue = b; |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1272 break; |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1273 } |
863 | 1274 |
3499
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1275 default: |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1276 throw OrthancException(ErrorCode_NotImplemented); |
863 | 1277 } |
1278 } | |
1279 | |
1280 | |
2415
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
1281 void ImageProcessing::GetMinMaxFloatValue(float& minValue, |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
1282 float& maxValue, |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
1283 const ImageAccessor& image) |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
1284 { |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
1285 switch (image.GetFormat()) |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
1286 { |
3499
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1287 case PixelFormat_Float32: |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1288 { |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1289 assert(sizeof(float) == 4); |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1290 float a, b; |
3525
8c66c9c2257b
fix ImageProcessing::ShiftScale() on float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3505
diff
changeset
|
1291 |
8c66c9c2257b
fix ImageProcessing::ShiftScale() on float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3505
diff
changeset
|
1292 /** |
8c66c9c2257b
fix ImageProcessing::ShiftScale() on float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3505
diff
changeset
|
1293 * WARNING - On floating-point types, the minimal value is |
8c66c9c2257b
fix ImageProcessing::ShiftScale() on float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3505
diff
changeset
|
1294 * "-FLT_MAX" (as implemented by "::lowest()"), not "FLT_MIN" |
8c66c9c2257b
fix ImageProcessing::ShiftScale() on float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3505
diff
changeset
|
1295 * (as implemented by "::min()") |
8c66c9c2257b
fix ImageProcessing::ShiftScale() on float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3505
diff
changeset
|
1296 * https://en.cppreference.com/w/cpp/types/numeric_limits |
8c66c9c2257b
fix ImageProcessing::ShiftScale() on float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3505
diff
changeset
|
1297 **/ |
8c66c9c2257b
fix ImageProcessing::ShiftScale() on float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3505
diff
changeset
|
1298 GetMinMaxValueInternal<float>(a, b, image, -std::numeric_limits<float>::max()); |
3499
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1299 minValue = a; |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1300 maxValue = b; |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1301 break; |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1302 } |
2415
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
1303 |
3499
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1304 default: |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1305 throw OrthancException(ErrorCode_NotImplemented); |
2415
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
1306 } |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
1307 } |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
1308 |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
1309 |
863 | 1310 |
1311 void ImageProcessing::AddConstant(ImageAccessor& image, | |
1312 int64_t value) | |
1313 { | |
1314 switch (image.GetFormat()) | |
1315 { | |
3499
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1316 case PixelFormat_Grayscale8: |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1317 AddConstantInternal<uint8_t>(image, value); |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1318 return; |
863 | 1319 |
3499
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1320 case PixelFormat_Grayscale16: |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1321 AddConstantInternal<uint16_t>(image, value); |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1322 return; |
863 | 1323 |
3499
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1324 case PixelFormat_SignedGrayscale16: |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1325 AddConstantInternal<int16_t>(image, value); |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1326 return; |
863 | 1327 |
3499
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1328 default: |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1329 throw OrthancException(ErrorCode_NotImplemented); |
863 | 1330 } |
1331 } | |
1332 | |
1333 | |
1334 void ImageProcessing::MultiplyConstant(ImageAccessor& image, | |
2488
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
1335 float factor, |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
1336 bool useRound) |
863 | 1337 { |
1338 switch (image.GetFormat()) | |
1339 { | |
3499
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1340 case PixelFormat_Grayscale8: |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1341 if (useRound) |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1342 { |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1343 MultiplyConstantInternal<uint8_t, true>(image, factor); |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1344 } |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1345 else |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1346 { |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1347 MultiplyConstantInternal<uint8_t, false>(image, factor); |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1348 } |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1349 return; |
863 | 1350 |
3499
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1351 case PixelFormat_Grayscale16: |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1352 if (useRound) |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1353 { |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1354 MultiplyConstantInternal<uint16_t, true>(image, factor); |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1355 } |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1356 else |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1357 { |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1358 MultiplyConstantInternal<uint16_t, false>(image, factor); |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1359 } |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1360 return; |
863 | 1361 |
3499
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1362 case PixelFormat_SignedGrayscale16: |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1363 if (useRound) |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1364 { |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1365 MultiplyConstantInternal<int16_t, true>(image, factor); |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1366 } |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1367 else |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1368 { |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1369 MultiplyConstantInternal<int16_t, false>(image, factor); |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1370 } |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1371 return; |
863 | 1372 |
3499
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1373 default: |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1374 throw OrthancException(ErrorCode_NotImplemented); |
863 | 1375 } |
1376 } | |
1377 | |
1378 | |
4080
f18eaade6153
simplification in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4079
diff
changeset
|
1379 void ImageProcessing::ShiftScale2(ImageAccessor& image, |
f18eaade6153
simplification in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4079
diff
changeset
|
1380 float offset, |
f18eaade6153
simplification in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4079
diff
changeset
|
1381 float scaling, |
f18eaade6153
simplification in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4079
diff
changeset
|
1382 bool useRound) |
863 | 1383 { |
4080
f18eaade6153
simplification in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4079
diff
changeset
|
1384 // We compute "a * x + b" |
3682
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1385 const float a = scaling; |
4080
f18eaade6153
simplification in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4079
diff
changeset
|
1386 const float b = offset; |
3682
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1387 |
863 | 1388 switch (image.GetFormat()) |
1389 { | |
3499
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1390 case PixelFormat_Grayscale8: |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1391 if (useRound) |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1392 { |
3682
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1393 ShiftScaleInternal<uint8_t, uint8_t, true, false>(image, image, a, b, std::numeric_limits<uint8_t>::min()); |
3499
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1394 } |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1395 else |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1396 { |
3682
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1397 ShiftScaleInternal<uint8_t, uint8_t, false, false>(image, image, a, b, std::numeric_limits<uint8_t>::min()); |
3499
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1398 } |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1399 return; |
863 | 1400 |
3499
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1401 case PixelFormat_Grayscale16: |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1402 if (useRound) |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1403 { |
3682
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1404 ShiftScaleInternal<uint16_t, uint16_t, true, false>(image, image, a, b, std::numeric_limits<uint16_t>::min()); |
3499
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1405 } |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1406 else |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1407 { |
3682
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1408 ShiftScaleInternal<uint16_t, uint16_t, false, false>(image, image, a, b, std::numeric_limits<uint16_t>::min()); |
3499
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1409 } |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1410 return; |
863 | 1411 |
3499
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1412 case PixelFormat_SignedGrayscale16: |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1413 if (useRound) |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1414 { |
3682
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1415 ShiftScaleInternal<int16_t, int16_t, true, false>(image, image, a, b, std::numeric_limits<int16_t>::min()); |
3499
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1416 } |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1417 else |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1418 { |
3682
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1419 ShiftScaleInternal<int16_t, int16_t, false, false>(image, image, a, b, std::numeric_limits<int16_t>::min()); |
3499
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1420 } |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1421 return; |
863 | 1422 |
3505
b2d4dd16dae8
removed C++11 primitive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3504
diff
changeset
|
1423 case PixelFormat_Float32: |
3684
3971ec6b1f72
fix for older compilers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1424 // "::min()" must be replaced by "::lowest()" or "-::max()" if dealing with float or double. |
3505
b2d4dd16dae8
removed C++11 primitive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3504
diff
changeset
|
1425 if (useRound) |
b2d4dd16dae8
removed C++11 primitive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3504
diff
changeset
|
1426 { |
3684
3971ec6b1f72
fix for older compilers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1427 ShiftScaleInternal<float, float, true, false>(image, image, a, b, -std::numeric_limits<float>::max()); |
3505
b2d4dd16dae8
removed C++11 primitive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3504
diff
changeset
|
1428 } |
b2d4dd16dae8
removed C++11 primitive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3504
diff
changeset
|
1429 else |
b2d4dd16dae8
removed C++11 primitive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3504
diff
changeset
|
1430 { |
3684
3971ec6b1f72
fix for older compilers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1431 ShiftScaleInternal<float, float, false, false>(image, image, a, b, -std::numeric_limits<float>::max()); |
3505
b2d4dd16dae8
removed C++11 primitive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3504
diff
changeset
|
1432 } |
b2d4dd16dae8
removed C++11 primitive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3504
diff
changeset
|
1433 return; |
b2d4dd16dae8
removed C++11 primitive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3504
diff
changeset
|
1434 |
3499
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1435 default: |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1436 throw OrthancException(ErrorCode_NotImplemented); |
863 | 1437 } |
1438 } | |
2281
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2252
diff
changeset
|
1439 |
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2252
diff
changeset
|
1440 |
4080
f18eaade6153
simplification in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4079
diff
changeset
|
1441 void ImageProcessing::ShiftScale2(ImageAccessor& target, |
f18eaade6153
simplification in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4079
diff
changeset
|
1442 const ImageAccessor& source, |
f18eaade6153
simplification in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4079
diff
changeset
|
1443 float offset, |
f18eaade6153
simplification in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4079
diff
changeset
|
1444 float scaling, |
f18eaade6153
simplification in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4079
diff
changeset
|
1445 bool useRound) |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3684
diff
changeset
|
1446 { |
4080
f18eaade6153
simplification in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4079
diff
changeset
|
1447 // We compute "a * x + b" |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3684
diff
changeset
|
1448 const float a = scaling; |
4080
f18eaade6153
simplification in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4079
diff
changeset
|
1449 const float b = offset; |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3684
diff
changeset
|
1450 |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3684
diff
changeset
|
1451 switch (target.GetFormat()) |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3684
diff
changeset
|
1452 { |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3684
diff
changeset
|
1453 case PixelFormat_Grayscale8: |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3684
diff
changeset
|
1454 |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3684
diff
changeset
|
1455 switch (source.GetFormat()) |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3684
diff
changeset
|
1456 { |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3684
diff
changeset
|
1457 case PixelFormat_Float32: |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3684
diff
changeset
|
1458 if (useRound) |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3684
diff
changeset
|
1459 { |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3684
diff
changeset
|
1460 ShiftScaleInternal<uint8_t, float, true, false>( |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3684
diff
changeset
|
1461 target, source, a, b, std::numeric_limits<uint8_t>::min()); |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3684
diff
changeset
|
1462 } |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3684
diff
changeset
|
1463 else |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3684
diff
changeset
|
1464 { |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3684
diff
changeset
|
1465 ShiftScaleInternal<uint8_t, float, false, false>( |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3684
diff
changeset
|
1466 target, source, a, b, std::numeric_limits<uint8_t>::min()); |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3684
diff
changeset
|
1467 } |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3684
diff
changeset
|
1468 return; |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3684
diff
changeset
|
1469 |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3684
diff
changeset
|
1470 default: |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3684
diff
changeset
|
1471 throw OrthancException(ErrorCode_NotImplemented); |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3684
diff
changeset
|
1472 } |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3684
diff
changeset
|
1473 |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3684
diff
changeset
|
1474 default: |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3684
diff
changeset
|
1475 throw OrthancException(ErrorCode_NotImplemented); |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3684
diff
changeset
|
1476 } |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3684
diff
changeset
|
1477 } |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3684
diff
changeset
|
1478 |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3684
diff
changeset
|
1479 |
4080
f18eaade6153
simplification in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4079
diff
changeset
|
1480 void ImageProcessing::ShiftScale(ImageAccessor& image, |
f18eaade6153
simplification in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4079
diff
changeset
|
1481 float offset, |
f18eaade6153
simplification in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4079
diff
changeset
|
1482 float scaling, |
f18eaade6153
simplification in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4079
diff
changeset
|
1483 bool useRound) |
4079
73c22208272f
ImageProcessing::ShiftScale2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
1484 { |
4080
f18eaade6153
simplification in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4079
diff
changeset
|
1485 // Rewrite "(x + offset) * scaling" as "a * x + b" |
f18eaade6153
simplification in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4079
diff
changeset
|
1486 |
f18eaade6153
simplification in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4079
diff
changeset
|
1487 const float a = scaling; |
f18eaade6153
simplification in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4079
diff
changeset
|
1488 const float b = offset * scaling; |
f18eaade6153
simplification in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4079
diff
changeset
|
1489 ShiftScale2(image, b, a, useRound); |
4079
73c22208272f
ImageProcessing::ShiftScale2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
1490 } |
73c22208272f
ImageProcessing::ShiftScale2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
1491 |
73c22208272f
ImageProcessing::ShiftScale2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
1492 |
4080
f18eaade6153
simplification in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4079
diff
changeset
|
1493 void ImageProcessing::ShiftScale(ImageAccessor& target, |
f18eaade6153
simplification in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4079
diff
changeset
|
1494 const ImageAccessor& source, |
f18eaade6153
simplification in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4079
diff
changeset
|
1495 float offset, |
f18eaade6153
simplification in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4079
diff
changeset
|
1496 float scaling, |
f18eaade6153
simplification in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4079
diff
changeset
|
1497 bool useRound) |
4079
73c22208272f
ImageProcessing::ShiftScale2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
1498 { |
4080
f18eaade6153
simplification in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4079
diff
changeset
|
1499 // Rewrite "(x + offset) * scaling" as "a * x + b" |
f18eaade6153
simplification in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4079
diff
changeset
|
1500 |
f18eaade6153
simplification in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4079
diff
changeset
|
1501 const float a = scaling; |
f18eaade6153
simplification in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4079
diff
changeset
|
1502 const float b = offset * scaling; |
f18eaade6153
simplification in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4079
diff
changeset
|
1503 ShiftScale2(target, source, b, a, useRound); |
4079
73c22208272f
ImageProcessing::ShiftScale2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
1504 } |
73c22208272f
ImageProcessing::ShiftScale2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
1505 |
73c22208272f
ImageProcessing::ShiftScale2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
1506 |
73c22208272f
ImageProcessing::ShiftScale2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
1507 |
3227 | 1508 void ImageProcessing::Invert(ImageAccessor& image, int64_t maxValue) |
1509 { | |
1510 const unsigned int width = image.GetWidth(); | |
1511 const unsigned int height = image.GetHeight(); | |
1512 | |
1513 switch (image.GetFormat()) | |
1514 { | |
3499
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1515 case PixelFormat_Grayscale16: |
3227 | 1516 { |
3499
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1517 uint16_t maxValueUint16 = (uint16_t)(std::min(maxValue, static_cast<int64_t>(std::numeric_limits<uint16_t>::max()))); |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1518 |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1519 for (unsigned int y = 0; y < height; y++) |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1520 { |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1521 uint16_t* p = reinterpret_cast<uint16_t*>(image.GetRow(y)); |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1522 |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1523 for (unsigned int x = 0; x < width; x++, p++) |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1524 { |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1525 *p = maxValueUint16 - (*p); |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1526 } |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1527 } |
3227 | 1528 |
3499
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1529 return; |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1530 } |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1531 case PixelFormat_Grayscale8: |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1532 { |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1533 uint8_t maxValueUint8 = (uint8_t)(std::min(maxValue, static_cast<int64_t>(std::numeric_limits<uint8_t>::max()))); |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1534 |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1535 for (unsigned int y = 0; y < height; y++) |
3227 | 1536 { |
3499
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1537 uint8_t* p = reinterpret_cast<uint8_t*>(image.GetRow(y)); |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1538 |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1539 for (unsigned int x = 0; x < width; x++, p++) |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1540 { |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1541 *p = maxValueUint8 - (*p); |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1542 } |
3227 | 1543 } |
3499
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1544 |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1545 return; |
3227 | 1546 } |
1547 | |
3499
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1548 default: |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1549 throw OrthancException(ErrorCode_NotImplemented); |
3227 | 1550 } |
1551 | |
1552 } | |
1553 | |
2281
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2252
diff
changeset
|
1554 void ImageProcessing::Invert(ImageAccessor& image) |
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2252
diff
changeset
|
1555 { |
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2252
diff
changeset
|
1556 switch (image.GetFormat()) |
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2252
diff
changeset
|
1557 { |
3499
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1558 case PixelFormat_Grayscale8: |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1559 return Invert(image, 255); |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1560 default: |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1561 throw OrthancException(ErrorCode_NotImplemented); // you should use the Invert(image, maxValue) overload |
3227 | 1562 } |
2281
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2252
diff
changeset
|
1563 } |
2489
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1564 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1565 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1566 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1567 namespace |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1568 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1569 template <Orthanc::PixelFormat Format> |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1570 class BresenhamPixelWriter |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1571 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1572 private: |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1573 typedef typename PixelTraits<Format>::PixelType PixelType; |
3227 | 1574 |
2489
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1575 Orthanc::ImageAccessor& image_; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1576 PixelType value_; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1577 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1578 void PlotLineLow(int x0, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1579 int y0, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1580 int x1, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1581 int y1) |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1582 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1583 int dx = x1 - x0; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1584 int dy = y1 - y0; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1585 int yi = 1; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1586 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1587 if (dy < 0) |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1588 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1589 yi = -1; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1590 dy = -dy; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1591 } |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1592 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1593 int d = 2 * dy - dx; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1594 int y = y0; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1595 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1596 for (int x = x0; x <= x1; x++) |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1597 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1598 Write(x, y); |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1599 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1600 if (d > 0) |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1601 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1602 y = y + yi; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1603 d = d - 2 * dx; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1604 } |
3227 | 1605 |
2489
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1606 d = d + 2*dy; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1607 } |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1608 } |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1609 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1610 void PlotLineHigh(int x0, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1611 int y0, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1612 int x1, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1613 int y1) |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1614 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1615 int dx = x1 - x0; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1616 int dy = y1 - y0; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1617 int xi = 1; |
3227 | 1618 |
2489
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1619 if (dx < 0) |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1620 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1621 xi = -1; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1622 dx = -dx; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1623 } |
3227 | 1624 |
2489
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1625 int d = 2 * dx - dy; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1626 int x = x0; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1627 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1628 for (int y = y0; y <= y1; y++) |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1629 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1630 Write(x, y); |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1631 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1632 if (d > 0) |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1633 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1634 x = x + xi; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1635 d = d - 2 * dy; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1636 } |
3227 | 1637 |
2489
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1638 d = d + 2 * dx; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1639 } |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1640 } |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1641 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1642 public: |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1643 BresenhamPixelWriter(Orthanc::ImageAccessor& image, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1644 int64_t value) : |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1645 image_(image), |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1646 value_(PixelTraits<Format>::IntegerToPixel(value)) |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1647 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1648 } |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1649 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1650 BresenhamPixelWriter(Orthanc::ImageAccessor& image, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1651 const PixelType& value) : |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1652 image_(image), |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1653 value_(value) |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1654 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1655 } |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1656 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1657 void Write(int x, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1658 int y) |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1659 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1660 if (x >= 0 && |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1661 y >= 0 && |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1662 static_cast<unsigned int>(x) < image_.GetWidth() && |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1663 static_cast<unsigned int>(y) < image_.GetHeight()) |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1664 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1665 PixelType* p = reinterpret_cast<PixelType*>(image_.GetRow(y)); |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1666 p[x] = value_; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1667 } |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1668 } |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1669 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1670 void DrawSegment(int x0, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1671 int y0, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1672 int x1, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1673 int y1) |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1674 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1675 // This is an implementation of Bresenham's line algorithm |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1676 // https://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm#All_cases |
3227 | 1677 |
2489
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1678 if (abs(y1 - y0) < abs(x1 - x0)) |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1679 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1680 if (x0 > x1) |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1681 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1682 PlotLineLow(x1, y1, x0, y0); |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1683 } |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1684 else |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1685 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1686 PlotLineLow(x0, y0, x1, y1); |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1687 } |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1688 } |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1689 else |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1690 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1691 if (y0 > y1) |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1692 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1693 PlotLineHigh(x1, y1, x0, y0); |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1694 } |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1695 else |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1696 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1697 PlotLineHigh(x0, y0, x1, y1); |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1698 } |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1699 } |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1700 } |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1701 }; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1702 } |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1703 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1704 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1705 void ImageProcessing::DrawLineSegment(ImageAccessor& image, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1706 int x0, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1707 int y0, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1708 int x1, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1709 int y1, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1710 int64_t value) |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1711 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1712 switch (image.GetFormat()) |
3227 | 1713 { |
3499
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1714 case Orthanc::PixelFormat_Grayscale8: |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1715 { |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1716 BresenhamPixelWriter<Orthanc::PixelFormat_Grayscale8> writer(image, value); |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1717 writer.DrawSegment(x0, y0, x1, y1); |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1718 break; |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1719 } |
2489
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1720 |
3499
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1721 case Orthanc::PixelFormat_Grayscale16: |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1722 { |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1723 BresenhamPixelWriter<Orthanc::PixelFormat_Grayscale16> writer(image, value); |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1724 writer.DrawSegment(x0, y0, x1, y1); |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1725 break; |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1726 } |
2489
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1727 |
3499
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1728 case Orthanc::PixelFormat_SignedGrayscale16: |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1729 { |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1730 BresenhamPixelWriter<Orthanc::PixelFormat_SignedGrayscale16> writer(image, value); |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1731 writer.DrawSegment(x0, y0, x1, y1); |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1732 break; |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1733 } |
3227 | 1734 |
3499
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1735 default: |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1736 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); |
2489
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1737 } |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1738 } |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1739 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1740 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1741 void ImageProcessing::DrawLineSegment(ImageAccessor& image, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1742 int x0, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1743 int y0, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1744 int x1, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1745 int y1, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1746 uint8_t red, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1747 uint8_t green, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1748 uint8_t blue, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1749 uint8_t alpha) |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1750 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1751 switch (image.GetFormat()) |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1752 { |
3499
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1753 case Orthanc::PixelFormat_BGRA32: |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1754 { |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1755 PixelTraits<Orthanc::PixelFormat_BGRA32>::PixelType pixel; |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1756 pixel.red_ = red; |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1757 pixel.green_ = green; |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1758 pixel.blue_ = blue; |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1759 pixel.alpha_ = alpha; |
3227 | 1760 |
3499
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1761 BresenhamPixelWriter<Orthanc::PixelFormat_BGRA32> writer(image, pixel); |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1762 writer.DrawSegment(x0, y0, x1, y1); |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1763 break; |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1764 } |
2489
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1765 |
3499
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1766 case Orthanc::PixelFormat_RGBA32: |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1767 { |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1768 PixelTraits<Orthanc::PixelFormat_RGBA32>::PixelType pixel; |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1769 pixel.red_ = red; |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1770 pixel.green_ = green; |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1771 pixel.blue_ = blue; |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1772 pixel.alpha_ = alpha; |
3227 | 1773 |
3499
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1774 BresenhamPixelWriter<Orthanc::PixelFormat_RGBA32> writer(image, pixel); |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1775 writer.DrawSegment(x0, y0, x1, y1); |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1776 break; |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1777 } |
2783
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2650
diff
changeset
|
1778 |
3499
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1779 case Orthanc::PixelFormat_RGB24: |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1780 { |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1781 PixelTraits<Orthanc::PixelFormat_RGB24>::PixelType pixel; |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1782 pixel.red_ = red; |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1783 pixel.green_ = green; |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1784 pixel.blue_ = blue; |
2489
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1785 |
3499
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1786 BresenhamPixelWriter<Orthanc::PixelFormat_RGB24> writer(image, pixel); |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1787 writer.DrawSegment(x0, y0, x1, y1); |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1788 break; |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1789 } |
3227 | 1790 |
3499
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1791 default: |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1792 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); |
2489
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1793 } |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1794 } |
3258 | 1795 |
1796 void ComputePolygonExtent(int32_t& left, int32_t& right, int32_t& top, int32_t& bottom, const std::vector<ImageProcessing::ImagePoint>& points) | |
1797 { | |
1798 left = std::numeric_limits<int32_t>::max(); | |
1799 right = std::numeric_limits<int32_t>::min(); | |
1800 top = std::numeric_limits<int32_t>::max(); | |
1801 bottom = std::numeric_limits<int32_t>::min(); | |
1802 | |
1803 for (size_t i = 0; i < points.size(); i++) | |
1804 { | |
1805 const ImageProcessing::ImagePoint& p = points[i]; | |
1806 left = std::min(p.GetX(), left); | |
1807 right = std::max(p.GetX(), right); | |
1808 bottom = std::max(p.GetY(), bottom); | |
1809 top = std::min(p.GetY(), top); | |
1810 } | |
1811 } | |
1812 | |
1813 template <PixelFormat TargetFormat> | |
1814 void FillPolygon_(ImageAccessor& image, | |
3499
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1815 const std::vector<ImageProcessing::ImagePoint>& points, |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1816 int64_t value_) |
3258 | 1817 { |
1818 typedef typename PixelTraits<TargetFormat>::PixelType TargetType; | |
1819 | |
1820 TargetType value = PixelTraits<TargetFormat>::IntegerToPixel(value_); | |
3323
a15a4b9d8c00
Added image clipping to <T> FillPolygon_ to prevent out-of-memory access
Benjamin Golinvaux <bgo@osimis.io>
parents:
3265
diff
changeset
|
1821 int imageWidth = static_cast<int>(image.GetWidth()); |
a15a4b9d8c00
Added image clipping to <T> FillPolygon_ to prevent out-of-memory access
Benjamin Golinvaux <bgo@osimis.io>
parents:
3265
diff
changeset
|
1822 int imageHeight = static_cast<int>(image.GetHeight()); |
3258 | 1823 int32_t left; |
1824 int32_t right; | |
1825 int32_t top; | |
1826 int32_t bottom; | |
1827 | |
3323
a15a4b9d8c00
Added image clipping to <T> FillPolygon_ to prevent out-of-memory access
Benjamin Golinvaux <bgo@osimis.io>
parents:
3265
diff
changeset
|
1828 // TODO: test clipping in UT (in Trello board) |
3258 | 1829 ComputePolygonExtent(left, right, top, bottom, points); |
1830 | |
3323
a15a4b9d8c00
Added image clipping to <T> FillPolygon_ to prevent out-of-memory access
Benjamin Golinvaux <bgo@osimis.io>
parents:
3265
diff
changeset
|
1831 // clip the computed extent with the target image |
a15a4b9d8c00
Added image clipping to <T> FillPolygon_ to prevent out-of-memory access
Benjamin Golinvaux <bgo@osimis.io>
parents:
3265
diff
changeset
|
1832 // L and R |
a15a4b9d8c00
Added image clipping to <T> FillPolygon_ to prevent out-of-memory access
Benjamin Golinvaux <bgo@osimis.io>
parents:
3265
diff
changeset
|
1833 left = std::max(0, left); |
a15a4b9d8c00
Added image clipping to <T> FillPolygon_ to prevent out-of-memory access
Benjamin Golinvaux <bgo@osimis.io>
parents:
3265
diff
changeset
|
1834 left = std::min(imageWidth, left); |
a15a4b9d8c00
Added image clipping to <T> FillPolygon_ to prevent out-of-memory access
Benjamin Golinvaux <bgo@osimis.io>
parents:
3265
diff
changeset
|
1835 right = std::max(0, right); |
a15a4b9d8c00
Added image clipping to <T> FillPolygon_ to prevent out-of-memory access
Benjamin Golinvaux <bgo@osimis.io>
parents:
3265
diff
changeset
|
1836 right = std::min(imageWidth, right); |
a15a4b9d8c00
Added image clipping to <T> FillPolygon_ to prevent out-of-memory access
Benjamin Golinvaux <bgo@osimis.io>
parents:
3265
diff
changeset
|
1837 if (left > right) |
a15a4b9d8c00
Added image clipping to <T> FillPolygon_ to prevent out-of-memory access
Benjamin Golinvaux <bgo@osimis.io>
parents:
3265
diff
changeset
|
1838 std::swap(left, right); |
a15a4b9d8c00
Added image clipping to <T> FillPolygon_ to prevent out-of-memory access
Benjamin Golinvaux <bgo@osimis.io>
parents:
3265
diff
changeset
|
1839 |
a15a4b9d8c00
Added image clipping to <T> FillPolygon_ to prevent out-of-memory access
Benjamin Golinvaux <bgo@osimis.io>
parents:
3265
diff
changeset
|
1840 // T and B |
a15a4b9d8c00
Added image clipping to <T> FillPolygon_ to prevent out-of-memory access
Benjamin Golinvaux <bgo@osimis.io>
parents:
3265
diff
changeset
|
1841 top = std::max(0, top); |
a15a4b9d8c00
Added image clipping to <T> FillPolygon_ to prevent out-of-memory access
Benjamin Golinvaux <bgo@osimis.io>
parents:
3265
diff
changeset
|
1842 top = std::min(imageHeight, top); |
a15a4b9d8c00
Added image clipping to <T> FillPolygon_ to prevent out-of-memory access
Benjamin Golinvaux <bgo@osimis.io>
parents:
3265
diff
changeset
|
1843 bottom = std::max(0, bottom); |
a15a4b9d8c00
Added image clipping to <T> FillPolygon_ to prevent out-of-memory access
Benjamin Golinvaux <bgo@osimis.io>
parents:
3265
diff
changeset
|
1844 bottom = std::min(imageHeight, bottom); |
a15a4b9d8c00
Added image clipping to <T> FillPolygon_ to prevent out-of-memory access
Benjamin Golinvaux <bgo@osimis.io>
parents:
3265
diff
changeset
|
1845 if (top > bottom) |
a15a4b9d8c00
Added image clipping to <T> FillPolygon_ to prevent out-of-memory access
Benjamin Golinvaux <bgo@osimis.io>
parents:
3265
diff
changeset
|
1846 std::swap(top, bottom); |
a15a4b9d8c00
Added image clipping to <T> FillPolygon_ to prevent out-of-memory access
Benjamin Golinvaux <bgo@osimis.io>
parents:
3265
diff
changeset
|
1847 |
3258 | 1848 // from http://alienryderflex.com/polygon_fill/ |
1849 | |
1850 // convert all "corner" points to double only once | |
1851 std::vector<double> cpx; | |
1852 std::vector<double> cpy; | |
1853 size_t cpSize = points.size(); | |
1854 for (size_t i = 0; i < points.size(); i++) | |
1855 { | |
3365 | 1856 if (points[i].GetX() < 0 || points[i].GetX() >= imageWidth |
1857 || points[i].GetY() < 0 || points[i].GetY() >= imageHeight) | |
1858 { | |
1859 throw Orthanc::OrthancException(ErrorCode_ParameterOutOfRange); | |
1860 } | |
3258 | 1861 cpx.push_back((double)points[i].GetX()); |
1862 cpy.push_back((double)points[i].GetY()); | |
1863 } | |
1864 | |
3431 | 1865 // Draw the lines segments |
1866 for (size_t i = 0; i < (points.size() -1); i++) | |
1867 { | |
1868 ImageProcessing::DrawLineSegment(image, points[i].GetX(), points[i].GetY(), points[i+1].GetX(), points[i+1].GetY(), value_); | |
1869 } | |
1870 ImageProcessing::DrawLineSegment(image, points[points.size() -1].GetX(), points[points.size() -1].GetY(), points[0].GetX(), points[0].GetY(), value_); | |
1871 | |
3258 | 1872 std::vector<int32_t> nodeX; |
1873 nodeX.resize(cpSize); | |
1874 int nodes, pixelX, pixelY, i, j, swap ; | |
1875 | |
1876 // Loop through the rows of the image. | |
1877 for (pixelY = top; pixelY < bottom; pixelY++) | |
1878 { | |
1879 double y = (double)pixelY; | |
1880 // Build a list of nodes. | |
1881 nodes = 0; | |
1882 j = static_cast<int>(cpSize) - 1; | |
1883 | |
3259
6f9398eb902d
unit test Toolbox.SubstituteVariables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3258
diff
changeset
|
1884 for (i = 0; i < static_cast<int>(cpSize); i++) |
3258 | 1885 { |
1886 if ((cpy[i] < y && cpy[j] >= y) || (cpy[j] < y && cpy[i] >= y)) | |
1887 { | |
1888 nodeX[nodes++] = (int32_t)(cpx[i] + (y - cpy[i])/(cpy[j] - cpy[i]) * (cpx[j] - cpx[i])); | |
1889 } | |
1890 j=i; | |
1891 } | |
1892 | |
1893 // Sort the nodes, via a simple “Bubble” sort. | |
1894 i=0; | |
1895 while (i < nodes-1) | |
1896 { | |
1897 if (nodeX[i] > nodeX[i+1]) | |
1898 { | |
1899 swap = nodeX[i]; | |
1900 nodeX[i] = nodeX[i+1]; | |
1901 nodeX[i+1] = swap; | |
1902 if (i > 0) | |
1903 { | |
1904 i--; | |
1905 } | |
1906 } | |
1907 else | |
1908 { | |
1909 i++; | |
1910 } | |
1911 } | |
1912 | |
1913 TargetType* row = reinterpret_cast<TargetType*>(image.GetRow(pixelY)); | |
1914 // Fill the pixels between node pairs. | |
3323
a15a4b9d8c00
Added image clipping to <T> FillPolygon_ to prevent out-of-memory access
Benjamin Golinvaux <bgo@osimis.io>
parents:
3265
diff
changeset
|
1915 for (i = 0; i < nodes; i += 2) |
3258 | 1916 { |
1917 if (nodeX[i] >= right) | |
1918 break; | |
1919 | |
3323
a15a4b9d8c00
Added image clipping to <T> FillPolygon_ to prevent out-of-memory access
Benjamin Golinvaux <bgo@osimis.io>
parents:
3265
diff
changeset
|
1920 if (nodeX[i + 1] >= left) |
3258 | 1921 { |
3323
a15a4b9d8c00
Added image clipping to <T> FillPolygon_ to prevent out-of-memory access
Benjamin Golinvaux <bgo@osimis.io>
parents:
3265
diff
changeset
|
1922 if (nodeX[i] < left) |
3258 | 1923 { |
1924 nodeX[i] = left; | |
1925 } | |
1926 | |
3323
a15a4b9d8c00
Added image clipping to <T> FillPolygon_ to prevent out-of-memory access
Benjamin Golinvaux <bgo@osimis.io>
parents:
3265
diff
changeset
|
1927 if (nodeX[i + 1] > right) |
3258 | 1928 { |
3323
a15a4b9d8c00
Added image clipping to <T> FillPolygon_ to prevent out-of-memory access
Benjamin Golinvaux <bgo@osimis.io>
parents:
3265
diff
changeset
|
1929 nodeX[i + 1] = right; |
3258 | 1930 } |
1931 | |
3323
a15a4b9d8c00
Added image clipping to <T> FillPolygon_ to prevent out-of-memory access
Benjamin Golinvaux <bgo@osimis.io>
parents:
3265
diff
changeset
|
1932 for (pixelX = nodeX[i]; pixelX <= nodeX[i + 1]; pixelX++) |
3258 | 1933 { |
1934 *(row + pixelX) = value; | |
1935 } | |
1936 } | |
1937 } | |
1938 } | |
1939 } | |
1940 | |
1941 void ImageProcessing::FillPolygon(ImageAccessor& image, | |
1942 const std::vector<ImagePoint>& points, | |
1943 int64_t value) | |
1944 { | |
1945 switch (image.GetFormat()) | |
1946 { | |
3499
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1947 case Orthanc::PixelFormat_Grayscale8: |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1948 { |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1949 FillPolygon_<Orthanc::PixelFormat_Grayscale8>(image, points, value); |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1950 break; |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1951 } |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1952 case Orthanc::PixelFormat_Grayscale16: |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1953 { |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1954 FillPolygon_<Orthanc::PixelFormat_Grayscale16>(image, points, value); |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1955 break; |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1956 } |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1957 case Orthanc::PixelFormat_SignedGrayscale16: |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1958 { |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1959 FillPolygon_<Orthanc::PixelFormat_SignedGrayscale16>(image, points, value); |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1960 break; |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1961 } |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1962 default: |
d8f7c3970e25
more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3431
diff
changeset
|
1963 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); |
3258 | 1964 } |
1965 } | |
3502
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
1966 |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
1967 |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
1968 template <PixelFormat Format> |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
1969 static void ResizeInternal(ImageAccessor& target, |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
1970 const ImageAccessor& source) |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
1971 { |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
1972 assert(target.GetFormat() == source.GetFormat() && |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
1973 target.GetFormat() == Format); |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
1974 |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
1975 const unsigned int sourceWidth = source.GetWidth(); |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
1976 const unsigned int sourceHeight = source.GetHeight(); |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
1977 const unsigned int targetWidth = target.GetWidth(); |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
1978 const unsigned int targetHeight = target.GetHeight(); |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
1979 |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
1980 if (targetWidth == 0 || targetHeight == 0) |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
1981 { |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
1982 return; |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
1983 } |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
1984 |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
1985 if (sourceWidth == 0 || sourceHeight == 0) |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
1986 { |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
1987 // Avoids division by zero below |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
1988 ImageProcessing::Set(target, 0); |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
1989 return; |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
1990 } |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
1991 |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
1992 const float scaleX = static_cast<float>(sourceWidth) / static_cast<float>(targetWidth); |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
1993 const float scaleY = static_cast<float>(sourceHeight) / static_cast<float>(targetHeight); |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
1994 |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
1995 |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
1996 /** |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
1997 * Create two lookup tables to quickly know the (x,y) position |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
1998 * in the source image, given the (x,y) position in the target |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
1999 * image. |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2000 **/ |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2001 |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2002 std::vector<unsigned int> lookupX(targetWidth); |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2003 |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2004 for (unsigned int x = 0; x < targetWidth; x++) |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2005 { |
3585
113a9643e8bb
Suppressed a few warnings when building with emscripten (clang) + numeric truncation warnings
Benjamin Golinvaux <bgo@osimis.io>
parents:
3565
diff
changeset
|
2006 int sourceX = static_cast<int>(std::floor((static_cast<float>(x) + 0.5f) * scaleX)); |
3502
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2007 if (sourceX < 0) |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2008 { |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2009 sourceX = 0; // Should never happen |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2010 } |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2011 else if (sourceX >= static_cast<int>(sourceWidth)) |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2012 { |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2013 sourceX = sourceWidth - 1; |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2014 } |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2015 |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2016 lookupX[x] = static_cast<unsigned int>(sourceX); |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2017 } |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2018 |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2019 std::vector<unsigned int> lookupY(targetHeight); |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2020 |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2021 for (unsigned int y = 0; y < targetHeight; y++) |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2022 { |
3585
113a9643e8bb
Suppressed a few warnings when building with emscripten (clang) + numeric truncation warnings
Benjamin Golinvaux <bgo@osimis.io>
parents:
3565
diff
changeset
|
2023 int sourceY = static_cast<int>(std::floor((static_cast<float>(y) + 0.5f) * scaleY)); |
3502
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2024 if (sourceY < 0) |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2025 { |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2026 sourceY = 0; // Should never happen |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2027 } |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2028 else if (sourceY >= static_cast<int>(sourceHeight)) |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2029 { |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2030 sourceY = sourceHeight - 1; |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2031 } |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2032 |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2033 lookupY[y] = static_cast<unsigned int>(sourceY); |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2034 } |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2035 |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2036 |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2037 /** |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2038 * Actual resizing |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2039 **/ |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2040 |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2041 for (unsigned int targetY = 0; targetY < targetHeight; targetY++) |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2042 { |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2043 unsigned int sourceY = lookupY[targetY]; |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2044 |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2045 for (unsigned int targetX = 0; targetX < targetWidth; targetX++) |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2046 { |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2047 unsigned int sourceX = lookupX[targetX]; |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2048 |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2049 typename ImageTraits<Format>::PixelType pixel; |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2050 ImageTraits<Format>::GetPixel(pixel, source, sourceX, sourceY); |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2051 ImageTraits<Format>::SetPixel(target, pixel, targetX, targetY); |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2052 } |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2053 } |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2054 } |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2055 |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2056 |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2057 |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2058 void ImageProcessing::Resize(ImageAccessor& target, |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2059 const ImageAccessor& source) |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2060 { |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2061 if (source.GetFormat() != source.GetFormat()) |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2062 { |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2063 throw OrthancException(ErrorCode_IncompatibleImageFormat); |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2064 } |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2065 |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2066 if (source.GetWidth() == target.GetWidth() && |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2067 source.GetHeight() == target.GetHeight()) |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2068 { |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2069 Copy(target, source); |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2070 return; |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2071 } |
3548
e1ce68692069
ImageProcessing::ApplyWindowing
Alain Mazy <alain@mazy.be>
parents:
3547
diff
changeset
|
2072 |
3502
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2073 switch (source.GetFormat()) |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2074 { |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2075 case PixelFormat_Grayscale8: |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2076 ResizeInternal<PixelFormat_Grayscale8>(target, source); |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2077 break; |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2078 |
3548
e1ce68692069
ImageProcessing::ApplyWindowing
Alain Mazy <alain@mazy.be>
parents:
3547
diff
changeset
|
2079 case PixelFormat_Float32: |
e1ce68692069
ImageProcessing::ApplyWindowing
Alain Mazy <alain@mazy.be>
parents:
3547
diff
changeset
|
2080 ResizeInternal<PixelFormat_Float32>(target, source); |
e1ce68692069
ImageProcessing::ApplyWindowing
Alain Mazy <alain@mazy.be>
parents:
3547
diff
changeset
|
2081 break; |
e1ce68692069
ImageProcessing::ApplyWindowing
Alain Mazy <alain@mazy.be>
parents:
3547
diff
changeset
|
2082 |
3502
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2083 case PixelFormat_RGB24: |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2084 ResizeInternal<PixelFormat_RGB24>(target, source); |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2085 break; |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2086 |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2087 default: |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2088 throw OrthancException(ErrorCode_NotImplemented); |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2089 } |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2090 } |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2091 |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2092 |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2093 ImageAccessor* ImageProcessing::Halve(const ImageAccessor& source, |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2094 bool forceMinimalPitch) |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2095 { |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3690
diff
changeset
|
2096 std::unique_ptr<Image> target(new Image(source.GetFormat(), source.GetWidth() / 2, |
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3690
diff
changeset
|
2097 source.GetHeight() / 2, forceMinimalPitch)); |
3502
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2098 Resize(*target, source); |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2099 return target.release(); |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2100 } |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2101 |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2102 |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2103 template <PixelFormat Format> |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2104 static void FlipXInternal(ImageAccessor& image) |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2105 { |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2106 const unsigned int height = image.GetHeight(); |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2107 const unsigned int width = image.GetWidth(); |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2108 |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2109 for (unsigned int y = 0; y < height; y++) |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2110 { |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2111 for (unsigned int x1 = 0; x1 < width / 2; x1++) |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2112 { |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2113 unsigned int x2 = width - 1 - x1; |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2114 |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2115 typename ImageTraits<Format>::PixelType a, b; |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2116 ImageTraits<Format>::GetPixel(a, image, x1, y); |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2117 ImageTraits<Format>::GetPixel(b, image, x2, y); |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2118 ImageTraits<Format>::SetPixel(image, a, x2, y); |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2119 ImageTraits<Format>::SetPixel(image, b, x1, y); |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2120 } |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2121 } |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2122 } |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2123 |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2124 |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2125 void ImageProcessing::FlipX(ImageAccessor& image) |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2126 { |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2127 switch (image.GetFormat()) |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2128 { |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2129 case PixelFormat_Grayscale8: |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2130 FlipXInternal<PixelFormat_Grayscale8>(image); |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2131 break; |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2132 |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2133 case PixelFormat_RGB24: |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2134 FlipXInternal<PixelFormat_RGB24>(image); |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2135 break; |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2136 |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2137 default: |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2138 throw OrthancException(ErrorCode_NotImplemented); |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2139 } |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2140 } |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2141 |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2142 |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2143 template <PixelFormat Format> |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2144 static void FlipYInternal(ImageAccessor& image) |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2145 { |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2146 const unsigned int height = image.GetHeight(); |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2147 const unsigned int width = image.GetWidth(); |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2148 |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2149 for (unsigned int y1 = 0; y1 < height / 2; y1++) |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2150 { |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2151 unsigned int y2 = height - 1 - y1; |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2152 |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2153 for (unsigned int x = 0; x < width; x++) |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2154 { |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2155 typename ImageTraits<Format>::PixelType a, b; |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2156 ImageTraits<Format>::GetPixel(a, image, x, y1); |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2157 ImageTraits<Format>::GetPixel(b, image, x, y2); |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2158 ImageTraits<Format>::SetPixel(image, a, x, y2); |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2159 ImageTraits<Format>::SetPixel(image, b, x, y1); |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2160 } |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2161 } |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2162 } |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2163 |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2164 |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2165 void ImageProcessing::FlipY(ImageAccessor& image) |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2166 { |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2167 switch (image.GetFormat()) |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2168 { |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2169 case PixelFormat_Grayscale8: |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2170 FlipYInternal<PixelFormat_Grayscale8>(image); |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2171 break; |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2172 |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2173 case PixelFormat_RGB24: |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2174 FlipYInternal<PixelFormat_RGB24>(image); |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2175 break; |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2176 |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2177 default: |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2178 throw OrthancException(ErrorCode_NotImplemented); |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2179 } |
c160eafc42a9
new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3499
diff
changeset
|
2180 } |
3503
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2181 |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2182 |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2183 // This is a slow implementation of horizontal convolution on one |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2184 // individual channel, that checks for out-of-image values |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2185 template <typename RawPixel, unsigned int ChannelsCount> |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2186 static float GetHorizontalConvolutionFloatSecure(const Orthanc::ImageAccessor& source, |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2187 const std::vector<float>& horizontal, |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2188 size_t horizontalAnchor, |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2189 unsigned int x, |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2190 unsigned int y, |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2191 float leftBorder, |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2192 float rightBorder, |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2193 unsigned int channel) |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2194 { |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2195 const RawPixel* row = reinterpret_cast<const RawPixel*>(source.GetConstRow(y)) + channel; |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2196 |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2197 float p = 0; |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2198 |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2199 for (unsigned int k = 0; k < horizontal.size(); k++) |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2200 { |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2201 float value; |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2202 |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2203 if (x + k < horizontalAnchor) // Negation of "x - horizontalAnchor + k >= 0" |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2204 { |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2205 value = leftBorder; |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2206 } |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2207 else if (x + k >= source.GetWidth() + horizontalAnchor) // Negation of "x - horizontalAnchor + k < width" |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2208 { |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2209 value = rightBorder; |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2210 } |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2211 else |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2212 { |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2213 // The value lies within the image |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2214 value = row[(x - horizontalAnchor + k) * ChannelsCount]; |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2215 } |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2216 |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2217 p += value * horizontal[k]; |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2218 } |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2219 |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2220 return p; |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2221 } |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2222 |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2223 |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2224 |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2225 // This is an implementation of separable convolution that uses |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2226 // floating-point arithmetics, and an intermediate Float32 |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2227 // image. The out-of-image values are taken as the border |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2228 // value. Further optimization is possible. |
4065
d6362b2c4b61
export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4056
diff
changeset
|
2229 template <typename RawPixel, unsigned int ChannelsCount, bool UseRound> |
3503
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2230 static void SeparableConvolutionFloat(ImageAccessor& image /* inplace */, |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2231 const std::vector<float>& horizontal, |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2232 size_t horizontalAnchor, |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2233 const std::vector<float>& vertical, |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2234 size_t verticalAnchor, |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2235 float normalization) |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2236 { |
3525
8c66c9c2257b
fix ImageProcessing::ShiftScale() on float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3505
diff
changeset
|
2237 // WARNING - "::min()" should be replaced by "::lowest()" if |
8c66c9c2257b
fix ImageProcessing::ShiftScale() on float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3505
diff
changeset
|
2238 // dealing with float or double (which is not the case so far) |
8c66c9c2257b
fix ImageProcessing::ShiftScale() on float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3505
diff
changeset
|
2239 assert(sizeof(RawPixel) <= 2); // Safeguard to remember about "float/double" |
8c66c9c2257b
fix ImageProcessing::ShiftScale() on float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3505
diff
changeset
|
2240 |
3503
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2241 const unsigned int width = image.GetWidth(); |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2242 const unsigned int height = image.GetHeight(); |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2243 |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2244 |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2245 /** |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2246 * Horizontal convolution |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2247 **/ |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2248 |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2249 Image tmp(PixelFormat_Float32, ChannelsCount * width, height, false); |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2250 |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2251 for (unsigned int y = 0; y < height; y++) |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2252 { |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2253 const RawPixel* row = reinterpret_cast<const RawPixel*>(image.GetConstRow(y)); |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2254 |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2255 float leftBorder[ChannelsCount], rightBorder[ChannelsCount]; |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2256 |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2257 for (unsigned int c = 0; c < ChannelsCount; c++) |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2258 { |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2259 leftBorder[c] = row[c]; |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2260 rightBorder[c] = row[ChannelsCount * (width - 1) + c]; |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2261 } |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2262 |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2263 float* p = static_cast<float*>(tmp.GetRow(y)); |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2264 |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2265 if (width < horizontal.size()) |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2266 { |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2267 // It is not possible to have the full kernel within the image, use the direct implementation |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2268 for (unsigned int x = 0; x < width; x++) |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2269 { |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2270 for (unsigned int c = 0; c < ChannelsCount; c++, p++) |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2271 { |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2272 *p = GetHorizontalConvolutionFloatSecure<RawPixel, ChannelsCount> |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2273 (image, horizontal, horizontalAnchor, x, y, leftBorder[c], rightBorder[c], c); |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2274 } |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2275 } |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2276 } |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2277 else |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2278 { |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2279 // Deal with the left border |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2280 for (unsigned int x = 0; x < horizontalAnchor; x++) |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2281 { |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2282 for (unsigned int c = 0; c < ChannelsCount; c++, p++) |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2283 { |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2284 *p = GetHorizontalConvolutionFloatSecure<RawPixel, ChannelsCount> |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2285 (image, horizontal, horizontalAnchor, x, y, leftBorder[c], rightBorder[c], c); |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2286 } |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2287 } |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2288 |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2289 // Deal with the central portion of the image (all pixel values |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2290 // scanned by the kernel lie inside the image) |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2291 |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2292 for (unsigned int x = 0; x < width - horizontal.size() + 1; x++) |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2293 { |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2294 for (unsigned int c = 0; c < ChannelsCount; c++, p++) |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2295 { |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2296 *p = 0; |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2297 for (unsigned int k = 0; k < horizontal.size(); k++) |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2298 { |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2299 *p += static_cast<float>(row[(x + k) * ChannelsCount + c]) * horizontal[k]; |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2300 } |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2301 } |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2302 } |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2303 |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2304 // Deal with the right border |
3585
113a9643e8bb
Suppressed a few warnings when building with emscripten (clang) + numeric truncation warnings
Benjamin Golinvaux <bgo@osimis.io>
parents:
3565
diff
changeset
|
2305 for (unsigned int x = static_cast<unsigned int>( |
3682
5f64c866108a
merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2306 horizontalAnchor + width - horizontal.size() + 1); x < width; x++) |
3503
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2307 { |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2308 for (unsigned int c = 0; c < ChannelsCount; c++, p++) |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2309 { |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2310 *p = GetHorizontalConvolutionFloatSecure<RawPixel, ChannelsCount> |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2311 (image, horizontal, horizontalAnchor, x, y, leftBorder[c], rightBorder[c], c); |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2312 } |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2313 } |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2314 } |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2315 } |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2316 |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2317 |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2318 /** |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2319 * Vertical convolution |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2320 **/ |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2321 |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2322 std::vector<const float*> rows(vertical.size()); |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2323 |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2324 for (unsigned int y = 0; y < height; y++) |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2325 { |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2326 for (unsigned int k = 0; k < vertical.size(); k++) |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2327 { |
3504
18566f9e1831
unit testing new functions in ImageProcessing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3503
diff
changeset
|
2328 if (y + k < verticalAnchor) |
3503
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2329 { |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2330 rows[k] = reinterpret_cast<const float*>(tmp.GetConstRow(0)); // Use top border |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2331 } |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2332 else if (y + k >= height + verticalAnchor) |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2333 { |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2334 rows[k] = reinterpret_cast<const float*>(tmp.GetConstRow(height - 1)); // Use bottom border |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2335 } |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2336 else |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2337 { |
3585
113a9643e8bb
Suppressed a few warnings when building with emscripten (clang) + numeric truncation warnings
Benjamin Golinvaux <bgo@osimis.io>
parents:
3565
diff
changeset
|
2338 rows[k] = reinterpret_cast<const float*>(tmp.GetConstRow(static_cast<unsigned int>(y + k - verticalAnchor))); |
3503
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2339 } |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2340 } |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2341 |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2342 RawPixel* p = reinterpret_cast<RawPixel*>(image.GetRow(y)); |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2343 |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2344 for (unsigned int x = 0; x < width; x++) |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2345 { |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2346 for (unsigned int c = 0; c < ChannelsCount; c++, p++) |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2347 { |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2348 float accumulator = 0; |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2349 |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2350 for (unsigned int k = 0; k < vertical.size(); k++) |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2351 { |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2352 accumulator += rows[k][ChannelsCount * x + c] * vertical[k]; |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2353 } |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2354 |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2355 accumulator *= normalization; |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2356 |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2357 if (accumulator <= static_cast<float>(std::numeric_limits<RawPixel>::min())) |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2358 { |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2359 *p = std::numeric_limits<RawPixel>::min(); |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2360 } |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2361 else if (accumulator >= static_cast<float>(std::numeric_limits<RawPixel>::max())) |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2362 { |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2363 *p = std::numeric_limits<RawPixel>::max(); |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2364 } |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2365 else |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2366 { |
4065
d6362b2c4b61
export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4056
diff
changeset
|
2367 if (UseRound) |
d6362b2c4b61
export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4056
diff
changeset
|
2368 { |
d6362b2c4b61
export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4056
diff
changeset
|
2369 assert(sizeof(RawPixel) < sizeof(int)); |
d6362b2c4b61
export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4056
diff
changeset
|
2370 *p = static_cast<RawPixel>(boost::math::iround(accumulator)); |
d6362b2c4b61
export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4056
diff
changeset
|
2371 } |
d6362b2c4b61
export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4056
diff
changeset
|
2372 else |
d6362b2c4b61
export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4056
diff
changeset
|
2373 { |
d6362b2c4b61
export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4056
diff
changeset
|
2374 *p = static_cast<RawPixel>(accumulator); |
d6362b2c4b61
export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4056
diff
changeset
|
2375 } |
3503
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2376 } |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2377 } |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2378 } |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2379 } |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2380 } |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2381 |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2382 |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2383 void ImageProcessing::SeparableConvolution(ImageAccessor& image /* inplace */, |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2384 const std::vector<float>& horizontal, |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2385 size_t horizontalAnchor, |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2386 const std::vector<float>& vertical, |
4065
d6362b2c4b61
export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4056
diff
changeset
|
2387 size_t verticalAnchor, |
d6362b2c4b61
export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4056
diff
changeset
|
2388 bool useRound) |
3503
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2389 { |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2390 if (horizontal.size() == 0 || |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2391 vertical.size() == 0 || |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2392 horizontalAnchor >= horizontal.size() || |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2393 verticalAnchor >= vertical.size()) |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2394 { |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2395 throw OrthancException(ErrorCode_ParameterOutOfRange); |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2396 } |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2397 |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2398 if (image.GetWidth() == 0 || |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2399 image.GetHeight() == 0) |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2400 { |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2401 return; |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2402 } |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2403 |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2404 /** |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2405 * Compute normalization |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2406 **/ |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2407 |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2408 float sumHorizontal = 0; |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2409 for (size_t i = 0; i < horizontal.size(); i++) |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2410 { |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2411 sumHorizontal += horizontal[i]; |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2412 } |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2413 |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2414 float sumVertical = 0; |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2415 for (size_t i = 0; i < vertical.size(); i++) |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2416 { |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2417 sumVertical += vertical[i]; |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2418 } |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2419 |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2420 if (fabsf(sumHorizontal) <= std::numeric_limits<float>::epsilon() || |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2421 fabsf(sumVertical) <= std::numeric_limits<float>::epsilon()) |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2422 { |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2423 throw OrthancException(ErrorCode_ParameterOutOfRange, "Singular convolution kernel"); |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2424 } |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2425 |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2426 const float normalization = 1.0f / (sumHorizontal * sumVertical); |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2427 |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2428 switch (image.GetFormat()) |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2429 { |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2430 case PixelFormat_Grayscale8: |
4065
d6362b2c4b61
export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4056
diff
changeset
|
2431 if (useRound) |
d6362b2c4b61
export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4056
diff
changeset
|
2432 { |
d6362b2c4b61
export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4056
diff
changeset
|
2433 SeparableConvolutionFloat<uint8_t, 1u, true> |
d6362b2c4b61
export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4056
diff
changeset
|
2434 (image, horizontal, horizontalAnchor, vertical, verticalAnchor, normalization); |
d6362b2c4b61
export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4056
diff
changeset
|
2435 } |
d6362b2c4b61
export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4056
diff
changeset
|
2436 else |
d6362b2c4b61
export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4056
diff
changeset
|
2437 { |
d6362b2c4b61
export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4056
diff
changeset
|
2438 SeparableConvolutionFloat<uint8_t, 1u, false> |
d6362b2c4b61
export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4056
diff
changeset
|
2439 (image, horizontal, horizontalAnchor, vertical, verticalAnchor, normalization); |
d6362b2c4b61
export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4056
diff
changeset
|
2440 } |
3503
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2441 break; |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2442 |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2443 case PixelFormat_RGB24: |
4065
d6362b2c4b61
export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4056
diff
changeset
|
2444 if (useRound) |
d6362b2c4b61
export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4056
diff
changeset
|
2445 { |
d6362b2c4b61
export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4056
diff
changeset
|
2446 SeparableConvolutionFloat<uint8_t, 3u, true> |
d6362b2c4b61
export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4056
diff
changeset
|
2447 (image, horizontal, horizontalAnchor, vertical, verticalAnchor, normalization); |
d6362b2c4b61
export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4056
diff
changeset
|
2448 } |
d6362b2c4b61
export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4056
diff
changeset
|
2449 else |
d6362b2c4b61
export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4056
diff
changeset
|
2450 { |
d6362b2c4b61
export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4056
diff
changeset
|
2451 SeparableConvolutionFloat<uint8_t, 3u, false> |
d6362b2c4b61
export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4056
diff
changeset
|
2452 (image, horizontal, horizontalAnchor, vertical, verticalAnchor, normalization); |
d6362b2c4b61
export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4056
diff
changeset
|
2453 } |
3503
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2454 break; |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2455 |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2456 default: |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2457 throw OrthancException(ErrorCode_NotImplemented); |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2458 } |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2459 } |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2460 |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2461 |
4065
d6362b2c4b61
export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4056
diff
changeset
|
2462 void ImageProcessing::SmoothGaussian5x5(ImageAccessor& image, |
d6362b2c4b61
export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4056
diff
changeset
|
2463 bool useRound) |
3503
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2464 { |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2465 std::vector<float> kernel(5); |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2466 kernel[0] = 1; |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2467 kernel[1] = 4; |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2468 kernel[2] = 6; |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2469 kernel[3] = 4; |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2470 kernel[4] = 1; |
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2471 |
4065
d6362b2c4b61
export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4056
diff
changeset
|
2472 SeparableConvolution(image, kernel, 2, kernel, 2, useRound); |
3503
46cf170ba121
ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3502
diff
changeset
|
2473 } |
3549
fab5777f4dd4
ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3547
diff
changeset
|
2474 |
fab5777f4dd4
ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3547
diff
changeset
|
2475 |
fab5777f4dd4
ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3547
diff
changeset
|
2476 void ImageProcessing::FitSize(ImageAccessor& target, |
fab5777f4dd4
ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3547
diff
changeset
|
2477 const ImageAccessor& source) |
fab5777f4dd4
ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3547
diff
changeset
|
2478 { |
fab5777f4dd4
ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3547
diff
changeset
|
2479 if (target.GetWidth() == 0 || |
fab5777f4dd4
ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3547
diff
changeset
|
2480 target.GetHeight() == 0) |
fab5777f4dd4
ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3547
diff
changeset
|
2481 { |
fab5777f4dd4
ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3547
diff
changeset
|
2482 return; |
fab5777f4dd4
ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3547
diff
changeset
|
2483 } |
fab5777f4dd4
ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3547
diff
changeset
|
2484 |
fab5777f4dd4
ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3547
diff
changeset
|
2485 if (source.GetWidth() == target.GetWidth() && |
fab5777f4dd4
ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3547
diff
changeset
|
2486 source.GetHeight() == target.GetHeight()) |
fab5777f4dd4
ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3547
diff
changeset
|
2487 { |
fab5777f4dd4
ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3547
diff
changeset
|
2488 Copy(target, source); |
fab5777f4dd4
ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3547
diff
changeset
|
2489 return; |
fab5777f4dd4
ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3547
diff
changeset
|
2490 } |
fab5777f4dd4
ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3547
diff
changeset
|
2491 |
fab5777f4dd4
ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3547
diff
changeset
|
2492 Set(target, 0); |
fab5777f4dd4
ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3547
diff
changeset
|
2493 |
fab5777f4dd4
ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3547
diff
changeset
|
2494 // Preserve the aspect ratio |
fab5777f4dd4
ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3547
diff
changeset
|
2495 float cw = static_cast<float>(source.GetWidth()); |
fab5777f4dd4
ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3547
diff
changeset
|
2496 float ch = static_cast<float>(source.GetHeight()); |
fab5777f4dd4
ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3547
diff
changeset
|
2497 float r = std::min( |
fab5777f4dd4
ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3547
diff
changeset
|
2498 static_cast<float>(target.GetWidth()) / cw, |
fab5777f4dd4
ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3547
diff
changeset
|
2499 static_cast<float>(target.GetHeight()) / ch); |
fab5777f4dd4
ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3547
diff
changeset
|
2500 |
fab5777f4dd4
ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3547
diff
changeset
|
2501 unsigned int sw = std::min(static_cast<unsigned int>(boost::math::iround(cw * r)), target.GetWidth()); |
fab5777f4dd4
ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3547
diff
changeset
|
2502 unsigned int sh = std::min(static_cast<unsigned int>(boost::math::iround(ch * r)), target.GetHeight()); |
4065
d6362b2c4b61
export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4056
diff
changeset
|
2503 |
3549
fab5777f4dd4
ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3547
diff
changeset
|
2504 Image resized(target.GetFormat(), sw, sh, false); |
fab5777f4dd4
ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3547
diff
changeset
|
2505 |
fab5777f4dd4
ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3547
diff
changeset
|
2506 //ImageProcessing::SmoothGaussian5x5(source); |
fab5777f4dd4
ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3547
diff
changeset
|
2507 ImageProcessing::Resize(resized, source); |
fab5777f4dd4
ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3547
diff
changeset
|
2508 |
fab5777f4dd4
ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3547
diff
changeset
|
2509 assert(target.GetWidth() >= resized.GetWidth() && |
fab5777f4dd4
ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3547
diff
changeset
|
2510 target.GetHeight() >= resized.GetHeight()); |
fab5777f4dd4
ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3547
diff
changeset
|
2511 unsigned int offsetX = (target.GetWidth() - resized.GetWidth()) / 2; |
fab5777f4dd4
ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3547
diff
changeset
|
2512 unsigned int offsetY = (target.GetHeight() - resized.GetHeight()) / 2; |
fab5777f4dd4
ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3547
diff
changeset
|
2513 |
fab5777f4dd4
ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3547
diff
changeset
|
2514 ImageAccessor region; |
fab5777f4dd4
ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3547
diff
changeset
|
2515 target.GetRegion(region, offsetX, offsetY, resized.GetWidth(), resized.GetHeight()); |
fab5777f4dd4
ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3547
diff
changeset
|
2516 ImageProcessing::Copy(region, resized); |
fab5777f4dd4
ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3547
diff
changeset
|
2517 } |
fab5777f4dd4
ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3547
diff
changeset
|
2518 |
fab5777f4dd4
ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3547
diff
changeset
|
2519 |
fab5777f4dd4
ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3547
diff
changeset
|
2520 ImageAccessor* ImageProcessing::FitSize(const ImageAccessor& source, |
fab5777f4dd4
ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3547
diff
changeset
|
2521 unsigned int width, |
fab5777f4dd4
ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3547
diff
changeset
|
2522 unsigned int height) |
fab5777f4dd4
ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3547
diff
changeset
|
2523 { |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3690
diff
changeset
|
2524 std::unique_ptr<ImageAccessor> target(new Image(source.GetFormat(), width, height, false)); |
3549
fab5777f4dd4
ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3547
diff
changeset
|
2525 FitSize(*target, source); |
fab5777f4dd4
ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3547
diff
changeset
|
2526 return target.release(); |
fab5777f4dd4
ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3547
diff
changeset
|
2527 } |
4082
2e1564f57542
ImageProcessing::FitSizeKeepAspectRatio()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4080
diff
changeset
|
2528 |
2e1564f57542
ImageProcessing::FitSizeKeepAspectRatio()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4080
diff
changeset
|
2529 |
2e1564f57542
ImageProcessing::FitSizeKeepAspectRatio()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4080
diff
changeset
|
2530 ImageAccessor* ImageProcessing::FitSizeKeepAspectRatio(const ImageAccessor& source, |
2e1564f57542
ImageProcessing::FitSizeKeepAspectRatio()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4080
diff
changeset
|
2531 unsigned int width, |
2e1564f57542
ImageProcessing::FitSizeKeepAspectRatio()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4080
diff
changeset
|
2532 unsigned int height) |
2e1564f57542
ImageProcessing::FitSizeKeepAspectRatio()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4080
diff
changeset
|
2533 { |
2e1564f57542
ImageProcessing::FitSizeKeepAspectRatio()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4080
diff
changeset
|
2534 std::unique_ptr<ImageAccessor> target(new Image(source.GetFormat(), width, height, false)); |
2e1564f57542
ImageProcessing::FitSizeKeepAspectRatio()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4080
diff
changeset
|
2535 Set(*target, 0); |
2e1564f57542
ImageProcessing::FitSizeKeepAspectRatio()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4080
diff
changeset
|
2536 |
2e1564f57542
ImageProcessing::FitSizeKeepAspectRatio()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4080
diff
changeset
|
2537 if (width != 0 && |
2e1564f57542
ImageProcessing::FitSizeKeepAspectRatio()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4080
diff
changeset
|
2538 height != 0 && |
2e1564f57542
ImageProcessing::FitSizeKeepAspectRatio()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4080
diff
changeset
|
2539 source.GetWidth() != 0 && |
2e1564f57542
ImageProcessing::FitSizeKeepAspectRatio()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4080
diff
changeset
|
2540 source.GetHeight() != 0) |
2e1564f57542
ImageProcessing::FitSizeKeepAspectRatio()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4080
diff
changeset
|
2541 { |
2e1564f57542
ImageProcessing::FitSizeKeepAspectRatio()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4080
diff
changeset
|
2542 float ratio = std::min(static_cast<float>(width) / static_cast<float>(source.GetWidth()), |
2e1564f57542
ImageProcessing::FitSizeKeepAspectRatio()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4080
diff
changeset
|
2543 static_cast<float>(height) / static_cast<float>(source.GetHeight())); |
2e1564f57542
ImageProcessing::FitSizeKeepAspectRatio()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4080
diff
changeset
|
2544 |
2e1564f57542
ImageProcessing::FitSizeKeepAspectRatio()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4080
diff
changeset
|
2545 unsigned int resizedWidth = static_cast<unsigned int>( |
2e1564f57542
ImageProcessing::FitSizeKeepAspectRatio()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4080
diff
changeset
|
2546 boost::math::iround(ratio * static_cast<float>(source.GetWidth()))); |
2e1564f57542
ImageProcessing::FitSizeKeepAspectRatio()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4080
diff
changeset
|
2547 |
2e1564f57542
ImageProcessing::FitSizeKeepAspectRatio()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4080
diff
changeset
|
2548 unsigned int resizedHeight = static_cast<unsigned int>( |
2e1564f57542
ImageProcessing::FitSizeKeepAspectRatio()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4080
diff
changeset
|
2549 boost::math::iround(ratio * static_cast<float>(source.GetHeight()))); |
2e1564f57542
ImageProcessing::FitSizeKeepAspectRatio()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4080
diff
changeset
|
2550 |
2e1564f57542
ImageProcessing::FitSizeKeepAspectRatio()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4080
diff
changeset
|
2551 std::unique_ptr<ImageAccessor> resized(FitSize(source, resizedWidth, resizedHeight)); |
2e1564f57542
ImageProcessing::FitSizeKeepAspectRatio()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4080
diff
changeset
|
2552 |
2e1564f57542
ImageProcessing::FitSizeKeepAspectRatio()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4080
diff
changeset
|
2553 ImageAccessor region; |
2e1564f57542
ImageProcessing::FitSizeKeepAspectRatio()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4080
diff
changeset
|
2554 target->GetRegion(region, (width - resizedWidth) / 2, |
2e1564f57542
ImageProcessing::FitSizeKeepAspectRatio()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4080
diff
changeset
|
2555 (height - resizedHeight) / 2, resizedWidth, resizedHeight); |
2e1564f57542
ImageProcessing::FitSizeKeepAspectRatio()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4080
diff
changeset
|
2556 Copy(region, *resized); |
2e1564f57542
ImageProcessing::FitSizeKeepAspectRatio()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4080
diff
changeset
|
2557 } |
2e1564f57542
ImageProcessing::FitSizeKeepAspectRatio()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4080
diff
changeset
|
2558 |
2e1564f57542
ImageProcessing::FitSizeKeepAspectRatio()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4080
diff
changeset
|
2559 return target.release(); |
2e1564f57542
ImageProcessing::FitSizeKeepAspectRatio()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4080
diff
changeset
|
2560 } |
853 | 2561 } |