ITK  5.1.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  * 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 itkLabelOverlayFunctor_h
19 #define itkLabelOverlayFunctor_h
20 
21 #include "itkLabelToRGBFunctor.h"
22 #include "itkMath.h"
23 
24 namespace itk
25 {
26 namespace Functor
27 {
48 template <typename TInputPixel, typename TLabel, typename TRGBPixel>
50 {
51 public:
53  {
54  // provide some default value for external use (outside
55  // LabelOverlayFunctorImageFilter) Inside LabelOverlayFunctorImageFilter,
56  // the values are always initialized
57  m_Opacity = 1.0;
59  }
61 
62  inline TRGBPixel
63  operator()(const TInputPixel & p1, const TLabel & p2) const
64  {
65  TRGBPixel rgbPixel;
67 
68  if (p2 == m_BackgroundValue)
69  {
70  // value is background
71  // return a gray pixel with the same intensity than the input pixel
72  auto p = static_cast<typename TRGBPixel::ValueType>(p1);
73  rgbPixel[0] = p;
74  rgbPixel[1] = p;
75  rgbPixel[2] = p;
76  return rgbPixel;
77  }
78 
79  // taint the input pixel with the colored one returned by
80  // the color functor.
81  TRGBPixel opaque = m_RGBFunctor(p2);
82  // the following has been unrolled due to a bug with apple's
83  // llvm-gcc-4.2 build 5658
84  const double p1_blend = p1 * (1.0 - m_Opacity);
85  rgbPixel[0] = static_cast<typename TRGBPixel::ValueType>(opaque[0] * m_Opacity + p1_blend);
86  rgbPixel[1] = static_cast<typename TRGBPixel::ValueType>(opaque[1] * m_Opacity + p1_blend);
87  rgbPixel[2] = static_cast<typename TRGBPixel::ValueType>(opaque[2] * m_Opacity + p1_blend);
88 
89  return rgbPixel;
90  }
91 
92  bool
94  {
97  return areDifferent;
98  }
99 
100  bool
102  {
103  return !(*this != l);
104  }
105 
106  ~LabelOverlayFunctor() = default;
107 
108  void
109  SetOpacity(double opacity)
110  {
111  m_Opacity = opacity;
112  }
113 
114  void
116  {
117  m_BackgroundValue = v;
118  m_RGBFunctor.SetBackgroundValue(v);
119  }
120 
121  void
123  {
124  m_RGBFunctor.ResetColors();
125  }
126 
127  unsigned int
129  {
130  return m_RGBFunctor.GetNumberOfColors();
131  }
132 
134  using ComponentType = typename TRGBPixel::ComponentType;
135 
136  void
137  AddColor(unsigned char r, unsigned char g, unsigned char b)
138  {
139  m_RGBFunctor.AddColor(r, g, b);
140  }
141 
142 protected:
143 private:
144  double m_Opacity;
146 
148 };
149 } // end namespace Functor
150 } // end namespace itk
151 
152 #endif
itk::Functor::LabelOverlayFunctor< FeatureImagePixelType, LabelMapPixelType, OutputImagePixelType >::ComponentType
typename OutputImagePixelType ::ComponentType ComponentType
Definition: itkLabelOverlayFunctor.h:134
itk::Functor::LabelOverlayFunctor::operator()
TRGBPixel operator()(const TInputPixel &p1, const TLabel &p2) const
Definition: itkLabelOverlayFunctor.h:63
itk::Functor::LabelOverlayFunctor::SetOpacity
void SetOpacity(double opacity)
Definition: itkLabelOverlayFunctor.h:109
itk::Functor::LabelOverlayFunctor
Functor for applying a colormap to a label image and combine it with a grayscale image.
Definition: itkLabelOverlayFunctor.h:49
itk::Functor::LabelOverlayFunctor::m_RGBFunctor
Functor::LabelToRGBFunctor< TLabel, TRGBPixel > m_RGBFunctor
Definition: itkLabelOverlayFunctor.h:147
itk::Functor::LabelOverlayFunctor::LabelOverlayFunctor
LabelOverlayFunctor()
Definition: itkLabelOverlayFunctor.h:52
itk::Functor::LabelOverlayFunctor::m_BackgroundValue
TLabel m_BackgroundValue
Definition: itkLabelOverlayFunctor.h:145
itk::Functor::LabelOverlayFunctor::operator==
bool operator==(const LabelOverlayFunctor &l) const
Definition: itkLabelOverlayFunctor.h:101
itk::Functor::LabelToRGBFunctor
Functor for converting labels into RGB triplets.
Definition: itkLabelToRGBFunctor.h:51
itk::NumericTraits::SetLength
static void SetLength(T &m, const unsigned int s)
Definition: itkNumericTraits.h:185
itk::Math::NotExactlyEquals
bool NotExactlyEquals(const TInput1 &x1, const TInput2 &x2)
Definition: itkMath.h:733
itk::Functor::LabelOverlayFunctor::~LabelOverlayFunctor
~LabelOverlayFunctor()=default
itk::Functor::LabelOverlayFunctor::ResetColors
void ResetColors()
Definition: itkLabelOverlayFunctor.h:122
itk::Functor::LabelOverlayFunctor::m_Opacity
double m_Opacity
Definition: itkLabelOverlayFunctor.h:144
itk::NumericTraits::ZeroValue
static T ZeroValue()
Definition: itkNumericTraits.h:148
itkLabelToRGBFunctor.h
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkArray.h:26
itk::Functor::LabelOverlayFunctor::SetBackgroundValue
void SetBackgroundValue(TLabel v)
Definition: itkLabelOverlayFunctor.h:115
itk::Functor::LabelOverlayFunctor::AddColor
void AddColor(unsigned char r, unsigned char g, unsigned char b)
Definition: itkLabelOverlayFunctor.h:137
itk::Functor::LabelOverlayFunctor::operator!=
bool operator!=(const LabelOverlayFunctor &l) const
Definition: itkLabelOverlayFunctor.h:93
itkMath.h
itk::Functor::LabelOverlayFunctor::GetNumberOfColors
unsigned int GetNumberOfColors() const
Definition: itkLabelOverlayFunctor.h:128