aimstil  5.0.5
imageTools.h
Go to the documentation of this file.
1 #ifndef TIL_IMAGETOOLS_H
2 #define TIL_IMAGETOOLS_H
3 
6 
7 // includes from STL
8 #include <limits>
9 #include <cmath>
10 #include <cstdlib> // rand
11 #include <typeinfo> // typeid
12 #include <vector>
13 
14 // includes from BOOST
15 #include "boost/utility/enable_if.hpp"
16 
17 // includes from TIL library
18 #include "til/til_common.h"
20 #include "til/image_common.h"
21 #include "til/labels.h"
22 #include "til/miscTools.h"
23 #include "til/numeric_array.h"
25 #include "til/Range.h"
26 #include "til/SymMatrix3.h"
27 
28 
29 // Namespace
30 namespace til
31 {
32 
33 
35 template < class TImage >
36 INLINE bool isAllocated(const TImage &im)
37 { return im.isAllocated(); }
38 
39 
41 template < class TImage >
42 INLINE void allocationCheck(const TImage &im)
43 {
44  if (!isAllocated(im))
45  {
46  throw std::invalid_argument("Unallocated image");
47  }
48 }
49 
53 template < class TImage1, class TImage2 >
54 INLINE void allocationCheck(const TImage1 &im1, const TImage2 &im2)
55 {
57 }
58 
59 template < class TImage1, class TImage2 >
60 INLINE bool areSimilar(const TImage1 &im1,
61  const TImage2 &im2)
62 {
63  return
64  (im1.dim()[0] == im2.dim()[0]) &&
65  (im1.dim()[1] == im2.dim()[1]) &&
66  (im1.dim()[2] == im2.dim()[2]) &&
67  (im1.vdim()[0] == im2.vdim()[0]) &&
68  (im1.vdim()[1] == im2.vdim()[1]) &&
69  (im1.vdim()[2] == im2.vdim()[2]);
70 }
71 
74 template < class TImage1, class TImage2 >
75 void similarityCheck(const TImage1 &im1,
76  const TImage2 &im2)
77 {
78  allocationCheck(im1);
79  allocationCheck(im2);
80 
81  if (!areSimilar(im1, im2))
82  {
83  throw std::invalid_argument("Incompatible images");
84  }
85 }
86 
87 
89 template < class TImage1, class TImage2 >
90 bool areSameObject(const TImage1 &, const TImage2 &)
91 { return false; }
92 
93 template < class TImage >
94 typename boost::enable_if<is_Image<TImage>, bool>::type
96 (
97  const TImage &im1,
98  const TImage &im2
99  )
100 { return im1==im2; }
101 
102 
103 template < class TImage1, class TImage2 >
104 typename boost::enable_if_c<
105  is_Image<TImage1>::value &&
106  is_Image<TImage2>::value
107 >::type
108 notSameImageCheck(const TImage1 &im1,
109  const TImage2 &im2)
110 {
111  allocationCheck(im1);
112  allocationCheck(im2);
113  if (areSameObject(im1, im2))
114  {
115  throw std::invalid_argument("Pointers point to the same image");
116  }
117 }
118 
119 
121 template < class TImage >
122 void printInfo(const TImage &im)
123 {
124  std::cout << "Image Type : " << typeid(typename TImage::value_type).name() << std::endl;
125  std::cout << "Image Size : " << im.dim()[0] <<" "<< im.dim()[1] <<" "<< im.dim()[2] << std::endl;
126  std::cout << "Image Voxel Size : " << im.vdim()[0] <<" "<< im.vdim()[1] <<" "<< im.vdim()[2] << std::endl;
127 }
128 
129 
130 
132 template < class TImage >
133 void copy(const TImage &in, TImage &out)
134 {
135  allocationCheck(in);
136  allocationCheck(out);
137  out.copy(in);
138 }
139 
140 
141 
149 template < typename TImage >
151 (
152  TImage &im,
153  double rx, double ry, double rz,
154  t_voxsize vx, t_voxsize vy, t_voxsize vz,
155  int sx, int sy, int sz,
156  typename TImage::value_type foreground,
157  typename TImage::value_type background
158 )
159 {
160 
161  if (rx <=0 || ry <= 0 || rz <= 0)
162  {
163  throw std::invalid_argument("Invalid radii");
164  }
165 
166  // Generate size if it is not provided
167  if (sx <= 0)
168  {
169  sx =2*(int)(ceil(2*rx))+1;
170  }
171  if (sy <= 0)
172  {
173  sy =2*(int)(ceil(2*ry))+1;
174  }
175  if (sz <= 0)
176  {
177  sz =2*(int)(ceil(2*rz))+1;
178  }
179 
180  im.init(numeric_array<int,3>(sx, sy, sz), numeric_array<float,3>(vx, vy, vz));
181 
182 
183  // Center coordinates
184 
185  double cx = (sx-1.0)/2;
186  double cy = (sy-1.0)/2;
187  double cz = (sz-1.0)/2;
188 
189  int i, j, k;
190  for (k = 0; k < im.dim()[2]; ++k)
191  {
192  for (j = 0; j < im.dim()[1]; ++j)
193  {
194  for (i = 0; i < im.dim()[0]; ++i)
195  {
196  im(numeric_array<int,3>(i,j,k)) =
197  square(i-cx) / square(rx) +
198  square(j-cy) / square(ry) +
199  square(k-cz) / square(rz) <= 1?
200  foreground : background;
201  }
202  }
203  }
204 }
205 
206 
207 
208 
215 template < typename TImage >
216 void generateGaussianImage(TImage &im,
218  typename TImage::value_type amplitude,
221 {
222  typedef typename TImage::value_type value_type;
223 
224  const double SIGMA_MIN = 0.0; // 1e-3;
225 
226  if (sigma[0] < SIGMA_MIN || sigma[1] < SIGMA_MIN || sigma[2] < SIGMA_MIN)
227  {
228  throw std::invalid_argument("Standard deviation is too small");
229  }
230 
231  // Generate size if it is not provided
232 
233  if (size[0] <= 0)
234  {
235  size[0] = 2*max(1,castValue<double, int>(3.0*ceil((double)sigma[0]))) + 1;
236  }
237  if (size[1] <= 0)
238  {
239  size[1] = 2*max(1,castValue<double, int>(3.0*ceil((double)sigma[1]))) + 1;
240  }
241  if (size[2] <= 0)
242  {
243  size[2] = 2*max(1,castValue<double, int>(3.0*ceil((double)sigma[2]))) + 1;
244  }
245 
246  im.init(size, voxSize);
247 
248 
249  // Center coordinates
250  // For a 3x3 image I want the center at (1,1)
251  // For a 2x2 image I want the center at (0.5, 0.5)
252  // Hence the '-1'
253 
254  //numeric_array<double,3> center(size-1);
256  convert(center, (size-1));
257  center *= 0.5;
258 
259  int i, j, k;
260  for (k = 0; k < im.dim()[2]; ++k)
261  {
262  for (j = 0; j < im.dim()[1]; ++j)
263  {
264  for (i = 0; i < im.dim()[0]; ++i)
265  {
266  im(numeric_array<int,3>(i,j,k)) = value_type( amplitude * exp(-
267  square(i-center[0]) / (2*square(sigma[0])) -
268  square(j-center[1]) / (2*square(sigma[1])) -
269  square(k-center[2]) / (2*square(sigma[2]))));
270  }
271  }
272  }
273 }
274 
275 
276 
277 template < typename TImage >
278 void generateGaussianKernel(TImage &kernel,
279  double sigmaX, double sigmaY, double sigmaZ,
280  t_voxsize vx, t_voxsize vy, t_voxsize vz,
281  int sx, int sy, int sz)
282 {
283  generateGaussianImage(kernel, numeric_array<double,3>(sigmaX, sigmaY, sigmaZ),
284  1.0, numeric_array<t_voxsize,3>(vx, vy, vz), numeric_array<int,3>(sx, sy, sz));
285 
286  setSumToOne(kernel);
287 }
288 
289 
290 
291 template <typename T1, typename TImage2>
292 void deduceImageSizeFromGaussianStandardDeviation(T1 sigma, const TImage2 &im, int &hx, int &hy, int &hz)
293 {
294  T1 sigmaX, sigmaY, sigmaZ;
295 
296  sigmaX = modifySigmaAccordingToVoxelSize(sigma, im.vdim()[0], im.vdim()[1], im.vdim()[2], 0);
297  sigmaY = modifySigmaAccordingToVoxelSize(sigma, im.vdim()[0], im.vdim()[1], im.vdim()[2], 1);
298  sigmaZ = modifySigmaAccordingToVoxelSize(sigma, im.vdim()[0], im.vdim()[1], im.vdim()[2], 2);
299 
300  hx = castValue<double, int>(3.0*ceil(sigmaX));
301  hy = castValue<double, int>(3.0*ceil(sigmaY));
302  hz = castValue<double, int>(3.0*ceil(sigmaZ));
303 }
304 
305 
306 
307 template < typename TImage >
308 void getLocalHessian(const TImage &im, SymMatrix3<typename TImage::value_type> &mat, int x, int y, int z)
309 {
310  if (!contains(getRange(im),
311  Range<int,3>(numeric_array<int, 3>(x-1, y-1, z-1),
312  numeric_array<int, 3>(x+1, y+1, z+1))))
313  {
314  throw std::invalid_argument("Point is outside image or on image border");
315  }
316 
317  mat.set(0,0, (im.getUnsafeValue(x+1,y,z) + im.getUnsafeValue(x-1,y,z) - 2*im.getUnsafeValue(x,y,z)) / square(im.vdim()[0]));
318  mat.set(1,1, (im.getUnsafeValue(x,y+1,z) + im.getUnsafeValue(x,y-1,z) - 2*im.getUnsafeValue(x,y,z)) / square(im.vdim()[1]));
319  mat.set(2,2, (im.getUnsafeValue(x,y,z+1) + im.getUnsafeValue(x,y,z-1) - 2*im.getUnsafeValue(x,y,z)) / square(im.vdim()[2]));
320 
321  mat.set(0,1, (im.getUnsafeValue(x+1,y+1,z) + im.getUnsafeValue(x-1,y-1,z) - im.getUnsafeValue(x+1,y-1,z) - im.getUnsafeValue(x-1,y+1,z)) / ( im.vdim()[0] * im.vdim()[1] ));
322  mat.set(0,2, (im.getUnsafeValue(x+1,y,z+1) + im.getUnsafeValue(x-1,y,z-1) - im.getUnsafeValue(x+1,y,z-1) - im.getUnsafeValue(x-1,y,z+1)) / ( im.vdim()[0] * im.vdim()[2] ));
323  mat.set(1,2, (im.getUnsafeValue(x,y+1,z+1) + im.getUnsafeValue(z,y-1,z-1) - im.getUnsafeValue(x,y+1,z-1) - im.getUnsafeValue(x,y-1,z+1)) / ( im.vdim()[1] * im.vdim()[2] ));
324 }
325 
326 
328 template < typename TImage >
329 inline numeric_array<int,3> getCenter(TImage &im)
330 {
331  return im.dim() / 2;
332  //return numeric_array<int,3>(div<Point<int,3> >(im.dim(),2));// / 2);
333  /*im.dim()[0] / 2,
334  im.dim()[1] / 2,
335  im.dim()[2] / 2);*/
336 }
337 
339 template < typename TImage >
340 void getImageCenter(const TImage &im, int &cx, int &cy, int &cz)
341 {
342  if (!(im.dim()[0]%2 && im.dim()[1]%2 && im.dim()[2]%2))
343  {
344  throw std::invalid_argument("Even image size");
345  }
346 
347  cx = im.dim()[0] / 2;
348  cy = im.dim()[1] / 2;
349  cz = im.dim()[2] / 2;
350 }
351 
352 
353 
354 /*
356 template < typename TImage >
357 INLINE
358 typename boost::enable_if<is_Image<TImage>, bool>::type
359 contains(const TImage &im, int i, int j, int k)
360 {
361  return (i >= 0 && j >= 0 && k >= 0 &&
362  i < im.dim()[0] &&
363  j < im.dim()[1] &&
364  k < im.dim()[2]);
365 }
366 */
367 
369 template < typename TImage >
370 INLINE
371 typename boost::enable_if<is_Image<TImage>, bool>::type
372 contains(const TImage & im, const numeric_array<int,3> & pos)
373 {
374  return all_greater_equal(pos, 0) && all_less(pos, im.dim());
375 }
376 
377 
383 template < typename TImage >
384 INLINE
385 bool contains(const TImage & im, const numeric_array<int,3> & pos, const numeric_array<int,3> & offset)
386 {
387  /*
388  // NB: this code did not make any difference in term of speed. This kind
389  // of optimizations seems to be carried out well by the compiler.
390  int temp;
391  return
392  (
393  ( offset.getX() == 0 || ((temp = pos.getX() + offset.getX()) >= 0 && temp < im.dim()[0])) &&
394  ( offset.getY() == 0 || ((temp = pos.getY() + offset.getY()) >= 0 && temp < im.dim()[1])) &&
395  ( offset.getZ() == 0 || ((temp = pos.getZ() + offset.getZ()) >= 0 && temp < im.dim()[2]))
396  );*/
397 
398  return
399  (
400  ( offset[0] == 0 || (pos[0] + offset[0] >= 0 && pos[0] + offset[0] < im.dim()[0])) &&
401  ( offset[1] == 0 || (pos[1] + offset[1] >= 0 && pos[1] + offset[1] < im.dim()[1])) &&
402  ( offset[2] == 0 || (pos[2] + offset[2] >= 0 && pos[2] + offset[2] < im.dim()[2]))
403  );
404 }
405 
407 template < typename TImage >
408 Range<int,3> getRange(const TImage &im)
409 {
410  return Range<int,3>(im.dim() - 1);
411 }
412 
413 
415 template < typename TImage >
416 Box<double,3> getBoundingBox(const TImage &im)
417 {
418  return Box<double,3>(numeric_array<double,3>(-0.5,-0.5,-0.5), im.dim() - 0.5);
419 }
420 
421 
422 
425 // TODO: these functions are so simple, they just simply shoudn't exist. Use loop.
426 /*
427 template < typename TImage >
428 void extractBar(const TImage &im, int x, int y, int z, ImageAxis axis, std::vector<typename TImage::value_type> &bar)
429 {
430  typename Iterator<TImage>::ConstVolumetric iIm(im);
431  typename std::vector<typename TImage::value_type>::iterator iBar = bar.begin();
432  for (iIm.setPos(x,y,z); iBar != bar.end(); iIm.next(axis), ++iBar)
433  {
434  *iBar = *iIm;
435  }
436 }*/
437 template < typename TImage >
438 void extractBar(const TImage &im, const numeric_array<int,3> & pos, ImageAxis axis, std::vector<typename TImage::value_type> &bar)
439 {
440  typename Iterator<TImage>::ConstVolumetric iIm(im);
441  typename std::vector<typename TImage::value_type>::iterator iBar = bar.begin();
442  for (iIm.set_pos(pos); iBar != bar.end(); iIm.next(axis), ++iBar)
443  {
444  *iBar = *iIm;
445  }
446 }
447 
448 
449 
452 /*
453 template < typename TImage >
454 void insertBar(TImage &im, int x, int y, int z, ImageAxis axis, const std::vector<typename TImage::value_type> &bar)
455 {
456  typename Iterator<TImage>::Volumetric iIm(im);
457  typename std::vector<typename TImage::value_type>::const_iterator iBar = bar.begin();
458  for (iIm.setPos(x,y,z); iBar != bar.end(); iIm.next(axis), ++iBar)
459  {
460  *iIm = *iBar;
461  }
462 }
463 */
464 template < typename TImage >
465 void insertBar(TImage &im, const numeric_array<int,3> & pos, ImageAxis axis, const std::vector<typename TImage::value_type> &bar)
466 {
467  typename Iterator<TImage>::Volumetric iIm(im);
468  typename std::vector<typename TImage::value_type>::const_iterator iBar = bar.begin();
469  for (iIm.set_pos(pos); iBar != bar.end(); iIm.next(axis), ++iBar)
470  {
471  *iIm = *iBar;
472  }
473 }
474 
475 /*
476 template < typename TImage >
477 Ptr<TImage> similarAs(Ptr<TImage> &im)
478 {
479  Ptr<TImage> res = new TImage(param(im));
480  return res;
481 }
482 */
483 
484 
486 // TODO: clearly the kind of thing that should be easily done in a few lines
487 // without using a function: how?
488 template < typename TImage >
489 void setSumToOne(TImage &im)
490 {
491  typedef typename TImage::value_type value_type;
492 
493  if (std::numeric_limits<value_type>::is_integer)
494  {
495  throw std::domain_error("Defined for floating numbers only");
496  }
497 
498  value_type nrm = sum(im);
499 
500  const value_type EPSILON = 128 * std::numeric_limits<value_type>::epsilon();
501 
502  if (std::abs(nrm) <= EPSILON)
503  {
504  throw std::underflow_error("kernel norm too small");
505  }
506 
507  mul(im, value_type(1.0/nrm));
508 }
509 
510 
511 
513 template < typename T >
514 T** simple2DoublePointer(T *data, int x, int y, int z)
515 {
516  if ( x<0 || y<0 || z<0)
517  {
518  throw std::invalid_argument("Image size < 0");
519  }
520 
521  T** res = new T*[z];
522 
523  for (int i=0; i < z; ++i)
524  {
525  res[i] = data + i * x * y;
526  }
527 
528  return res;
529 }
530 
531 
532 template < typename TImage >
534 itlin(TImage &im)
535 {
536  return typename Iterator<TImage>::Linear(im);
537 }
538 // NB: BoolFunctor is the first template parameter so that it can be given
539 // explicitely without having to give also the image type
540 template < typename BoolFunctor, typename TImage >
542 itlin(TImage &im, const BoolFunctor &boolFunctor = BoolFunctor())
543 {
544  return ConditionalIterator<typename Iterator<TImage>::Linear, BoolFunctor>(im, boolFunctor);
545 }
546 
547 template < typename TImage >
549 itlin_const(const TImage &im)
550 {
551  return typename Iterator<TImage>::ConstLinear(im);
552 }
553 
554 template < typename BoolFunctor, typename TImage >
556 itlin_const(const TImage &im, const BoolFunctor &boolFunctor = BoolFunctor())
557 {
558  return ConditionalIterator<typename Iterator<TImage>::ConstLinear, BoolFunctor>(im, boolFunctor);
559 }
560 
561 template < typename TImage >
563 itvol(TImage &im)
564 {
565  return typename Iterator<TImage>::Volumetric(im);
566 }
567 
568 template < typename BoolFunctor, typename TImage >
570 itvol(TImage &im, const BoolFunctor &boolFunctor = BoolFunctor())
571 {
572  return ConditionalIterator<typename Iterator<TImage>::Volumetric, BoolFunctor>(im, boolFunctor);
573 }
574 
575 template < typename TImage >
577 itvol_const(const TImage &im)
578 {
579  return typename Iterator<TImage>::ConstVolumetric(im);
580 }
581 
582 template < typename BoolFunctor, typename TImage >
584 itvol_const(const TImage &im, const BoolFunctor &boolFunctor = BoolFunctor())
585 {
586  return ConditionalIterator<typename Iterator<TImage>::ConstVolumetric, BoolFunctor>(im, boolFunctor);
587 }
588 
589 
592 template < typename TImage >
593 void rand
594 (
595  TImage & im,
596  typename TImage::value_type min,
597  typename TImage::value_type max
598 )
599 {
600  //typedef typename TImage::value_type value_type;
601 
602  // Checking whether max < min
603  if (max < min)
604  {
605  warning("til::rand: input max < min, setting max := min");
606  max = min;
607  }
608 
609  typename Iterator<TImage>::Linear iIm(im);
610  for (; !iIm.isAtEnd(); ++iIm)
611  {
612  *iIm = rand(min, max);
613  }
614 }
615 
617 // TODO: clearly a task that should be easy to do in a few lines without
618 // having to write a function: how?
619 template < typename TImage >
620 void setSlice(TImage &im,
621  int sliceNumber,
622  ImageAxis axis,
623  typename TImage::value_type value
624  )
625 {
626  Range<int,3> range = getRange(im);
627  // collapse range on current axis
628  range.set_bounds(axis, sliceNumber, sliceNumber);
629 
630  typename Iterator<TImage>::Volumetric iIm(im, range);
631  for (; !iIm.isAtEnd(); ++iIm)
632  {
633  *iIm = value;
634  }
635 }
636 
637 
639 template < typename TImage >
640 void clearBorder
641 (
642  TImage &im,
643  typename TImage::value_type background = 0
644 )
645 {
646  typename Iterator<TImage>::Volumetric iIm(im);
647 
648  for (; !iIm.isAtEnd(); ++iIm)
649  {
650  if (
651  (iIm.pos()[0] == 0) ||
652  (iIm.pos()[1] == 0) ||
653  (iIm.pos()[2] == 0) ||
654  (iIm.pos()[0] == im.dim()[0] - 1) ||
655  (iIm.pos()[1] == im.dim()[1] - 1) ||
656  (iIm.pos()[2] == im.dim()[2] - 1))
657  {
658  *iIm = background;
659  }
660  }
661 }
662 
663 
664 template <int dx, int dy, int dz, class VolumetricImageIterator>
665 bool containsNeighbor(const VolumetricImageIterator & iIm)
666 {
667  return (
668  (dx >= 0 || iIm.pos()[0] > 1+dx) &&
669  (dx <= 0 || iIm.pos()[0] < iIm.image().dim()[0]-dx) &&
670 
671  (dy >= 0 || iIm.pos()[1] > 1+dy) &&
672  (dy <= 0 || iIm.pos()[1] < iIm.image().dim()[1]-dy) &&
673 
674  (dz >= 0 || iIm.pos()[2] > 1+dz) &&
675  (dz <= 0 || iIm.pos()[2] < iIm.image().dim()[2]-dz));
676 }
677 
679 template < typename TImage, typename T >
680 INLINE
681 typename boost::enable_if< is_Image<TImage>, numeric_array<double,3> >::type
682 vol2world(const TImage & im, const numeric_array<T,3> & volumePos)
683 {
684  //return (volumePos - im.getOrigin()) * im.getVDim();
685  //return volumePos * im.vdim();
686  return mul<numeric_array<double,3> >(volumePos, im.vdim());
687 }
688 
689 template < typename TImage >
690 INLINE
691 typename boost::enable_if< is_Image<TImage>, numeric_array<double,3> >::type
692 world2vol(const TImage & im, const numeric_array<double,3> & worldPos)
693 {
694  // En fait c'est pas si idiot que ca de passer par le data, parce que ca nous
695  // indique qu'effectivement on fait qqch de non-standard, et c'est vrai:
696  // c'est une approx rapide de l'application d'une matrice que l'on fait.
697  return div<numeric_array<double,3> >(worldPos, im.vdim());
698  //return worldPos / im.vdim();// + im.getOrigin();
699 }
700 
701 
702 } // namespace
703 
704 #endif
705 
A trait class to assign iterators to image types.
void setSlice(TImage &im, int sliceNumber, ImageAxis axis, typename TImage::value_type value)
Set a value to an image slice.
Definition: imageTools.h:620
void convert(TTo &x, const TFrom &y)
Definition: functors.h:410
boost::enable_if_c< is_Image< TImage1 >::value &&is_Image< TImage2 >::value >::type notSameImageCheck(const TImage1 &im1, const TImage2 &im2)
Definition: imageTools.h:108
boost::enable_if< is_Image< TImage >, typename TImage::value_type >::type min(const TImage &im)
Iterator< TImage >::ConstLinear itlin_const(const TImage &im)
Definition: imageTools.h:549
void set_bounds(const numeric_array< T, D > &minBounds, const numeric_array< T, D > &maxBounds)
Set min and max bounds.
Definition: Box.h:87
void similarityCheck(const TImage1 &im1, const TImage2 &im2)
Check whether both images are allocated and have the same size and voxel size.
Definition: imageTools.h:75
void getImageCenter(const TImage &im, int &cx, int &cy, int &cz)
Get coordinates of image center.
Definition: imageTools.h:340
void getLocalHessian(const TImage &im, SymMatrix3< typename TImage::value_type > &mat, int x, int y, int z)
Definition: imageTools.h:308
A class to store a 3*3 symetric matrix.
Definition: SymMatrix3.h:23
void clearBorder(TImage &im, typename TImage::value_type background=0)
Clear image borders.
Definition: imageTools.h:641
Belongs to package Box Do not include directly, include til/Box.h instead.
Definition: Accumulator.h:10
numeric_array< int, 3 > getCenter(TImage &im)
Get coordinates of image center.
Definition: imageTools.h:329
void printInfo(ConstVolumetricIterator< ImageNC< T > > &it)
void set(const std::pair< std::size_t, std::size_t > &i, T value)
Set a value to the matrix.
Definition: SymMatrix3.h:67
numeric_array< T, D > size(const Box< T, D > &box)
Return the size of a box.
Definition: boxTools.h:56
General macros, definitions and functions.
void deduceImageSizeFromGaussianStandardDeviation(T1 sigma, const TImage2 &im, int &hx, int &hy, int &hz)
Definition: imageTools.h:292
Iterator< TImage >::Volumetric itvol(TImage &im)
Definition: imageTools.h:563
Conditional iterator for images.
Defines empty classes that serves as labels.
void generateEllipsoidImage(TImage &im, double rx, double ry, double rz, t_voxsize vx, t_voxsize vy, t_voxsize vz, int sx, int sy, int sz, typename TImage::value_type foreground, typename TImage::value_type background)
Creates an image with an ellipsoid centered on the image center.
Definition: imageTools.h:151
void extractBar(const TImage &im, const numeric_array< int, 3 > &pos, ImageAxis axis, std::vector< typename TImage::value_type > &bar)
Extract the line starting from (x,y,z) in the direction of axis from im to bar.
Definition: imageTools.h:438
ImageAxis
Definition: miscTools.h:123
void rand(TImage &im, typename TImage::value_type min, typename TImage::value_type max)
Fills the image with random numbers uniformly distributed on [min, max].
Definition: imageTools.h:594
numeric_array< T, D > abs(const numeric_array< T, D > &a)
Absolute value, element-wise.
void generateGaussianImage(TImage &im, numeric_array< double, 3 > sigma, typename TImage::value_type amplitude, numeric_array< t_voxsize, 3 > voxSize, numeric_array< int, 3 > size)
Creates an image with a Gaussian around image center.
Definition: imageTools.h:216
bool containsNeighbor(const VolumetricImageIterator &iIm)
Definition: imageTools.h:665
INLINE void allocationCheck(const TImage &im)
Check whether smart pointer and image are allocated.
Definition: imageTools.h:42
INLINE boost::enable_if< is_Image< TImage >, numeric_array< double, 3 > >::type vol2world(const TImage &im, const numeric_array< T, 3 > &volumePos)
Get the world coordinates of an image point.
Definition: imageTools.h:682
t_bsprec sum(const TImage &im)
Computes the sum of the intensities of the input image.
#define INLINE
Definition: til_common.h:26
void warning(const char *msg)
Library warning.
Definition: til_common.h:79
TImage::value_type max(const TImage &im)
Returns the maximum intensity of the input image.
void copy(const TImage &in, TImage &out)
Copy one image to another.
Definition: imageTools.h:133
INLINE bool isAllocated(const TImage &im)
Check whether smart pointer and image are allocated.
Definition: imageTools.h:36
bool areSameObject(const TImage1 &, const TImage2 &)
Check that inputs do not point to the same image.
Definition: imageTools.h:90
boost::enable_if< is_numeric_container< TStorage >, bool >::type contains(const Box< T, D > &box, const TStorage &v)
Check whether a point lies within box.
Definition: boxTools.h:15
Iterator< TImage >::ConstVolumetric itvol_const(const TImage &im)
Definition: imageTools.h:577
Range< int, 3 > getRange(const TImage &im)
Get image range.
Definition: imageTools.h:408
void setSumToOne(TImage &im)
Normalize the image so that the sum of its element is equal to one.
Definition: imageTools.h:489
T modifySigmaAccordingToVoxelSize(T sigma, const numeric_array< float, 3 > &vdim, ImageAxis axis)
INLINE bool areSimilar(const TImage1 &im1, const TImage2 &im2)
Definition: imageTools.h:60
void insertBar(TImage &im, const numeric_array< int, 3 > &pos, ImageAxis axis, const std::vector< typename TImage::value_type > &bar)
Insert the line starting from (x,y,z) in the direction of axis from bar to im.
Definition: imageTools.h:465
Box< double, 3 > getBoundingBox(const TImage &im)
Get image bounding box.
Definition: imageTools.h:416
TRes mul(T1 x, T2 y)
Definition: functors.h:402
A 3D box parallel to canonical axes.
Definition: Box.h:25
INLINE boost::enable_if< is_Image< TImage >, numeric_array< double, 3 > >::type world2vol(const TImage &im, const numeric_array< double, 3 > &worldPos)
Definition: imageTools.h:692
T ** simple2DoublePointer(T *data, int x, int y, int z)
Converts a contiguous memory buffer into a per-slice buffer.
Definition: imageTools.h:514
void square(const TImage &in, TImage &out)
Definition: imageArith.h:310
float t_voxsize
type of voxel size
Definition: ImageBase.h:13
void generateGaussianKernel(TImage &kernel, double sigmaX, double sigmaY, double sigmaZ, t_voxsize vx, t_voxsize vy, t_voxsize vz, int sx, int sy, int sz)
Definition: imageTools.h:278
Iterator< TImage >::Linear itlin(TImage &im)
Definition: imageTools.h:534