Mercurial > hg > orthanc-stone
annotate Framework/Toolbox/ImageToolbox.h @ 1335:35469f75faa2
fix
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 31 Mar 2020 15:47:29 +0200 |
parents | ea6c2254536d |
children | 30deba7bc8e2 |
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 |
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 #pragma once |
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 "../StoneEnumerations.h" |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
25 #include "LinearAlgebra.h" |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
26 |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
27 #include <Core/Images/ImageAccessor.h> |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
28 |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
29 namespace OrthancStone |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
30 { |
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 /** |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
33 This structure represents the result of an histogram computation |
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 bins[0] contains the values in [minValue , minValue + binSize [ |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
36 bins[1] contains the values in [minValue + binSize, minValue + 2*binSize [ |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
37 bins[2] contains the values in [minValue + 2*binSize, minValue + 3*binSize [ |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
38 ... |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
39 bins[N-1] contains the values in [minValue + (N-1)*binSize, minValue + N*binSize [ |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
40 |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
41 */ |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
42 struct HistogramData |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
43 { |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
44 std::vector<size_t> bins; |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
45 double minValue; |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
46 double binSize; |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
47 }; |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
48 |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
49 /** |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
50 Dumps the supplied histogram to the supplied strings |
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 void DumpHistogramResult(std::string& s, const HistogramData& hd); |
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 /** |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
55 This will compute the histogram of the supplied image (count the number of |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
56 pixels). |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
57 |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
58 The image must contain arithmetic pixels (that is, having a single component, |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
59 integer or float). Compound pixel types like RGB, YUV are not supported and |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
60 will cause this function to throw an exception. |
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 The range of available values will be split in sets of size `binSize`, and |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
63 each set will contain the number of pixels in the given bin |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
64 (see HistogramResult above). |
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 void ComputeHistogram(const Orthanc::ImageAccessor& img, |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
67 HistogramData& hd, double binSize); |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
68 |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
69 |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
70 /** |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
71 Computes the min max values in an image |
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 void ComputeMinMax(const Orthanc::ImageAccessor& img, |
ddb6676bbcbf
Added Histogram functions (new files: ImageToolbox...)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
74 double& minValue, double& maxValue); |
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 } |