aimsalgo 6.0.0
Neuroimaging image processing
scaleLevel.h
Go to the documentation of this file.
1/* This software and supporting documentation are distributed by
2 * Institut Federatif de Recherche 49
3 * CEA/NeuroSpin, Batiment 145,
4 * 91191 Gif-sur-Yvette cedex
5 * France
6 *
7 * This software is governed by the CeCILL-B license under
8 * French law and abiding by the rules of distribution of free software.
9 * You can use, modify and/or redistribute the software under the
10 * terms of the CeCILL-B license as circulated by CEA, CNRS
11 * and INRIA at the following URL "http://www.cecill.info".
12 *
13 * As a counterpart to the access to the source code and rights to copy,
14 * modify and redistribute granted by the license, users are provided only
15 * with a limited warranty and the software's author, the holder of the
16 * economic rights, and the successive licensors have only limited
17 * liability.
18 *
19 * In this respect, the user's attention is drawn to the risks associated
20 * with loading, using, modifying and/or developing or reproducing the
21 * software by the user in light of its specific status of free software,
22 * that may mean that it is complicated to manipulate, and that also
23 * therefore means that it is reserved for developers and experienced
24 * professionals having in-depth computer knowledge. Users are therefore
25 * encouraged to load and test the software's suitability as regards their
26 * requirements in conditions enabling the security of their systems and/or
27 * data to be ensured and, more generally, to use and operate it in the
28 * same conditions as regards security.
29 *
30 * The fact that you are presently reading this means that you have had
31 * knowledge of the CeCILL-B license and that you accept its terms.
32 */
33
34
35#ifndef AIMS_PRIMALSKETCH_SCALELEVEL_H
36#define AIMS_PRIMALSKETCH_SCALELEVEL_H
37
38#include <cstdlib>
40#include <aims/texdata/texdata.h>
42#include <aims/mesh/surface.h>
43#include <aims/mesh/texture.h>
44#include <cartodata/volume/volume.h>
45#include <set>
46#include <map>
47#include <string>
48
49namespace aims
50{
51
52 // Scalelevel Is Templated With Respect To A Geometry And A Texture
53 // Same Mechanism Than Textureddata And Extractgreylevelblobs
54
55 // A Scale Level
56
57 template<typename Geom, typename Text> class ScaleLevel {
58
59 public:
60
61 typedef typename SiteType<Geom>::type Site;
62 typedef typename TexType<Text>::type Val;
63
64 ScaleLevel(float scale) { _scale=scale; }
65
67
68 float Scale() { return _scale; }
69 std::map<int, GreyLevelBlob<Site> *> BlobList() { return blobs; }
70 std::list<SaddlePoint<Site> *> SaddlePointList() { return saddlePoints; }
71 std::list<MaximumPoint<Site> *> MaximumPointList() { return maximumPoints; }
72
74 {
75 if (blobs.find(label) != blobs.end())
76 return blobs[label];
77 else
78 {
79 std::cerr << "looking for GLB that does not exist..." << std::endl;
80 exit(EXIT_FAILURE);
81 }
82 }
83
85
87 int nbBlobs() { return blobs.size(); }
88
90 {_scale=other._scale; blobs=other.blobs;
91 saddlePoints=other.saddlePoints; maximumPoints=other.maximumPoints; return *this;}
92
93 private:
94
95 float _scale;
96
97 std::map<int, GreyLevelBlob<Site> *> blobs;
98 std::list<SaddlePoint<Site> *> saddlePoints;
99 std::list<MaximumPoint<Site> *> maximumPoints;
100
101 };
102
103 // Scale Levels Image Partial Specialisation
104
105 template<typename T>
106 class ScaleLevel<carto::VolumeRef<T>, carto::VolumeRef<T> >
107 {
108
109 public:
110
112
113 ScaleLevel(float scale, carto::VolumeRef<T> level) { _scale=scale; _level = level.copy(); _originallevel=NULL; }
114
115 ScaleLevel(float scale, carto::VolumeRef<T> level, carto::VolumeRef<T> *originallevel)
116 { _scale=scale; _level = level.copy(); _originallevel=originallevel; }
117
119
120 carto::VolumeRef<T> & Level() { return _level; }
121
122
123 // Essai
126
127 float Scale() { return _scale; }
128 std::map<int, GreyLevelBlob<Site> *> BlobList() { return blobs; }
129 std::list<SaddlePoint<Site> *> SaddlePointList() { return saddlePoints; }
130 std::list<MaximumPoint<Site> *> MaximumPointList() { return maximumPoints; }
131
132 GreyLevelBlob<Site> *Blob(int label) {if (blobs.find(label) != blobs.end())
133 return blobs[label];
134 else
135 {std::cerr << "looking for GLB " << label << " that does not exist at scale " << _scale << std::endl;
136 exit(EXIT_FAILURE);}}
137
139 int nbBlobs() { return blobs.size(); }
140
142 {_scale=other._scale; _level=other._level; blobs=other.blobs;
143 saddlePoints=other.saddlePoints; maximumPoints=other.maximumPoints; return *this;}
144
145 void WriteBlobImage(std::string fileBlob);
146
147 private:
148
149 float _scale;
150 carto::VolumeRef<T> _level;
151 carto::VolumeRef<T> *_originallevel;
152 std::map<int, GreyLevelBlob<Site> *> blobs;
153 std::list<SaddlePoint<Site> *> saddlePoints;
154 std::list<MaximumPoint<Site> *> maximumPoints;
155 };
156
157 // Scale Levels Texture Partial Specialisation
158
159 template<int D, typename T> class ScaleLevel<AimsSurface<D, Void>, Texture<T> >
160 {
161
162 public:
163
165
166 ScaleLevel(float scale, Texture<T> level, AimsSurface<D, Void> *mesh)
167 {
168 _scale=scale; _level=level; _mesh=mesh; _coordinates=NULL; _originallevel=NULL;
169 }
170 ScaleLevel(float scale, Texture<T> level, AimsSurface<D, Void> *mesh, std::vector<Point3df> *coords)
171 {
172 _scale=scale; _level=level; _mesh=mesh; _coordinates=coords; _originallevel=NULL;
173 }
175 {
176 (*this)._scale=other._scale; (*this)._level=other._level; (*this)._mesh=other._mesh; (*this)._coordinates=_coordinates; _originallevel=NULL;
177 }
178 ScaleLevel(float scale, Texture<T> level, AimsSurface<D, Void> *mesh, Texture<T> *originallevel)
179 {
180 _scale=scale; _level=level; _mesh=mesh; _coordinates=NULL; _originallevel=originallevel;
181 }
182 ScaleLevel(float scale, Texture<T> level, AimsSurface<D, Void> *mesh, std::vector<Point3df> *coords, Texture<T> *originallevel)
183 {
184 _scale=scale; _level=level; _mesh=mesh; _coordinates=coords; _originallevel=originallevel;
185 }
187 {
188 (*this)._scale=other._scale; (*this)._level=other._level; (*this)._mesh=other._mesh; (*this)._coordinates=_coordinates; _originallevel=originallevel;
189 }
190
192
193
194 Texture<T> & Level() { return _level; }
197
198
199 float Scale() { return _scale; }
200 AimsSurface<D, Void> *Mesh() { return _mesh; }
201 std::map<int, GreyLevelBlob<Site> *> & BlobList() { return blobs; }
202 std::list<SaddlePoint<Site> *> & SaddlePointList()
203 { return saddlePoints; }
204 std::list<MaximumPoint<Site> *> & MaximumPointList()
205 { return maximumPoints; }
206
208 if (blobs.find(label) != blobs.end())
209 return blobs[label];
210 else
211 {
212 std::cerr << "looking for GLB " << label << " that does not exist..." << std::endl;
213 exit(EXIT_FAILURE);
214 }
215 }
216
218
219 int nbBlobs() { return blobs.size(); }
220 void PutCoordinates ( std::vector<Point3df> *coord ) { _coordinates = coord; }
221
222
225 {
226 (*this)._scale=other._scale;(*this)._level=other._level;(*this)._mesh=other._mesh; (*this).blobs=other.blobs;
227 (*this).saddlePoints=other.saddlePoints; (*this).maximumPoints=other.maximumPoints; return *this;
228 }
229
230 private:
231
232 float _scale;
233 Texture<T> _level;
234 Texture<T> *_originallevel;
236 std::vector<Point3df> *_coordinates;
237
238 std::map<int, GreyLevelBlob<Site> *> blobs;
239 std::list<SaddlePoint<Site> *> saddlePoints;
240 std::list<MaximumPoint<Site> *> maximumPoints;
241 };
242
243
244 //---------------- METHOD/FUNCTION DEFINITIONS ------------------------------
245
246 template<typename T>
248 {
250 TexturedData<carto::VolumeRef<T>, carto::VolumeRef<T> >rawtextdata(_originallevel) ;
251
252
253 ExtractGreyLevelBlobs<carto::VolumeRef<T>, carto::VolumeRef<T> > extractor(&textdata, &rawtextdata, mask, stats);
254
255 typename std::map<int, GreyLevelBlob<Site> *>::iterator itBlob;
256
257 //std::cout << "DEBUG: starting detection" << std::endl;
258 if (blobs.size() == 0)
259 {
260 extractor.Run();
261 //std::cout << "DEBUG: ran" << std::endl;
262 blobs = extractor.GetBlobs();
263 saddlePoints = extractor.GetSaddleList();
264 maximumPoints = extractor.GetMaxList();
265 //std::cout << "DEBUG: Got lists" << std::endl;
266 itBlob=blobs.begin();
267 for ( ; itBlob != blobs.end(); ++itBlob)
268 ((*itBlob).second)->SetScale(_scale);
269 //std::cout << "DEBUG: Set scales" << std::endl;
270 }
271 }
272
273 //-------------------------------------------------------------------
274
275 template<int D, typename T>
277 {
278
279 TexturedData<AimsSurface<D, Void>, Texture<T> > textdata(_mesh, &_level, _coordinates) ;
280 TexturedData<AimsSurface<D, Void>, Texture<T> > rawtextdata(_mesh, _originallevel, _coordinates) ;
281
282 ExtractGreyLevelBlobs<AimsSurface<D, Void>, Texture<T> > extractor(&textdata, &rawtextdata, mask, stats);
283
284 typename std::map<int, GreyLevelBlob<Site> *>::iterator itBlob;
285 if (blobs.size() == 0){
286 extractor.Run();
287 blobs=extractor.GetBlobs();
288 saddlePoints=extractor.GetSaddleList();
289 maximumPoints=extractor.GetMaxList();
290 itBlob=blobs.begin();
291 for ( ; itBlob != blobs.end(); ++itBlob)
292 ((*itBlob).second)->SetScale(_scale);
293 }
294
295 }
296
297 //-------------------------------------------------------------------
298
299 template<typename T>
301 {
302 int x,y,z;
303 int sx=_level.getSizeX(), sy=_level.getSizeY(), sz=_level.getSizeZ();
304 carto::VolumeRef<float> imaBlob(sx,sy,sz);
305 typename std::map<int, GreyLevelBlob<Site> *>::iterator itBlob=blobs.begin();;
306 typename std::list<SaddlePoint<Site> *>::iterator itSaddle=saddlePoints.begin();
307 typename std::list<MaximumPoint<Site> *>::iterator itMax=maximumPoints.begin();
308 typename std::set<Site,ltstr_p3d<Site> >::iterator itPoints;
309 GreyLevelBlob<Site> *blobby;
310
311 imaBlob.setVoxelSize( _level.getVoxelSize() );
312
313 for (z=0; z<sz; z++)
314 for (y=0; y<sy; y++)
315 for (x=0; x<sx; x++)
316 imaBlob(x,y,z)=0.0;
317
318 for (; itBlob!=blobs.end(); ++itBlob)
319 {
320 blobby=(*itBlob).second;
321 itPoints=blobby->GetListePoints().begin();
322 for (; itPoints!=blobby->GetListePoints().end(); ++itPoints)
323 {
324 x=int((*itPoints)[0]); y=int((*itPoints)[1]); z=int((*itPoints)[2]);
325 imaBlob(x,y,z)=255.0;
326 }
327 }
328
329 for (; itSaddle!=saddlePoints.end(); ++itSaddle)
330 {
331 x=int((*itSaddle)->_node[0]); y=int((*itSaddle)->_node[1]); z=int((*itSaddle)->_node[2]);
332 imaBlob(x,y,z)=128.0;
333 }
334
335 for (; itMax!=maximumPoints.end(); ++itMax)
336 {
337 x=int((*itMax)->_node[0]); y=int((*itMax)->_node[1]); z=int((*itMax)->_node[2]);
338 imaBlob(x,y,z)=128.0;
339 }
340 Writer<carto::VolumeRef<float> > dataW(fileBlob);
341 dataW.write(imaBlob);
342 }
343
344}
345
346#endif
Class that define grey-level blobs algorithm extraction.
std::list< SaddlePoint< Site > * > GetSaddleList()
std::map< int, GreyLevelBlob< Site > * > GetBlobs()
std::list< MaximumPoint< Site > * > GetMaxList()
Class for grey-level blobs Templated with respect to the type of points: TypeSite<carto::VolumeRef<T>...
std::set< T, ltstr_p3d< T > > & GetListePoints()
ScaleLevel(float scale, Texture< T > level, AimsSurface< D, Void > *mesh, std::vector< Point3df > *coords, Texture< T > *originallevel)
Definition scaleLevel.h:182
ScaleLevel(float scale, Texture< T > level, AimsSurface< D, Void > *mesh, Texture< T > *originallevel)
Definition scaleLevel.h:178
ScaleLevel(const ScaleLevel< AimsSurface< D, Void >, Texture< T > > &other, Texture< T > *originallevel)
Definition scaleLevel.h:186
TexturedData< AimsSurface< D, Void >, Texture< T > > OriginalData()
Definition scaleLevel.h:196
std::list< MaximumPoint< Site > * > & MaximumPointList()
Definition scaleLevel.h:204
std::map< int, GreyLevelBlob< Site > * > & BlobList()
Definition scaleLevel.h:201
void DetectBlobs(TexturedData< AimsSurface< D, Void >, Texture< T > > *mask=0, char *stats=0)
Definition scaleLevel.h:276
TexturedData< AimsSurface< D, Void >, Texture< T > > Data()
Definition scaleLevel.h:195
SiteType< AimsSurface< D, Void > >::type Site
Definition scaleLevel.h:164
ScaleLevel(float scale, Texture< T > level, AimsSurface< D, Void > *mesh, std::vector< Point3df > *coords)
Definition scaleLevel.h:170
void PutCoordinates(std::vector< Point3df > *coord)
Definition scaleLevel.h:220
ScaleLevel(const ScaleLevel< AimsSurface< D, Void >, Texture< T > > &other)
Definition scaleLevel.h:174
std::list< SaddlePoint< Site > * > & SaddlePointList()
Definition scaleLevel.h:202
ScaleLevel(float scale, Texture< T > level, AimsSurface< D, Void > *mesh)
Definition scaleLevel.h:166
TexturedData< carto::VolumeRef< T >, carto::VolumeRef< T > > Data()
Definition scaleLevel.h:124
void DetectBlobs(TexturedData< carto::VolumeRef< T >, carto::VolumeRef< T > > *mask=0, char *stats=0)
Definition scaleLevel.h:247
TexturedData< carto::VolumeRef< T >, carto::VolumeRef< T > > OriginalData()
Definition scaleLevel.h:125
ScaleLevel(float scale, carto::VolumeRef< T > level)
Definition scaleLevel.h:113
ScaleLevel(float scale, carto::VolumeRef< T > level, carto::VolumeRef< T > *originallevel)
Definition scaleLevel.h:115
std::map< int, GreyLevelBlob< Site > * > BlobList()
Definition scaleLevel.h:128
std::list< MaximumPoint< Site > * > MaximumPointList()
Definition scaleLevel.h:71
void DetectBlobs(TexturedData< Geom, Text > *mask, char *stats=0)
ScaleLevel< Geom, Text > & operator=(const ScaleLevel< Geom, Text > &other)
Definition scaleLevel.h:89
std::list< SaddlePoint< Site > * > SaddlePointList()
Definition scaleLevel.h:70
GreyLevelBlob< Site > * Blob(int label)
Definition scaleLevel.h:73
TexturedData< Geom, Text > Data()
Definition scaleLevel.h:84
std::map< int, GreyLevelBlob< Site > * > BlobList()
Definition scaleLevel.h:69
ScaleLevel(float scale)
Definition scaleLevel.h:64
TexType< Text >::type Val
Definition scaleLevel.h:62
SiteType< Geom >::type Site
Definition scaleLevel.h:61
virtual bool write(const T &obj, bool ascii=false, const std::string *format=0)
void setVoxelSize(float vx, float vy=1., float vz=1., float vt=1.)
VolumeRef< T > copy() const
BucketMap< Void > * mask(const BucketMap< Void > &src, const BucketMap< Void > &m, bool intersect=true)