ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
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::Functor
25{
45template <typename TInputPixel, typename TLabel, typename TRGBPixel>
47{
48public:
50 : m_BackgroundValue(TLabel{})
51 {
52 // provide some default value for external use (outside
53 // LabelOverlayFunctorImageFilter) Inside LabelOverlayFunctorImageFilter,
54 // the values are always initialized
55 }
56
57 inline TRGBPixel
58 operator()(const TInputPixel & p1, const TLabel & p2) const
59 {
60 TRGBPixel rgbPixel;
62
63 if (p2 == m_BackgroundValue)
64 {
65 // value is background
66 // return a gray pixel with the same intensity than the input pixel
67 auto p = static_cast<typename TRGBPixel::ValueType>(p1);
68 rgbPixel[0] = p;
69 rgbPixel[1] = p;
70 rgbPixel[2] = p;
71 return rgbPixel;
72 }
73
74 // taint the input pixel with the colored one returned by
75 // the color functor.
76 TRGBPixel opaque = m_RGBFunctor(p2);
77 // the following has been unrolled due to a bug with apple's
78 // llvm-gcc-4.2 build 5658
79 const double p1_blend = p1 * (1.0 - m_Opacity);
80 rgbPixel[0] = static_cast<typename TRGBPixel::ValueType>(opaque[0] * m_Opacity + p1_blend);
81 rgbPixel[1] = static_cast<typename TRGBPixel::ValueType>(opaque[1] * m_Opacity + p1_blend);
82 rgbPixel[2] = static_cast<typename TRGBPixel::ValueType>(opaque[2] * m_Opacity + p1_blend);
83
84 return rgbPixel;
85 }
86
87 bool
88 operator==(const LabelOverlayFunctor & other) const
89 {
92 }
93
95
97
98 void
99 SetOpacity(double opacity)
100 {
101 m_Opacity = opacity;
102 }
103
104 void
106 {
108 m_RGBFunctor.SetBackgroundValue(v);
109 }
110
111 void
113 {
114 m_RGBFunctor.ResetColors();
115 }
116
117 [[nodiscard]] unsigned int
119 {
120 return m_RGBFunctor.GetNumberOfColors();
121 }
122
124 using ComponentType = typename TRGBPixel::ComponentType;
125
126 void
127 AddColor(unsigned char r, unsigned char g, unsigned char b)
128 {
129 m_RGBFunctor.AddColor(r, g, b);
130 }
131
132protected:
133private:
134 double m_Opacity{ 1.0 };
136
138};
139} // namespace itk::Functor
140
141#endif
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:716