aimstil  5.0.5
morpho.h
Go to the documentation of this file.
1 #ifndef TIL_MORPHO_H
2 #define TIL_MORPHO_H
3 
4 #include <cartobase/config/cartobase_config.h>
5 
6 // includes from STL library
7 #include <memory>
8 #include <vector>
9 
10 // includes from TIL library
11 #include "til/til_common.h"
12 #include "til/miscTools.h"
13 #include "til/numeric_array.h"
14 
15 namespace til
16 {
17 
18 /*
21 template < typename TImage >
22 std::unique_ptr<std::vector<numeric_array<int,3> > >
23 findBorderPoints6(const ConstPtr<TImage> &im,
24  typename TImage::value_type foreground)
25 {
26  Ptr<PointList<int> > borderPoint = new PointList<int>;
27 
28  typename Iterator<TImage>::ConstVolumetric iIm(im);
29 
30  while (!iIm.isAtEnd())
31  {
32  if (*iIm == foreground)
33  {
34  if ((iIm.getX() > 0 && iIm(-1,0,0) != foreground) ||
35  (iIm.getX() < im.getX()-1 && iIm(+1,0,0) != foreground) ||
36  (iIm.getY() > 0 && iIm(0,-1,0) != foreground) ||
37  (iIm.getY() < im.getY()-1 && iIm(0,+1,0) != foreground) ||
38  (iIm.getZ() > 0 && iIm(0,0,-1) != foreground) ||
39  (iIm.getZ() < im.getZ()-1 && iIm(0,0,+1) != foreground))
40  {
41  borderPoint->push_back(iIm.pos());
42  }
43  }
44 
45  ++iIm;
46  }
47 
48  return borderPoint;
49 }
50 */
51 
52 
53 template < typename TImage >
54 void oneStepDilation(TImage &im,
55  typename TImage::value_type foreground,
56  typename TImage::value_type background)
57 {
58 
59  int xs = im.dim()[0];
60  int ys = im.dim()[1];
61  int zs = im.dim()[2];
62 
63  int xy = xs*ys;
64 
65  typename TImage::value_type color = findValueOtherThan(foreground, background);
66 
67  typename Iterator<TImage>::Volumetric iIm(im);
68 
69  for (; !iIm.isAtEnd(); ++iIm)
70  {
71  if (*iIm == background)
72  {
73  if (
74  // TODO: this has to change to, so that we don't have to write this sort of code
75  (containsNeighbor<-1, 0, 0>(iIm) && (iIm.template getUnsafeValue<-1,0,0>() == foreground)) ||
76  (containsNeighbor<+1, 0, 0>(iIm) && (iIm.template getUnsafeValue<+1,0,0>() == foreground)) ||
77  (containsNeighbor< 0,-1, 0>(iIm) && (iIm.template getUnsafeValue<0,-1,0>() == foreground)) ||
78  (containsNeighbor< 0,+1, 0>(iIm) && (iIm.template getUnsafeValue<0,+1,0>() == foreground)) ||
79  (containsNeighbor< 0, 0,-1>(iIm) && (iIm.template getUnsafeValue<0,0,-1>() == foreground)) ||
80  (containsNeighbor< 0, 0,+1>(iIm) && (iIm.template getUnsafeValue<0,0,+1>() == foreground)))
81  {
82  *iIm = color;
83  }
84  }
85  }
86 
87  //IF_THEN(im, im[n] == color, im[n] = foreground);
88  {
89  typename Iterator<TImage>::Linear iIm(im);
90  for (; !iIm.isAtEnd(); ++iIm)
91  {
92  if (*iIm == color) *iIm = foreground;
93  }
94  }
95 }
96 
97 
98 
99 template < typename TImage >
100 void diamondDilation(TImage &im, int nsteps,
101  typename TImage::value_type foreground,
102  typename TImage::value_type background)
103 {
104  for (int i = 0; i < nsteps; ++i)
105  oneStepDilation(im, foreground, background);
106 }
107 
108 
109 
110 template < typename TImage >
111 void diamondErosion(TImage &im, int nsteps,
112  typename TImage::value_type foreground,
113  typename TImage::value_type background)
114 {
115  for (int i = 0; i < nsteps; ++i)
116  oneStepDilation(im, background, foreground);
117 }
118 
119 
120 
121 template < typename TImage >
122 void diamondClosure(TImage &im,
123  int nsteps,
124  typename TImage::value_type foreground,
125  typename TImage::value_type background)
126 {
127  diamondDilation(im, nsteps, foreground, background);
128  diamondErosion(im, nsteps, foreground, background);
129 }
130 
131 } // namespace
132 
133 
134 #endif
135 
A trait class to assign iterators to image types.
Belongs to package Box Do not include directly, include til/Box.h instead.
Definition: Accumulator.h:10
void diamondErosion(TImage &im, int nsteps, typename TImage::value_type foreground, typename TImage::value_type background)
Definition: morpho.h:111
General macros, definitions and functions.
void diamondDilation(TImage &im, int nsteps, typename TImage::value_type foreground, typename TImage::value_type background)
Definition: morpho.h:100
bool containsNeighbor(const VolumetricImageIterator &iIm)
Definition: imageTools.h:665
void diamondClosure(TImage &im, int nsteps, typename TImage::value_type foreground, typename TImage::value_type background)
Definition: morpho.h:122
void oneStepDilation(TImage &im, typename TImage::value_type foreground, typename TImage::value_type background)
Definition: morpho.h:54
T findValueOtherThan(T v1, T v2)
Returns a number (a positive integer) with a different value than the input numbers.
Definition: miscTools.h:21