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