1 #ifndef BIOPROCESSING_UTILITY_EXTREMAFINDER_H
2 #define BIOPROCESSING_UTILITY_EXTREMAFINDER_H
9 #include <aims/connectivity/structuring_element.h>
10 #include <aims/data/cartodatavolume.h>
11 #include <aims/bucket/bucketMap.h>
12 #include <aims/utility/progress.h>
14 #include <cartodata/volume/volume.h>
16 #include <cartobase/config/verbose.h>
17 #include <cartobase/smart/rcptr.h>
28 _strel( new
aims::strel::Sphere(1.0) ),
29 _connex( new
aims::strel::Connectivity26XYZ() ),
40 _strel.reset( se.clone() );
42 void setModeMin() { _modemin =
true; _modestrict =
false; }
43 void setModeMax() { _modemin =
false; _modestrict =
false; }
49 _connex.reset( c.clone() );
54 template <
typename IN,
typename OUT>
56 carto::VolumeRef<OUT> out );
57 template <
typename IN,
typename OUT,
typename M>
59 carto::VolumeRef<OUT> out,
60 carto::VolumeRef<M> mask );
61 template <
typename IN,
typename OUT>
63 aims::BucketMap<OUT> & out );
64 template <
typename IN,
typename OUT,
typename M>
66 aims::BucketMap<OUT> & out,
67 carto::VolumeRef<M> mask );
70 template <
typename IN,
typename OUT>
73 carto::VolumeRef<OUT> out( in.getSizeX(),
77 out->copyHeaderFrom( in.header() );
83 template <
typename IN,
typename OUT,
typename M >
85 carto::VolumeRef<IN> in,
86 carto::VolumeRef<M> mask )
88 carto::VolumeRef<OUT> out( in.getSizeX(),
92 out->copyHeaderFrom( in.header() );
98 template <
typename IN,
typename OUT>
101 aims::BucketMap<OUT> out;
102 std::vector<float> vs(4,1.);
103 if( in.header().hasProperty(
"voxel_size" ) )
104 in.header().getProperty(
"voxel_size", vs );
105 out.setSizeXYZT( vs[0], vs[1], vs[2], vs[3] );
110 template <
typename IN,
typename OUT,
typename M>
112 carto::VolumeRef<IN> in,
113 carto::VolumeRef<M> mask
114 = carto::VolumeRef<M>( (carto::Volume<M>*)0 ) )
116 aims::BucketMap<OUT> out;
117 std::vector<float> vs(4,1.);
118 if( in.header().hasProperty(
"voxel_size" ) )
119 in.header().getProperty(
"voxel_size", vs );
120 out.setSizeXYZT( vs[0], vs[1], vs[2], vs[3] );
126 template <
typename IN>
127 bool isExtremum( carto::VolumeRef<IN> in,
int x,
int y,
int z,
int t );
128 carto::rc_ptr<aims::StructuringElement> _strel;
129 carto::rc_ptr<aims::strel::Connectivity> _connex;
136 template <
typename IN>
137 bool ExtremaFinder::isExtremum( carto::VolumeRef<IN> in,
138 int x,
int y,
int z,
int t )
140 aims::StructuringElement::const_iterator p;
142 for( p = _strel->begin(); p != _strel->end(); ++p )
144 if( _modemin && _modestrict )
146 if( in( x, y, z, t ) >= in( x + (*p)[0], y + (*p)[1], z + (*p)[2], t ) )
149 else if( _modemin && !_modestrict )
151 if( in( x, y, z, t ) > in( x + (*p)[0], y + (*p)[1], z + (*p)[2], t ) )
154 else if( !_modemin && _modestrict )
156 if( in( x, y, z, t ) <= in( x + (*p)[0], y + (*p)[1], z + (*p)[2], t ) )
159 else if( !_modemin && !_modestrict )
161 if( in( x, y, z, t ) < in( x + (*p)[0], y + (*p)[1], z + (*p)[2], t ) )
169 template <
typename IN,
typename OUT>
171 carto::VolumeRef<OUT> out )
174 for( t=0; t<in.getSizeT(); ++t )
175 for( z=0; z<in.getSizeZ(); ++z )
176 for( y=0; y<in.getSizeY(); ++y )
177 for( x=0; x<in.getSizeX(); ++x )
178 if( isExtremum( in, x, y, z, t ) )
179 out( x, y, z, t ) = _value;
182 std::cout <<
"ExtremaFinder:: connected components mode not implemented yet." << std::endl;
185 template <
typename IN,
typename OUT,
typename M>
187 carto::VolumeRef<OUT> out,
188 carto::VolumeRef<M> mask )
191 for( t=0; t<in.getSizeT(); ++t )
192 for( z=0; z<in.getSizeZ(); ++z )
193 for( y=0; y<in.getSizeY(); ++y )
194 for( x=0; x<in.getSizeX(); ++x )
195 if( mask( x, y, z, t ) )
196 if( isExtremum( in, x, y, z, t ) )
197 out( x, y, z, t ) = _value;
200 std::cout <<
"ExtremaFinder:: connected components mode not implemented yet." << std::endl;
203 template <
typename IN,
typename OUT>
205 aims::BucketMap<OUT> & out )
209 double lmax = in.getSizeT();
210 lmax *= in.getSizeZ();
211 lmax *= in.getSizeY();
214 for( t=0; t<in.getSizeT(); ++t )
215 for( z=0; z<in.getSizeZ(); ++z )
216 for( y=0; y<in.getSizeY(); ++y )
217 for( x=0; x<in.getSizeX(); ++x )
218 if( isExtremum( in, x, y, z, t ) )
219 out.insert( Point3d(x,y,z), (OUT)_value );
222 std::cout <<
"ExtremaFinder:: connected components mode not implemented yet." << std::endl;
225 template <
typename IN,
typename OUT,
typename M>
227 aims::BucketMap<OUT> & out,
228 carto::VolumeRef<M> mask )
232 double lmax = in.getSizeT();
233 lmax *= in.getSizeZ();
234 lmax *= in.getSizeY();
237 for( t=0; t<in.getSizeT(); ++t )
238 for( z=0; z<in.getSizeZ(); ++z )
239 for( y=0; y<in.getSizeY(); ++y )
240 for( x=0; x<in.getSizeX(); ++x )
241 if( mask( x, y, z, t ) )
242 if( isExtremum( in, x, y, z, t ) )
243 out.insert( Point3d(x,y,z), (OUT)_value );
246 std::cout <<
"ExtremaFinder:: connected components mode not implemented yet." << std::endl;
void computeExtrema(carto::VolumeRef< IN > in, carto::VolumeRef< OUT > out)
aims::BucketMap< OUT > computeExtremaBucket(carto::VolumeRef< IN > in)
aims::BucketMap< OUT > computeExtremaBucket(carto::VolumeRef< IN > in, carto::VolumeRef< M > mask=carto::VolumeRef< M >((carto::Volume< M > *) 0))
carto::VolumeRef< OUT > computeExtremaVolume(carto::VolumeRef< IN > in)
void setStructuringElement(const aims::StructuringElement &se)
carto::VolumeRef< OUT > computeExtremaVolume(carto::VolumeRef< IN > in, carto::VolumeRef< M > mask)
void setModeValueConnectComp(const aims::strel::Connectivity &c)
void setModeValueConst(double value)