-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathitkBoykovImageToGraphFunctor.h
executable file
·151 lines (123 loc) · 5.7 KB
/
itkBoykovImageToGraphFunctor.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: $RCSfile: itkBoykovImageToGraphFunctor.h,v $
Language: C++
Date:
Version: $Revision: 1.2 $
Copyright (c) Insight Software Consortium. All rights reserved.
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
Portions of this code are covered under the VTK copyright.
See VTKCopyright.txt or http://www.kitware.com/VTKCopyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef __itkBoykovImageToGraphTraits_h
#define __itkBoykovImageToGraphTraits_h
#include "itkDefaultImageToGraphFunctor.h"
namespace itk
{
/** \class itkBoykovImageToGraphFunctor
* \brief Class which defines node/edge weighting in constructing a
* graph from an image.
*
* \par
* Using the ImageToGraphFilter class, one wishes to construct a
* graph from a given input image. This functor determines whether
* or not a given pixel constitutes a node, what weight that node
* should have, and what edge weight should be assigned an edge
* between two nodes. The weighting scheme is based on the
* reference below. Also note that the weights of the nodes are
* used to n-link affinities whereas the edge weights store the
* t-link affinities. This eliminates unnecessary memory usage.
*
* \par INPUTS
* This class should be used in conjunction with the
* itkBoykovFilter class. As such, the resulting graph is
* going to have a binary labeling (sink vs. source). The input
* consists partly of 2 probability (likelihood) images of the
* same dimension and size as the input image. These can be
* derived from non-parametric techniques such as Parzen windowing,
* etc. Optional: 2 IndexContainerTypes of pixel indices can be
* specified to "hard-constrain" those pixels to be of a specific
* labeling. Other parameters include lambda and sigma which are
* described below.
*
* \par REFERENCE
* Y. Boykov and M.-P. Jolly, "Interactive Graph Cuts for Optimal Boundary
* & Region Segmentation of Objects in N-D Images," ICCV, 2001, 105-112.
*
**/
template<typename TInputImage, typename TOutputGraph>
class BoykovImageToGraphFunctor
: public DefaultImageToGraphFunctor<TInputImage, TOutputGraph>
{
public:
/** Standard class typedefs. */
typedef BoykovImageToGraphFunctor Self;
typedef DefaultImageToGraphFunctor<TInputImage, TOutputGraph> Superclass;
typedef SmartPointer<Self> Pointer;
typedef SmartPointer<const Self> ConstPointer;
/** Method for creation through the object factory. */
itkNewMacro( Self );
typedef TInputImage InputImageType;
typedef TOutputGraph OutputGraphType;
typedef typename Superclass::IndexType IndexType;
typedef typename Superclass::PixelType PixelType;
typedef typename Superclass::NodeType NodeType;
typedef typename Superclass::EdgeType EdgeType;
typedef typename Superclass::NodeIteratorType NodeIteratorType;
typedef typename Superclass::EdgeIteratorType EdgeIteratorType;
typedef typename Superclass::NodePointerType NodePointerType;
typedef typename Superclass::EdgePointerType EdgePointerType;
typedef typename Superclass::NodeWeightType NodeWeightType;
typedef typename Superclass::EdgeWeightType EdgeWeightType;
typedef typename Superclass::NodeImageType NodeImageType;
typedef typename Superclass::EdgeIdentifierContainerType
EdgeIdentifierContainerType;
typedef double RealType;
typedef std::vector<IndexType> IndexContainerType;
/** define virtual functions */
virtual EdgeWeightType GetEdgeWeight( IndexType, IndexType );
virtual NodeWeightType GetNodeWeight( IndexType idx )
{ return this->GetSinkDataTerm( idx ) - this->GetSourceDataTerm( idx ); }
virtual void NormalizeGraph( NodeImageType *, OutputGraphType * );
NodeWeightType GetSourceDataTerm( IndexType );
NodeWeightType GetSinkDataTerm( IndexType );
EdgeWeightType GetSmoothnessTerm( IndexType idx1, IndexType idx2 )
{ return this->GetEdgeWeight( idx1, idx2 ); }
/** lambda - factor which specifies the relative weighting
* between the regional properties and the boundary properties.
*/
itkGetMacro( Lambda, RealType );
itkSetMacro( Lambda, RealType );
/** sigma - standard deviation associated with the weighting
* of the distances between neighboring pixels/
*/
itkGetMacro( Sigma, RealType );
itkSetMacro( Sigma, RealType );
/** Declare the probability image type */
typedef Image<RealType, InputImageType::ImageDimension> LikelihoodImageType;
void SetSourceLikelihoodImage( const LikelihoodImageType * );
void SetSinkLikelihoodImage( const LikelihoodImageType * );
void SetSourceIndexContainer( const IndexContainerType source )
{ this->m_SourceIndexContainer = source; }
void SetSinkIndexContainer( const IndexContainerType sink )
{ this->m_SinkIndexContainer = sink; }
protected:
BoykovImageToGraphFunctor();
~BoykovImageToGraphFunctor() {}
void PrintSelf( std::ostream& os, Indent indent ) const;
private:
BoykovImageToGraphFunctor( const Self& ); //purposely not implemented
void operator=( const Self& ); //purposely not implemented
RealType m_Lambda;
RealType m_Sigma;
IndexContainerType m_SourceIndexContainer;
IndexContainerType m_SinkIndexContainer;
};
} // end namespace itk
#ifndef ITK_MANUAL_INSTANTIATION
#include "itkBoykovImageToGraphFunctor.hxx"
#endif
#endif