My Project
convert.hh
Go to the documentation of this file.
1/* -*- mia-c++ -*-
2 *
3 * This file is part of MIA - a toolbox for medical image analysis
4 * Copyright (c) Leipzig, Madrid 1999-2017 Gert Wollny
5 *
6 * MIA is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with MIA; if not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20
21#ifndef __mia_internal_convert_hh
22#define __mia_internal_convert_hh
23
24#include <mia/core/filter.hh>
25
26
28
30/*
31
32 \ingroup templates
33 \brief Generic pixel conversion for images
34
35 This class implements the image pixel type conversion.
36 Various mappings are supported and defined as EPixelConversion.
37 \tparam Image the image type that must provide STL-like iterators.
38 */
39template <class Image>
40class TConvert: public TDataFilter<Image>
41{
42public:
44
52 TConvert(mia::EPixelType pt, EPixelConversion ct, float a, float b);
53
61 template <template <typename> class Data, typename T>
62 typename TConvert<Image>::result_type operator () (const Data<T>& data) const;
63
64private:
65 template <template <typename> class Data, typename S, typename T>
66 typename TConvert<Image>::result_type convert(const Data<S>& src) const;
67 typename TConvert::result_type do_filter(const Image& image) const;
68
69 EPixelType m_pt;
71 float m_a;
72 float m_b;
73};
74
75/*
76 \ingroup templates
77 \brief Generic plug-in for pixel conversion image filters
78*/
79template <class Image>
80class TConvertFilterPlugin: public TDataFilterPlugin<Image>
81{
82public:
83 TConvertFilterPlugin();
84private:
85 virtual TDataFilter<Image> *do_create()const;
86 virtual const std::string do_get_descr()const;
87
88 EPixelType m_pixeltype;
89 EPixelConversion m_convert;
90 float m_a;
91 float m_b;
92
93};
94
96
102template <typename T, bool is_float>
103struct __mia_round {
104 static T apply(T x)
105 {
106 return x;
107 }
108};
109
110template <typename T>
111struct __mia_round<T, false> {
112 static T apply(long double x)
113 {
114 return static_cast<T>(floor(x + 0.5));
115 }
116};
117
118template <typename T, bool is_float>
119struct __dispatch_minmax {
120 static std::pair<T, T> apply()
121 {
122 return std::pair<T, T>(std::numeric_limits<T>::min(), std::numeric_limits<T>::max());
123 }
124};
125
126template <typename T>
127struct __dispatch_minmax<T, true> {
128 static std::pair<T, T> apply()
129 {
130 return std::pair<T, T>(-1.0f, 1.0f);
131 }
132};
133
134template <typename T>
135struct get_minmax {
136 static std::pair<T, T> apply()
137 {
138 return __dispatch_minmax<T, std::is_floating_point<T>::value >::apply();
139 }
140};
141
143
145
146#endif
Generic image filter plugin base.
Definition: core/filter.hh:186
Generic interface class to data filters.
Definition: core/filter.hh:87
TFilter< std::shared_ptr< D > >::result_type result_type
result type of this filter
Definition: core/filter.hh:102
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition: defines.hh:33
#define NS_MIA_END
conveniance define to end the mia namespace
Definition: defines.hh:36
EPixelConversion
Definition: pixeltype.hh:51
EPixelType
Definition: pixeltype.hh:33