ITK  5.4.0
Insight Toolkit
itkLabelOverlayFunctor.h
Go to the documentation of this file.
1/*=========================================================================
2 *
3 * Copyright NumFOCUS
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 * https://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 itkLabelOverlayFunctor_h
19#define itkLabelOverlayFunctor_h
20
22#include "itkMath.h"
23
24namespace itk
25{
26namespace Functor
27{
47template <typename TInputPixel, typename TLabel, typename TRGBPixel>
49{
50public:
52 {
53 // provide some default value for external use (outside
54 // LabelOverlayFunctorImageFilter) Inside LabelOverlayFunctorImageFilter,
55 // the values are always initialized
56 m_Opacity = 1.0;
57 m_BackgroundValue = TLabel{};
58 }
61 inline TRGBPixel
62 operator()(const TInputPixel & p1, const TLabel & p2) const
63 {
64 TRGBPixel rgbPixel;
66
67 if (p2 == m_BackgroundValue)
68 {
69 // value is background
70 // return a gray pixel with the same intensity than the input pixel
71 auto p = static_cast<typename TRGBPixel::ValueType>(p1);
72 rgbPixel[0] = p;
73 rgbPixel[1] = p;
74 rgbPixel[2] = p;
75 return rgbPixel;
76 }
77
78 // taint the input pixel with the colored one returned by
79 // the color functor.
80 TRGBPixel opaque = m_RGBFunctor(p2);
81 // the following has been unrolled due to a bug with apple's
82 // llvm-gcc-4.2 build 5658
83 const double p1_blend = p1 * (1.0 - m_Opacity);
84 rgbPixel[0] = static_cast<typename TRGBPixel::ValueType>(opaque[0] * m_Opacity + p1_blend);
85 rgbPixel[1] = static_cast<typename TRGBPixel::ValueType>(opaque[1] * m_Opacity + p1_blend);
86 rgbPixel[2] = static_cast<typename TRGBPixel::ValueType>(opaque[2] * m_Opacity + p1_blend);
87
88 return rgbPixel;
89 }
90
91 bool
92 operator==(const LabelOverlayFunctor & other) const
93 {
96 }
97
99
101
102 void
103 SetOpacity(double opacity)
104 {
105 m_Opacity = opacity;
106 }
107
108 void
110 {
112 m_RGBFunctor.SetBackgroundValue(v);
113 }
114
115 void
117 {
118 m_RGBFunctor.ResetColors();
119 }
120
121 unsigned int
123 {
124 return m_RGBFunctor.GetNumberOfColors();
125 }
126
128 using ComponentType = typename TRGBPixel::ComponentType;
129
130 void
131 AddColor(unsigned char r, unsigned char g, unsigned char b)
132 {
133 m_RGBFunctor.AddColor(r, g, b);
134 }
135
136protected:
137private:
138 double m_Opacity;
140
142};
143} // end namespace Functor
144} // end namespace itk
145
146#endif
Functor for applying a colormap to a label image and combine it with a grayscale image.
TRGBPixel operator()(const TInputPixel &p1, const TLabel &p2) const
bool operator==(const LabelOverlayFunctor &other) const
void AddColor(unsigned char r, unsigned char g, unsigned char b)
ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(LabelOverlayFunctor)
Functor::LabelToRGBFunctor< TLabel, TRGBPixel > m_RGBFunctor
typename TRGBPixel::ComponentType ComponentType
Functor for converting labels into RGB triplets.
static void SetLength(T &m, const unsigned int s)
bool ExactlyEquals(const TInput1 &x1, const TInput2 &x2)
Return the result of an exact comparison between two scalar values of potentially different types.
Definition: itkMath.h:726
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....