Mercurial > hg > orthanc-stone
annotate OrthancStone/Sources/Toolbox/ImageToolbox.cpp @ 1925:a7a77488ddb1
fix
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 23 Mar 2022 14:21:22 +0100 |
parents | 7053b8a0aaec |
children | 07964689cb0b |
rev | line source |
---|---|
1286
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
1 /** |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
2 * Stone of Orthanc |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
1871
7053b8a0aaec
upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1870
diff
changeset
|
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium |
7053b8a0aaec
upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1870
diff
changeset
|
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
1286
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
7 * |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
8 * This program is free software: you can redistribute it and/or |
1598
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
9 * modify it under the terms of the GNU Lesser General Public License |
1286
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
10 * as published by the Free Software Foundation, either version 3 of |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
11 * the License, or (at your option) any later version. |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
12 * |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
13 * This program is distributed in the hope that it will be useful, but |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
14 * WITHOUT ANY WARRANTY; without even the implied warranty of |
1598
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
16 * Lesser General Public License for more details. |
1596
4fb8fdf03314
removed annoying whitespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
17 * |
1598
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
18 * You should have received a copy of the GNU Lesser General Public |
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
19 * License along with this program. If not, see |
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
20 * <http://www.gnu.org/licenses/>. |
1286
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
21 **/ |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
22 |
1484
121d01aa328e
SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1455
diff
changeset
|
23 #include "../OrthancStone.h" |
1286
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
24 #include "ImageToolbox.h" |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
25 |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
26 #include "../StoneException.h" |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
27 |
1455
30deba7bc8e2
simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1296
diff
changeset
|
28 #include <Images/ImageProcessing.h> |
30deba7bc8e2
simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1296
diff
changeset
|
29 #include <Images/PixelTraits.h> |
1286
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
30 |
1455
30deba7bc8e2
simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1296
diff
changeset
|
31 #include <Logging.h> |
30deba7bc8e2
simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1296
diff
changeset
|
32 #include <OrthancException.h> |
1286
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
33 |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
34 #include <boost/static_assert.hpp> |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
35 #include <boost/type_traits.hpp> |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
36 |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
37 #include <vector> |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
38 |
1484
121d01aa328e
SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1455
diff
changeset
|
39 #if !defined(ORTHANC_ENABLE_DCMTK) |
121d01aa328e
SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1455
diff
changeset
|
40 # error ORTHANC_ENABLE_DCMTK is not defined |
121d01aa328e
SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1455
diff
changeset
|
41 #endif |
121d01aa328e
SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1455
diff
changeset
|
42 |
121d01aa328e
SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1455
diff
changeset
|
43 #if !defined(ORTHANC_ENABLE_DCMTK_JPEG) |
121d01aa328e
SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1455
diff
changeset
|
44 # error ORTHANC_ENABLE_DCMTK_JPEG is not defined |
121d01aa328e
SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1455
diff
changeset
|
45 #endif |
121d01aa328e
SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1455
diff
changeset
|
46 |
121d01aa328e
SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1455
diff
changeset
|
47 #if !defined(ORTHANC_ENABLE_DCMTK_JPEG_LOSSLESS) |
121d01aa328e
SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1455
diff
changeset
|
48 # error ORTHANC_ENABLE_DCMTK_JPEG_LOSSLESS is not defined |
121d01aa328e
SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1455
diff
changeset
|
49 #endif |
121d01aa328e
SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1455
diff
changeset
|
50 |
121d01aa328e
SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1455
diff
changeset
|
51 |
1286
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
52 namespace OrthancStone |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
53 { |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
54 namespace |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
55 { |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
56 using Orthanc::PixelTraits; |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
57 using Orthanc::PixelFormat; |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
58 using Orthanc::ImageAccessor; |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
59 using Orthanc::PixelFormat; |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
60 |
1288 | 61 template<typename Orthanc::PixelFormat Format> |
1286
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
62 class PixelBinner |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
63 { |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
64 // "PixelBinner requires an arithmetic (integer or floating-point) pixel format" |
1288 | 65 typedef typename Orthanc::PixelTraits<Format>::PixelType PixelType; |
1286
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
66 BOOST_STATIC_ASSERT(boost::is_arithmetic<PixelType>::value); |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
67 |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
68 public: |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
69 PixelBinner(HistogramData& hd, double minValue, double maxValue) |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
70 : hd_(hd) |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
71 , minValue_(minValue) |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
72 , maxValue_(maxValue) |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
73 , division_(1.0 / hd_.binSize) |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
74 { |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
75 ORTHANC_ASSERT(hd_.bins.size() > 0); |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
76 ORTHANC_ASSERT(maxValue > minValue); |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
77 } |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
78 |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
79 ORTHANC_FORCE_INLINE void AddPixel(PixelType p) |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
80 { |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
81 if (p <= minValue_) |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
82 { |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
83 hd_.bins[0] += 1; |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
84 } |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
85 else if (p >= maxValue_) |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
86 { |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
87 hd_.bins.back() += 1; |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
88 } |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
89 else |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
90 { |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
91 double distanceFromMin = p - minValue_; |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
92 size_t binIndex = static_cast<size_t>( |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
93 std::floor(distanceFromMin * division_)); |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
94 if (binIndex >= hd_.bins.size()) |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
95 binIndex = hd_.bins.size() - 1; |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
96 hd_.bins[binIndex] += 1; |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
97 } |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
98 } |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
99 private: |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
100 HistogramData& hd_; |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
101 double minValue_; |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
102 double maxValue_; |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
103 double division_; |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
104 }; |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
105 |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
106 template<PixelFormat Format> |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
107 struct Histogram |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
108 { |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
109 typedef typename PixelTraits<Format>::PixelType PixelType; |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
110 |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
111 static void Apply(const Orthanc::ImageAccessor& img, HistogramData& hd, |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
112 double minValue = 0, |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
113 double maxValue = 0) |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
114 { |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
115 ORTHANC_ASSERT(Format == img.GetFormat(), |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
116 "Internal error. Wrong template histogram type"); |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
117 |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
118 const size_t height = img.GetHeight(); |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
119 const size_t width = img.GetHeight(); |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
120 |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
121 if ((minValue == 0) && (maxValue == 0)) |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
122 { |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
123 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
124 //ORTHANC_ASSERT(boost::is_integral<PixelType>::value, |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
125 // "Min and max values must be supplied for float-based histogram"); |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
126 // |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
127 //PixelTraits<Format>::SetMinValue(minValue); |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
128 //PixelTraits<Format>::SetMaxValue(maxValue); |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
129 } |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
130 |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
131 hd.minValue = minValue; |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
132 |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
133 // the following code is not really pretty but ensures |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
134 size_t numBins = static_cast<size_t>( |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
135 std::ceil((maxValue - minValue) / hd.binSize)); |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
136 |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
137 hd.bins.resize(numBins); |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
138 std::fill(hd.bins.begin(), hd.bins.end(), 0); |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
139 |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
140 PixelBinner<Format> binner(hd, minValue, maxValue); |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
141 for (uint32_t y = 0; y < height; ++y) |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
142 { |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
143 const PixelType* curPix = reinterpret_cast<const PixelType*>( |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
144 img.GetConstRow(y)); |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
145 |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
146 for (uint32_t x = 0; x < width; x++, curPix++) |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
147 { |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
148 binner.AddPixel(*curPix); |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
149 } |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
150 } |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
151 } |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
152 }; |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
153 |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
154 |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
155 template<PixelFormat Format> |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
156 struct ComputeMinMax__ |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
157 { |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
158 typedef typename PixelTraits<Format>::PixelType PixelType; |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
159 |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
160 static void Apply(const Orthanc::ImageAccessor& img, |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
161 PixelType& minValue, PixelType& maxValue) |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
162 { |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
163 ORTHANC_ASSERT(Format == img.GetFormat(), |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
164 "Internal error. Wrong template histogram type"); |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
165 |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
166 const size_t height = img.GetHeight(); |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
167 const size_t width = img.GetHeight(); |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
168 |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
169 if (height * width == 0) |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
170 { |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
171 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat); |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
172 } |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
173 |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
174 // min and max are crossed below. Think about it. This is OK :) |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
175 PixelTraits<Format>::SetMaxValue(minValue); |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
176 PixelTraits<Format>::SetMinValue(maxValue); |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
177 |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
178 for (uint32_t y = 0; y < height; ++y) |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
179 { |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
180 const PixelType* curPix = reinterpret_cast<const PixelType*>( |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
181 img.GetConstRow(y)); |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
182 |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
183 for (uint32_t x = 0; x < width; x++, curPix++) |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
184 { |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
185 if (*curPix <= minValue) |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
186 minValue = *curPix; |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
187 if (*curPix >= maxValue) |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
188 maxValue = *curPix; |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
189 } |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
190 } |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
191 } |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
192 }; |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
193 |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
194 template<PixelFormat Format> |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
195 void ComputeMinMax_(const Orthanc::ImageAccessor& img, |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
196 double& minValue, double& maxValue) |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
197 { |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
198 typedef typename PixelTraits<Format>::PixelType PixelType; |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
199 PixelType minValuePix = PixelType(); |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
200 PixelType maxValuePix = PixelType(); |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
201 ComputeMinMax__<Format>::Apply(img, minValuePix, maxValuePix); |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
202 minValue = static_cast<double>(minValuePix); |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
203 maxValue = static_cast<double>(maxValuePix); |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
204 } |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
205 |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
206 template<PixelFormat Format> |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
207 void ComputeHistogram_(const Orthanc::ImageAccessor& img, HistogramData& hd) |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
208 { |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
209 typedef typename PixelTraits<Format>::PixelType PixelType; |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
210 PixelType minValue = PixelType(); |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
211 PixelType maxValue = PixelType(); |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
212 ComputeMinMax__<Format>::Apply(img, minValue, maxValue); |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
213 |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
214 // make bins a little bigger to center integer pixel values |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
215 Histogram<Format>::Apply(img, hd, |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
216 static_cast<double>(minValue) - 0.5, |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
217 static_cast<double>(maxValue) + 0.5); |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
218 } |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
219 } |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
220 |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
221 void ComputeHistogram(const Orthanc::ImageAccessor& img, |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
222 HistogramData& hd, double binSize) |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
223 { |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
224 hd.binSize = binSize; |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
225 |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
226 // dynamic/static bridge |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
227 switch (img.GetFormat()) |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
228 { |
1742
911cd9a11ad3
removed "using namespace Orthanc"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
229 case Orthanc::PixelFormat_Grayscale8: |
911cd9a11ad3
removed "using namespace Orthanc"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
230 ComputeHistogram_<Orthanc::PixelFormat_Grayscale8> (img, hd); |
1286
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
231 break; |
1742
911cd9a11ad3
removed "using namespace Orthanc"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
232 case Orthanc::PixelFormat_Grayscale16: |
911cd9a11ad3
removed "using namespace Orthanc"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
233 ComputeHistogram_<Orthanc::PixelFormat_Grayscale16> (img, hd); |
1286
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
234 break; |
1742
911cd9a11ad3
removed "using namespace Orthanc"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
235 case Orthanc::PixelFormat_SignedGrayscale16: |
911cd9a11ad3
removed "using namespace Orthanc"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
236 ComputeHistogram_<Orthanc::PixelFormat_SignedGrayscale16>(img, hd); |
1286
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
237 break; |
1742
911cd9a11ad3
removed "using namespace Orthanc"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
238 case Orthanc::PixelFormat_Float32: |
911cd9a11ad3
removed "using namespace Orthanc"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
239 ComputeHistogram_<Orthanc::PixelFormat_Float32> (img, hd); |
1286
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
240 break; |
1742
911cd9a11ad3
removed "using namespace Orthanc"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
241 case Orthanc::PixelFormat_Grayscale32: |
911cd9a11ad3
removed "using namespace Orthanc"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
242 ComputeHistogram_<Orthanc::PixelFormat_Grayscale32> (img, hd); |
1286
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
243 break; |
1742
911cd9a11ad3
removed "using namespace Orthanc"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
244 case Orthanc::PixelFormat_Grayscale64: |
911cd9a11ad3
removed "using namespace Orthanc"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
245 ComputeHistogram_<Orthanc::PixelFormat_Grayscale64> (img, hd); |
1286
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
246 break; |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
247 default: |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
248 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat); |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
249 } |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
250 } |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
251 |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
252 void ComputeMinMax(const Orthanc::ImageAccessor& img, |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
253 double& minValue, double& maxValue) |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
254 { |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
255 // dynamic/static bridge |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
256 switch (img.GetFormat()) |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
257 { |
1742
911cd9a11ad3
removed "using namespace Orthanc"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
258 case Orthanc::PixelFormat_Grayscale8: |
911cd9a11ad3
removed "using namespace Orthanc"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
259 ComputeMinMax_<Orthanc::PixelFormat_Grayscale8> (img, minValue, maxValue); |
1286
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
260 break; |
1742
911cd9a11ad3
removed "using namespace Orthanc"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
261 case Orthanc::PixelFormat_Grayscale16: |
911cd9a11ad3
removed "using namespace Orthanc"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
262 ComputeMinMax_<Orthanc::PixelFormat_Grayscale16> (img, minValue, maxValue); |
1286
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
263 break; |
1742
911cd9a11ad3
removed "using namespace Orthanc"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
264 case Orthanc::PixelFormat_SignedGrayscale16: |
911cd9a11ad3
removed "using namespace Orthanc"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
265 ComputeMinMax_<Orthanc::PixelFormat_SignedGrayscale16>(img, minValue, maxValue); |
1286
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
266 break; |
1742
911cd9a11ad3
removed "using namespace Orthanc"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
267 case Orthanc::PixelFormat_Float32: |
911cd9a11ad3
removed "using namespace Orthanc"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
268 ComputeMinMax_<Orthanc::PixelFormat_Float32> (img, minValue, maxValue); |
1286
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
269 break; |
1742
911cd9a11ad3
removed "using namespace Orthanc"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
270 case Orthanc::PixelFormat_Grayscale32: |
911cd9a11ad3
removed "using namespace Orthanc"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
271 ComputeMinMax_<Orthanc::PixelFormat_Grayscale32> (img, minValue, maxValue); |
1286
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
272 break; |
1742
911cd9a11ad3
removed "using namespace Orthanc"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
273 case Orthanc::PixelFormat_Grayscale64: |
911cd9a11ad3
removed "using namespace Orthanc"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
274 ComputeMinMax_<Orthanc::PixelFormat_Grayscale64> (img, minValue, maxValue); |
1286
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
275 break; |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
276 default: |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
277 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat); |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
278 } |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
279 |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
280 } |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
281 |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
282 void DumpHistogramResult(std::string& s, const HistogramData& hd) |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
283 { |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
284 std::stringstream ss; |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
285 ss << "Histogram:\n"; |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
286 ss << "==========\n"; |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
287 ss << "\n"; |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
288 ss << "minValue : " << hd.minValue << "\n"; |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
289 ss << "binSize : " << hd.binSize << "\n"; |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
290 ss << "bins.size() : " << hd.bins.size() << "\n"; |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
291 ss << "bins :\n"; |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
292 double curBinStart = hd.minValue; |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
293 size_t pixCount = 0; |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
294 for (size_t i = 0; i < hd.bins.size(); ++i) |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
295 { |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
296 ss << "index: " << i << " (from " << curBinStart << " to " |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
297 << curBinStart + hd.binSize << ") : " << hd.bins[i] << " pixels\n"; |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
298 curBinStart += hd.binSize; |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
299 pixCount += hd.bins[i]; |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
300 } |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
301 ss << "total pix. count: " << pixCount << "\n"; |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
302 s = ss.str(); |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
303 } |
1484
121d01aa328e
SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1455
diff
changeset
|
304 |
121d01aa328e
SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1455
diff
changeset
|
305 |
121d01aa328e
SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1455
diff
changeset
|
306 bool ImageToolbox::IsDecodingSupported(Orthanc::DicomTransferSyntax& transferSyntax) |
121d01aa328e
SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1455
diff
changeset
|
307 { |
121d01aa328e
SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1455
diff
changeset
|
308 switch (transferSyntax) |
121d01aa328e
SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1455
diff
changeset
|
309 { |
121d01aa328e
SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1455
diff
changeset
|
310 case Orthanc::DicomTransferSyntax_LittleEndianImplicit: |
121d01aa328e
SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1455
diff
changeset
|
311 case Orthanc::DicomTransferSyntax_LittleEndianExplicit: |
121d01aa328e
SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1455
diff
changeset
|
312 case Orthanc::DicomTransferSyntax_DeflatedLittleEndianExplicit: |
121d01aa328e
SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1455
diff
changeset
|
313 case Orthanc::DicomTransferSyntax_BigEndianExplicit: |
121d01aa328e
SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1455
diff
changeset
|
314 case Orthanc::DicomTransferSyntax_RLELossless: |
121d01aa328e
SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1455
diff
changeset
|
315 return true; |
121d01aa328e
SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1455
diff
changeset
|
316 |
121d01aa328e
SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1455
diff
changeset
|
317 #if (ORTHANC_ENABLE_DCMTK == 1) && (ORTHANC_ENABLE_DCMTK_JPEG == 1) |
121d01aa328e
SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1455
diff
changeset
|
318 case Orthanc::DicomTransferSyntax_JPEGProcess1: |
121d01aa328e
SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1455
diff
changeset
|
319 case Orthanc::DicomTransferSyntax_JPEGProcess2_4: |
121d01aa328e
SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1455
diff
changeset
|
320 case Orthanc::DicomTransferSyntax_JPEGProcess14: |
121d01aa328e
SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1455
diff
changeset
|
321 case Orthanc::DicomTransferSyntax_JPEGProcess14SV1: |
121d01aa328e
SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1455
diff
changeset
|
322 return true; |
121d01aa328e
SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1455
diff
changeset
|
323 #endif |
121d01aa328e
SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1455
diff
changeset
|
324 |
121d01aa328e
SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1455
diff
changeset
|
325 #if (ORTHANC_ENABLE_DCMTK == 1) && (ORTHANC_ENABLE_DCMTK_JPEG_LOSSLESS == 1) |
121d01aa328e
SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1455
diff
changeset
|
326 case Orthanc::DicomTransferSyntax_JPEGLSLossless: |
121d01aa328e
SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1455
diff
changeset
|
327 case Orthanc::DicomTransferSyntax_JPEGLSLossy: |
121d01aa328e
SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1455
diff
changeset
|
328 return true; |
121d01aa328e
SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1455
diff
changeset
|
329 #endif |
121d01aa328e
SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1455
diff
changeset
|
330 |
121d01aa328e
SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1455
diff
changeset
|
331 default: |
121d01aa328e
SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1455
diff
changeset
|
332 return false; |
121d01aa328e
SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1455
diff
changeset
|
333 } |
121d01aa328e
SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1455
diff
changeset
|
334 } |
1286
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
335 } |