ITK
4.2.0
Insight Segmentation and Registration Toolkit
Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
ITK
Modules
Filtering
ImageFusion
include
itkLabelToRGBFunctor.h
Go to the documentation of this file.
1
/*=========================================================================
2
*
3
* Copyright Insight Software Consortium
4
*
5
* Licensed under the Apache License, Version 2.0 (the "License");
6
* you may not use this file except in compliance with the License.
7
* You may obtain a copy of the License at
8
*
9
* http://www.apache.org/licenses/LICENSE-2.0.txt
10
*
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
16
*
17
*=========================================================================*/
18
#ifndef __itkLabelToRGBFunctor_h
19
#define __itkLabelToRGBFunctor_h
20
21
#include <vector>
22
#include "
itkNumericTraits.h
"
23
24
namespace
itk
25
{
26
namespace
Functor
27
{
49
template
<
class
TLabel,
class
TRGBPixel >
50
class
LabelToRGBFunctor
51
{
52
public
:
53
54
typedef
LabelToRGBFunctor
Self
;
55
56
LabelToRGBFunctor
()
57
{
58
TRGBPixel rgbPixel;
59
60
typedef
typename
TRGBPixel::ValueType ValueType;
61
62
// the following colors are from "R", and named:
63
// "red" "green3" "blue" "cyan"
64
//"magenta" "darkorange1" "darkgreen" "blueviolet"
65
//"brown4" "navy" "yellow4" "violetred1"
66
//"salmon4" "turquoise4" "sienna3" "darkorchid1"
67
//"springgreen4" "mediumvioletred" "orangered3" "lightseagreen"
68
//"slateblue" "deeppink1" "aquamarine4" "royalblue1"
69
//"tomato3" "mediumblue" "violetred4" "darkmagenta"
70
//"violet" "red4"
71
// They are a good selection of distinct colours for plotting and
72
// overlays.
73
74
AddColor
(255, 0, 0);
75
AddColor
(0, 205, 0);
76
AddColor
(0, 0, 255);
77
AddColor
(0, 255, 255);
78
AddColor
(255, 0, 255);
79
AddColor
(255, 127, 0);
80
AddColor
(0, 100, 0);
81
AddColor
(138, 43, 226);
82
AddColor
(139, 35, 35);
83
AddColor
(0, 0, 128);
84
AddColor
(139, 139, 0);
85
AddColor
(255, 62, 150);
86
AddColor
(139, 76, 57);
87
AddColor
(0, 134, 139);
88
AddColor
(205, 104, 57);
89
AddColor
(191, 62, 255);
90
AddColor
(0, 139, 69);
91
AddColor
(199, 21, 133);
92
AddColor
(205, 55, 0);
93
AddColor
(32, 178, 170);
94
AddColor
(106, 90, 205);
95
AddColor
(255, 20, 147);
96
AddColor
(69, 139, 116);
97
AddColor
(72, 118, 255);
98
AddColor
(205, 79, 57);
99
AddColor
(0, 0, 205);
100
AddColor
(139, 34, 82);
101
AddColor
(139, 0, 139);
102
AddColor
(238, 130, 238);
103
AddColor
(139, 0, 0);
104
105
// provide some default value for external use (outside
106
// LabelToRGBImageFilter)
107
// Inside LabelToRGBImageFilter, the values are always initialized
108
NumericTraits<TRGBPixel>::SetLength
(
m_BackgroundColor
, 3);
109
m_BackgroundColor
.Fill(
NumericTraits< ValueType >::Zero
);
110
m_BackgroundValue
=
NumericTraits< TLabel >::Zero
;
111
}
112
113
inline
TRGBPixel
operator()
(
const
TLabel & p)
const
114
{
115
// value is background
116
// return a gray pixel with the same intensity than the label pixel
117
if
( p ==
m_BackgroundValue
)
118
{
119
return
m_BackgroundColor
;
120
}
121
122
// else, return a colored pixel from the color table
123
return
m_Colors
[p %
m_Colors
.size()];
124
}
125
126
void
AddColor
(
unsigned
char
r,
unsigned
char
g,
unsigned
char
b)
127
{
128
TRGBPixel rgbPixel;
129
NumericTraits<TRGBPixel>::SetLength
(rgbPixel, 3);
130
131
typedef
typename
TRGBPixel::ValueType ValueType;
132
133
ValueType m =
NumericTraits<ValueType>::max
();
134
135
rgbPixel[0] =
static_cast<
ValueType
>
(
static_cast<
double
>
( r ) / 255 * m );
136
rgbPixel[1] =
static_cast<
ValueType
>
(
static_cast<
double
>
( g ) / 255 * m );
137
rgbPixel[2] =
static_cast<
ValueType
>
(
static_cast<
double
>
( b ) / 255 * m );
138
m_Colors
.push_back(rgbPixel);
139
}
140
141
// Empty the color LUT
142
void
ResetColors
()
143
{
144
m_Colors
.clear();
145
}
146
147
// Get number of colors in the LUT
148
unsigned
int
GetNumberOfColors
()
const
149
{
150
return
m_Colors
.size();
151
}
152
153
bool
operator!=
(
const
Self
& l)
const
154
{
155
const
bool
areDifferent =
m_BackgroundColor
!= l.
m_BackgroundColor
156
||
m_BackgroundValue
!= l.
m_BackgroundValue
;
157
158
return
areDifferent;
159
}
160
161
bool
operator==
(
const
Self
& other)
const
162
{
163
return
!( *
this
!= other );
164
}
165
166
void
SetBackgroundValue
(TLabel v)
167
{
168
m_BackgroundValue
= v;
169
}
170
171
void
SetBackgroundColor
(TRGBPixel rgb)
172
{
173
m_BackgroundColor
= rgb;
174
}
175
176
~LabelToRGBFunctor
() {}
177
178
std::vector< TRGBPixel >
m_Colors
;
179
180
TRGBPixel
m_BackgroundColor
;
181
182
TLabel
m_BackgroundValue
;
183
};
184
}
// end namespace functor
185
}
// end namespace itk
186
187
#endif
188
Generated on Tue Jul 10 2012 23:33:59 for ITK by
1.8.1