annotate OrthancStone/Sources/Toolbox/ImageToolbox.cpp @ 1512:244ad1e4e76a

reorganization of folders
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 07 Jul 2020 16:21:02 +0200
parents Framework/Toolbox/ImageToolbox.cpp@121d01aa328e
children 4fb8fdf03314
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
6 *
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
9 * 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
10 * the License, or (at your option) any later version.
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
11 *
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
12 * 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
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
15 * Affero General Public License for more details.
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
16 *
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
19 **/
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
20
1484
121d01aa328e SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1455
diff changeset
21 #include "../OrthancStone.h"
1286
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
22 #include "ImageToolbox.h"
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
23
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
24 #include "../StoneException.h"
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
25
1455
30deba7bc8e2 simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1296
diff changeset
26 #include <Images/ImageProcessing.h>
30deba7bc8e2 simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1296
diff changeset
27 #include <Images/PixelTraits.h>
1286
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
28
1455
30deba7bc8e2 simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1296
diff changeset
29 #include <Logging.h>
30deba7bc8e2 simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1296
diff changeset
30 #include <OrthancException.h>
1286
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
31
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
32 #include <boost/static_assert.hpp>
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
33 #include <boost/type_traits.hpp>
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
34
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
35 #include <vector>
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
36
1484
121d01aa328e SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1455
diff changeset
37 #if !defined(ORTHANC_ENABLE_DCMTK)
121d01aa328e SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1455
diff changeset
38 # error ORTHANC_ENABLE_DCMTK is not defined
121d01aa328e SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1455
diff changeset
39 #endif
121d01aa328e SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1455
diff changeset
40
121d01aa328e SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1455
diff changeset
41 #if !defined(ORTHANC_ENABLE_DCMTK_JPEG)
121d01aa328e SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1455
diff changeset
42 # 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
43 #endif
121d01aa328e SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1455
diff changeset
44
121d01aa328e SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1455
diff changeset
45 #if !defined(ORTHANC_ENABLE_DCMTK_JPEG_LOSSLESS)
121d01aa328e SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1455
diff changeset
46 # 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
47 #endif
121d01aa328e SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1455
diff changeset
48
121d01aa328e SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1455
diff changeset
49
1286
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
50 namespace OrthancStone
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
51 {
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
52 namespace
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 using Orthanc::PixelTraits;
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
55 using Orthanc::PixelFormat;
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
56 using Orthanc::ImageAccessor;
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
1288
d8c42e5e5843 Fixed clang errors
Benjamin Golinvaux <bgo@osimis.io>
parents: 1286
diff changeset
59 template<typename Orthanc::PixelFormat Format>
1286
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
60 class PixelBinner
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
61 {
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
62 // "PixelBinner requires an arithmetic (integer or floating-point) pixel format"
1288
d8c42e5e5843 Fixed clang errors
Benjamin Golinvaux <bgo@osimis.io>
parents: 1286
diff changeset
63 typedef typename Orthanc::PixelTraits<Format>::PixelType PixelType;
1286
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
64 BOOST_STATIC_ASSERT(boost::is_arithmetic<PixelType>::value);
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
65
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
66 public:
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
67 PixelBinner(HistogramData& hd, double minValue, double maxValue)
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
68 : hd_(hd)
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
69 , minValue_(minValue)
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
70 , maxValue_(maxValue)
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
71 , division_(1.0 / hd_.binSize)
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
72 {
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
73 ORTHANC_ASSERT(hd_.bins.size() > 0);
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
74 ORTHANC_ASSERT(maxValue > minValue);
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
75 }
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
76
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
77 ORTHANC_FORCE_INLINE void AddPixel(PixelType p)
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 if (p <= minValue_)
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 hd_.bins[0] += 1;
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 else if (p >= maxValue_)
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 hd_.bins.back() += 1;
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 else
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 double distanceFromMin = p - minValue_;
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
90 size_t binIndex = static_cast<size_t>(
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
91 std::floor(distanceFromMin * division_));
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
92 if (binIndex >= hd_.bins.size())
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
93 binIndex = hd_.bins.size() - 1;
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
94 hd_.bins[binIndex] += 1;
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
95 }
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
96 }
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
97 private:
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
98 HistogramData& hd_;
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
99 double minValue_;
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
100 double maxValue_;
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
101 double division_;
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
102 };
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
103
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
104 template<PixelFormat Format>
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
105 struct Histogram
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
106 {
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
107 typedef typename PixelTraits<Format>::PixelType PixelType;
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 static void Apply(const Orthanc::ImageAccessor& img, HistogramData& hd,
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
110 double minValue = 0,
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
111 double maxValue = 0)
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
112 {
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
113 ORTHANC_ASSERT(Format == img.GetFormat(),
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
114 "Internal error. Wrong template histogram type");
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
115
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
116 const size_t height = img.GetHeight();
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
117 const size_t width = img.GetHeight();
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
118
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
119 if ((minValue == 0) && (maxValue == 0))
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 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
122 //ORTHANC_ASSERT(boost::is_integral<PixelType>::value,
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
123 // "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
124 //
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
125 //PixelTraits<Format>::SetMinValue(minValue);
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
126 //PixelTraits<Format>::SetMaxValue(maxValue);
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
127 }
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
128
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
129 hd.minValue = minValue;
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 // the following code is not really pretty but ensures
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
132 size_t numBins = static_cast<size_t>(
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
133 std::ceil((maxValue - minValue) / hd.binSize));
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
134
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
135 hd.bins.resize(numBins);
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
136 std::fill(hd.bins.begin(), hd.bins.end(), 0);
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
137
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
138 PixelBinner<Format> binner(hd, minValue, maxValue);
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
139 for (uint32_t y = 0; y < height; ++y)
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
140 {
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
141 const PixelType* curPix = reinterpret_cast<const PixelType*>(
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
142 img.GetConstRow(y));
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
143
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
144 for (uint32_t x = 0; x < width; x++, curPix++)
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 binner.AddPixel(*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 }
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 template<PixelFormat Format>
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
154 struct ComputeMinMax__
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
155 {
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
156 typedef typename PixelTraits<Format>::PixelType PixelType;
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 static void Apply(const Orthanc::ImageAccessor& img,
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
159 PixelType& minValue, PixelType& maxValue)
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
160 {
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
161 ORTHANC_ASSERT(Format == img.GetFormat(),
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
162 "Internal error. Wrong template histogram type");
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
163
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
164 const size_t height = img.GetHeight();
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
165 const size_t width = img.GetHeight();
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
166
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
167 if (height * width == 0)
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 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat);
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
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
172 // 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
173 PixelTraits<Format>::SetMaxValue(minValue);
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
174 PixelTraits<Format>::SetMinValue(maxValue);
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
175
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
176 for (uint32_t y = 0; y < height; ++y)
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 const PixelType* curPix = reinterpret_cast<const PixelType*>(
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
179 img.GetConstRow(y));
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
180
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
181 for (uint32_t x = 0; x < width; x++, curPix++)
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 if (*curPix <= minValue)
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
184 minValue = *curPix;
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
185 if (*curPix >= maxValue)
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
186 maxValue = *curPix;
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
187 }
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
188 }
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 template<PixelFormat Format>
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
193 void ComputeMinMax_(const Orthanc::ImageAccessor& img,
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
194 double& minValue, double& maxValue)
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
195 {
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
196 typedef typename PixelTraits<Format>::PixelType PixelType;
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
197 PixelType minValuePix = PixelType();
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
198 PixelType maxValuePix = PixelType();
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
199 ComputeMinMax__<Format>::Apply(img, minValuePix, maxValuePix);
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
200 minValue = static_cast<double>(minValuePix);
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
201 maxValue = static_cast<double>(maxValuePix);
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
202 }
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
203
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
204 template<PixelFormat Format>
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
205 void ComputeHistogram_(const Orthanc::ImageAccessor& img, HistogramData& hd)
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
206 {
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
207 typedef typename PixelTraits<Format>::PixelType PixelType;
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
208 PixelType minValue = PixelType();
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
209 PixelType maxValue = PixelType();
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
210 ComputeMinMax__<Format>::Apply(img, minValue, maxValue);
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
211
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
212 // 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
213 Histogram<Format>::Apply(img, hd,
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
214 static_cast<double>(minValue) - 0.5,
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
215 static_cast<double>(maxValue) + 0.5);
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
216 }
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
217 }
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 void ComputeHistogram(const Orthanc::ImageAccessor& img,
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
220 HistogramData& hd, double binSize)
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
221 {
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
222 using namespace Orthanc;
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 {
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
229 case PixelFormat_Grayscale8:
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
230 ComputeHistogram_<PixelFormat_Grayscale8> (img, hd);
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
231 break;
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
232 case PixelFormat_Grayscale16:
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
233 ComputeHistogram_<PixelFormat_Grayscale16> (img, hd);
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
234 break;
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
235 case PixelFormat_SignedGrayscale16:
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
236 ComputeHistogram_<PixelFormat_SignedGrayscale16>(img, hd);
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
237 break;
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
238 case PixelFormat_Float32:
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
239 ComputeHistogram_<PixelFormat_Float32> (img, hd);
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
240 break;
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
241 case PixelFormat_Grayscale32:
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
242 ComputeHistogram_<PixelFormat_Grayscale32> (img, hd);
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
243 break;
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
244 case PixelFormat_Grayscale64:
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
245 ComputeHistogram_<PixelFormat_Grayscale64> (img, hd);
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 using namespace Orthanc;
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
256
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
257 // dynamic/static bridge
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
258 switch (img.GetFormat())
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
259 {
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
260 case PixelFormat_Grayscale8:
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
261 ComputeMinMax_<PixelFormat_Grayscale8> (img, minValue, maxValue);
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
262 break;
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
263 case PixelFormat_Grayscale16:
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
264 ComputeMinMax_<PixelFormat_Grayscale16> (img, minValue, maxValue);
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
265 break;
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
266 case PixelFormat_SignedGrayscale16:
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
267 ComputeMinMax_<PixelFormat_SignedGrayscale16>(img, minValue, maxValue);
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
268 break;
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
269 case PixelFormat_Float32:
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
270 ComputeMinMax_<PixelFormat_Float32> (img, minValue, maxValue);
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
271 break;
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
272 case PixelFormat_Grayscale32:
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
273 ComputeMinMax_<PixelFormat_Grayscale32> (img, minValue, maxValue);
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
274 break;
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
275 case PixelFormat_Grayscale64:
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
276 ComputeMinMax_<PixelFormat_Grayscale64> (img, minValue, maxValue);
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
277 break;
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
278 default:
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
279 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat);
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 }
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 void DumpHistogramResult(std::string& s, const HistogramData& hd)
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
285 {
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
286 std::stringstream ss;
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
287 ss << "Histogram:\n";
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
288 ss << "==========\n";
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
289 ss << "\n";
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
290 ss << "minValue : " << hd.minValue << "\n";
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
291 ss << "binSize : " << hd.binSize << "\n";
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
292 ss << "bins.size() : " << hd.bins.size() << "\n";
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
293 ss << "bins :\n";
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
294 double curBinStart = hd.minValue;
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
295 size_t pixCount = 0;
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
296 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
297 {
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
298 ss << "index: " << i << " (from " << curBinStart << " to "
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
299 << curBinStart + hd.binSize << ") : " << hd.bins[i] << " pixels\n";
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
300 curBinStart += hd.binSize;
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
301 pixCount += hd.bins[i];
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
302 }
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
303 ss << "total pix. count: " << pixCount << "\n";
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
304 s = ss.str();
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
305 }
1484
121d01aa328e SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1455
diff changeset
306
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 bool ImageToolbox::IsDecodingSupported(Orthanc::DicomTransferSyntax& 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 switch (transferSyntax)
121d01aa328e SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1455
diff changeset
311 {
121d01aa328e SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1455
diff changeset
312 case Orthanc::DicomTransferSyntax_LittleEndianImplicit:
121d01aa328e SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1455
diff changeset
313 case Orthanc::DicomTransferSyntax_LittleEndianExplicit:
121d01aa328e SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1455
diff changeset
314 case Orthanc::DicomTransferSyntax_DeflatedLittleEndianExplicit:
121d01aa328e SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1455
diff changeset
315 case Orthanc::DicomTransferSyntax_BigEndianExplicit:
121d01aa328e SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1455
diff changeset
316 case Orthanc::DicomTransferSyntax_RLELossless:
121d01aa328e SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1455
diff changeset
317 return true;
121d01aa328e SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1455
diff changeset
318
121d01aa328e SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1455
diff changeset
319 #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
320 case Orthanc::DicomTransferSyntax_JPEGProcess1:
121d01aa328e SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1455
diff changeset
321 case Orthanc::DicomTransferSyntax_JPEGProcess2_4:
121d01aa328e SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1455
diff changeset
322 case Orthanc::DicomTransferSyntax_JPEGProcess14:
121d01aa328e SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1455
diff changeset
323 case Orthanc::DicomTransferSyntax_JPEGProcess14SV1:
121d01aa328e SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1455
diff changeset
324 return true;
121d01aa328e SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1455
diff changeset
325 #endif
121d01aa328e SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1455
diff changeset
326
121d01aa328e SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1455
diff changeset
327 #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
328 case Orthanc::DicomTransferSyntax_JPEGLSLossless:
121d01aa328e SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1455
diff changeset
329 case Orthanc::DicomTransferSyntax_JPEGLSLossy:
121d01aa328e SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1455
diff changeset
330 return true;
121d01aa328e SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1455
diff changeset
331 #endif
121d01aa328e SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1455
diff changeset
332
121d01aa328e SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1455
diff changeset
333 default:
121d01aa328e SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1455
diff changeset
334 return false;
121d01aa328e SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1455
diff changeset
335 }
121d01aa328e SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1455
diff changeset
336 }
1286
ddb6676bbcbf Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
337 }