ITK  5.2.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 {
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;
58  }
60 
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
93  {
96  return areDifferent;
97  }
98 
99  bool
101  {
102  return !(*this != l);
103  }
104 
105  ~LabelOverlayFunctor() = default;
106 
107  void
108  SetOpacity(double opacity)
109  {
110  m_Opacity = opacity;
111  }
112 
113  void
115  {
116  m_BackgroundValue = v;
117  m_RGBFunctor.SetBackgroundValue(v);
118  }
119 
120  void
122  {
123  m_RGBFunctor.ResetColors();
124  }
125 
126  unsigned int
128  {
129  return m_RGBFunctor.GetNumberOfColors();
130  }
131 
133  using ComponentType = typename TRGBPixel::ComponentType;
134 
135  void
136  AddColor(unsigned char r, unsigned char g, unsigned char b)
137  {
138  m_RGBFunctor.AddColor(r, g, b);
139  }
140 
141 protected:
142 private:
143  double m_Opacity;
145 
147 };
148 } // end namespace Functor
149 } // end namespace itk
150 
151 #endif
itk::Functor::LabelOverlayFunctor< FeatureImagePixelType, LabelMapPixelType, OutputImagePixelType >::ComponentType
typename OutputImagePixelType ::ComponentType ComponentType
Definition: itkLabelOverlayFunctor.h:133
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:108
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:146
itk::Functor::LabelOverlayFunctor::LabelOverlayFunctor
LabelOverlayFunctor()
Definition: itkLabelOverlayFunctor.h:51
itk::Functor::LabelOverlayFunctor::m_BackgroundValue
TLabel m_BackgroundValue
Definition: itkLabelOverlayFunctor.h:144
itk::Functor::LabelOverlayFunctor::operator==
bool operator==(const LabelOverlayFunctor &l) const
Definition: itkLabelOverlayFunctor.h:100
itk::Functor::LabelToRGBFunctor
Functor for converting labels into RGB triplets.
Definition: itkLabelToRGBFunctor.h:50
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:121
itk::Functor::LabelOverlayFunctor::m_Opacity
double m_Opacity
Definition: itkLabelOverlayFunctor.h:143
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: itkAnnulusOperator.h:24
itk::Functor::LabelOverlayFunctor::SetBackgroundValue
void SetBackgroundValue(TLabel v)
Definition: itkLabelOverlayFunctor.h:114
itk::Functor::LabelOverlayFunctor::AddColor
void AddColor(unsigned char r, unsigned char g, unsigned char b)
Definition: itkLabelOverlayFunctor.h:136
itk::Functor::LabelOverlayFunctor::operator!=
bool operator!=(const LabelOverlayFunctor &l) const
Definition: itkLabelOverlayFunctor.h:92
itkMath.h
itk::Functor::LabelOverlayFunctor::GetNumberOfColors
unsigned int GetNumberOfColors() const
Definition: itkLabelOverlayFunctor.h:127