iRoCS Toolbox  1.1.0
lmorph.hh
Go to the documentation of this file.
1 /**************************************************************************
2  *
3  * Copyright (C) 2015 Kun Liu, Thorsten Falk
4  *
5  * Image Analysis Lab, University of Freiburg, Germany
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software Foundation,
19  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  *
21  **************************************************************************/
22 
23 /*
24  * lMorph.hh
25  *
26  * Created on: Nov 2, 2010
27  * Author: liu
28  */
29 
30 #ifndef _LMORPH_HH
31 #define _LMORPH_HH
32 
33 #ifdef HAVE_CONFIG_H
34 #include <config.hh>
35 #endif
36 
37 #include <queue>
38 
39 #include <blitz/array.h>
40 
41 #include "DisjointSets.hh"
42 
43 // //-------------------designed for 3D----------------------------------
44 
45 template<typename VoxelT, int Dim>
46 void morphDilate(blitz::Array<VoxelT,Dim> &data, int size);
47 
48 template<typename VoxelT, int Dim>
49 void morphClose(blitz::Array<VoxelT,Dim> &data, int size);
50 
51 template<typename MarkerT, typename LabelT, int Dim>
53  blitz::Array<MarkerT,Dim> &marker, blitz::Array<LabelT,Dim> &label,
54  int conn);
55 
56 template<typename VoxelT, typename MarkerT, typename LabelT, int Dim>
57 void morphWatershed(
58  blitz::Array<VoxelT,Dim> &data, blitz::Array<MarkerT,Dim> &marker,
59  blitz::Array<LabelT,Dim> &label, int conn);
60 
61 //with labeled marker
62 template<typename VoxelT, typename LabelT, int Dim>
63 void morphWatershed(
64  blitz::Array<VoxelT,Dim> &data, blitz::Array<LabelT,Dim> &label, int conn);
65 
66 /*
67  * note that the boundary on the border will be omitted.
68  */
69 template<typename Type, typename bType, int Dim>
71  blitz::Array<Type,Dim> &phi, Type thresh, blitz::Array<bType,Dim> &border);
72 
73 // helper for watersheding
74 template<typename DT, typename PT>
76 {
77  DT m_value;
79  long int m_order;
80 
81  explicit orderedPrioritizedNode(DT value, PT priority, long int order);
82 
83  //Operator overloading for priority comparison
84  bool operator <(orderedPrioritizedNode const &opN) const;
85 };
86 
87 static const int moveIn3DNeighbor[26][3] =
88 {
89  { -1, 0, 0 },
90  { 1, 0, 0 },
91  { 0, -1, 0 },
92  { 0, 1, 0 },
93  { 0, 0, -1 },
94  { 0, 0, 1 },
95 
96  { -1, -1, 0 },
97  { -1, 1, 0 },
98  { 1, -1, 0 },
99  { 1, 1, 0 },
100 
101  { -1, 0, -1 },
102  { -1, 0, 1 },
103  { 1, 0, -1 },
104  { 1, 0, 1 },
105 
106  { 0, -1, -1 },
107  { 0, -1, 1 },
108  { 0, 1, -1 },
109  { 0, 1, 1 },
110 
111  { -1, -1, -1 },
112  { -1, -1, 1 },
113  { -1, 1, -1 },
114  { 1, -1, -1 },
115  { -1, 1, 1 },
116  { 1, -1, 1 },
117  { 1, 1, -1 },
118  { 1, 1, 1 } };
119 
120 static const int moveIn3DHalfNeighbor[13][3] =
121 {
122  { -1, 0, 0 },
123  { 0, -1, 0 },
124  { 0, 0, -1 },
125 
126  { -1, -1, 0 },
127  { -1, 1, 0 },
128  { -1, 0, -1 },
129  { -1, 0, 1 },
130  { 0, -1, -1 },
131  { 0, -1, 1 },
132 
133  { -1, -1, -1 },
134  { -1, -1, 1 },
135  { -1, 1, -1 },
136  { -1, 1, 1 }, };
137 
138 class Walker3D
139 {
140 public:
141  Walker3D();
142  Walker3D(blitz::TinyVector<int, 3> shape, int conn);
143  void setLocation(const blitz::TinyVector<int, 3> &p);
144  bool getNextNeighbor(blitz::TinyVector<int, 3> &q);
145 private:
146  blitz::TinyVector<int, 3> m_p;
147  int m_conn;
148  int walks;
149  blitz::TinyVector<int, 3> m_shape;
150 };
151 
153 {
154 public:
155  Scanner3D();
156  Scanner3D(blitz::TinyVector<int, 3> shape, int conn);
157  void setLocation(const blitz::TinyVector<int, 3> &p);
158  bool getNextNeighbor(blitz::TinyVector<int, 3> &q);
159 private:
160  //current position
161  blitz::TinyVector<int, 3> m_p;
162  // connectivity
163  int m_conn;
164  //a counter for how many neighbors already visited
165  int walks;
166  // image size for border check
167  blitz::TinyVector<int, 3> m_shape;
168 };
169 
170 #include "lmorph.icc"
171 
172 #endif
void morphWatershed(blitz::Array< VoxelT, Dim > &data, blitz::Array< MarkerT, Dim > &marker, blitz::Array< LabelT, Dim > &label, int conn)
void morphClose(blitz::Array< VoxelT, Dim > &data, int size)
void morphDilate(blitz::Array< VoxelT, Dim > &data, int size)
void morphConnectedComponentLabelling(blitz::Array< MarkerT, Dim > &marker, blitz::Array< LabelT, Dim > &label, int conn)
bool operator<(orderedPrioritizedNode const &opN) const
static const int moveIn3DHalfNeighbor[13][3]
Definition: lmorph.hh:120
static const int moveIn3DNeighbor[26][3]
Definition: lmorph.hh:87
void morphBoundaryDetection(blitz::Array< Type, Dim > &phi, Type thresh, blitz::Array< bType, Dim > &border)
orderedPrioritizedNode(DT value, PT priority, long int order)