ITK  6.0.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 
21 #include "itkLabelToRGBFunctor.h"
22 #include "itkMath.h"
23 
24 namespace itk
25 {
26 namespace Functor
27 {
47 template <typename TInputPixel, typename TLabel, typename TRGBPixel>
49 {
50 public:
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  {
95  m_RGBFunctor == other.m_RGBFunctor;
96  }
97 
99 
100  ~LabelOverlayFunctor() = default;
101 
102  void
103  SetOpacity(double opacity)
104  {
105  m_Opacity = opacity;
106  }
107 
108  void
110  {
111  m_BackgroundValue = v;
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 
136 protected:
137 private:
138  double m_Opacity;
140 
142 };
143 } // end namespace Functor
144 } // end namespace itk
145 
146 #endif
itk::Functor::LabelOverlayFunctor< FeatureImagePixelType, LabelMapPixelType, OutputImagePixelType >::ComponentType
typename OutputImagePixelType ::ComponentType ComponentType
Definition: itkLabelOverlayFunctor.h:128
itk::Functor::LabelOverlayFunctor::operator()
TRGBPixel operator()(const TInputPixel &p1, const TLabel &p2) const
Definition: itkLabelOverlayFunctor.h:62
itk::Functor::LabelOverlayFunctor::SetOpacity
void SetOpacity(double opacity)
Definition: itkLabelOverlayFunctor.h:103
itk::Functor::LabelOverlayFunctor
Functor for applying a colormap to a label image and combine it with a grayscale image.
Definition: itkLabelOverlayFunctor.h:48
itk::Functor::LabelOverlayFunctor::m_RGBFunctor
Functor::LabelToRGBFunctor< TLabel, TRGBPixel > m_RGBFunctor
Definition: itkLabelOverlayFunctor.h:141
itk::Functor::LabelOverlayFunctor::LabelOverlayFunctor
LabelOverlayFunctor()
Definition: itkLabelOverlayFunctor.h:51
itk::Functor::LabelOverlayFunctor::m_BackgroundValue
TLabel m_BackgroundValue
Definition: itkLabelOverlayFunctor.h:139
itk::Functor::LabelToRGBFunctor
Functor for converting labels into RGB triplets.
Definition: itkLabelToRGBFunctor.h:50
itk::Math::ExactlyEquals
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:722
itk::NumericTraits::SetLength
static void SetLength(T &m, const unsigned int s)
Definition: itkNumericTraits.h:187
itk::Functor::LabelOverlayFunctor::ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION
ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(LabelOverlayFunctor)
itk::Functor::LabelOverlayFunctor::~LabelOverlayFunctor
~LabelOverlayFunctor()=default
itk::Functor::LabelOverlayFunctor::ResetColors
void ResetColors()
Definition: itkLabelOverlayFunctor.h:116
itk::Functor::LabelOverlayFunctor::m_Opacity
double m_Opacity
Definition: itkLabelOverlayFunctor.h:138
itk::Functor::LabelOverlayFunctor::operator==
bool operator==(const LabelOverlayFunctor &other) const
Definition: itkLabelOverlayFunctor.h:92
itkLabelToRGBFunctor.h
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
itk::Functor::LabelOverlayFunctor::SetBackgroundValue
void SetBackgroundValue(TLabel v)
Definition: itkLabelOverlayFunctor.h:109
itk::Functor::LabelOverlayFunctor::AddColor
void AddColor(unsigned char r, unsigned char g, unsigned char b)
Definition: itkLabelOverlayFunctor.h:131
itkMath.h
itk::Functor::LabelOverlayFunctor::GetNumberOfColors
unsigned int GetNumberOfColors() const
Definition: itkLabelOverlayFunctor.h:122