HashImage.h
1 /*
2  * Medical Image Registration ToolKit (MIRTK)
3  *
4  * Copyright 2013-2015 Antonios Makropoulos
5  * Copyright 2017 Andreas Schuh
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 
20 #ifndef MIRTK_HashImage_H
21 #define MIRTK_HashImage_H
22 
23 #include "mirtk/BaseImage.h"
24 #include "mirtk/VoxelCast.h"
25 #include "mirtk/UnorderedMap.h"
26 
27 namespace mirtk {
28 
29 
30 /**
31  * Hash class for N-D images
32  *
33  * This class implements N-D images based on hashmaps. It provides functions
34  * for accessing, reading, writing and manipulating images. This class can
35  * be used for images with arbitrary voxel types using templates.
36  */
37 
38 template <class TVoxel>
39 class HashImage : public BaseImage
40 {
41  mirtkObjectMacro(HashImage);
42 
43  // ---------------------------------------------------------------------------
44  // Types
45 
46 public:
47 
48  /// Voxel type
49  typedef TVoxel VoxelType;
50 
51  /// Floating point type corresponding to voxel type
52  /// \note The VoxelType as well as the RealType may be a matrix/vector type!
53  typedef typename voxel_info<VoxelType>::RealType RealType;
54 
55  /// Data map (hashmap)
56  typedef UnorderedMap<int, VoxelType> DataMap;
57 
58  /// Data map iterator
59  typedef typename DataMap::const_iterator DataIterator;
60 
61  /// Scalar type corresponding to voxel type
62  typedef typename voxel_info<VoxelType>::ScalarType ScalarType;
63 
64  // ---------------------------------------------------------------------------
65  // Data members
66 
67 protected:
68 
69  /// Pointer array for access to image data
70  ///
71  /// \note The image data is stored in a hash map
72  mirtkPublicAttributeMacro(DataMap, Data);
73 
74  /// \note Voxels that their value==DefaultValue are not stored
75  mirtkPublicAttributeMacro(VoxelType, DefaultValue);
76 
77  // ---------------------------------------------------------------------------
78  // Construction/Destruction
79 
80  /// Allocate image memory
81  void AllocateImage();
82 
83  /// Function for not const pixel get access
84  VoxelType Access(int);
85 
86 public:
87 
88  /// Default constructor
89  HashImage();
90 
91  /// Constructor from image file
92  HashImage(const char *);
93 
94  /// Constructor for given image size
95  explicit HashImage(int, int, int = 1, int = 1);
96 
97  /// Constructor for given image size
98  explicit HashImage(int, int, int, int, int);
99 
100  /// Constructor for given image attributes
101  explicit HashImage(const ImageAttributes &, int = -1);
102 
103  /// Copy constructor for image
104  explicit HashImage(const BaseImage &);
105 
106  /// Copy constructor for image
108 
109  /// Copy constructor for image of different type
110  template <class TVoxel2>
112 
113  /// Copy constructor for image of different type
114  template <class TVoxel2>
115  HashImage(const HashImage<TVoxel2> &);
116 
117  /// Destructor
118  ~HashImage();
119 
120  // ---------------------------------------------------------------------------
121  // Initialization
122 
123  /// Create copy of this image
124  virtual BaseImage *Copy() const;
125 
126  /// Initialize a previously allocated image
127  virtual void Initialize();
128 
129  /// Initialize an image
130  virtual void Initialize(const ImageAttributes &, int = -1);
131 
132  /// Initialize an image
133  void Initialize(int, int, int, int, int);
134 
135  /// Initialize an image
136  void Initialize(int, int, int = 1, int = 1);
137 
138  /// Copy image data from other image of same size
139  void CopyFrom(const BaseImage &);
140 
141  /// Copy image data from other image of same size
142  template <class TVoxel2>
143  void CopyFrom(const GenericImage<TVoxel2> &);
144 
145  /// Copy image data from other image of same size
146  template <class TVoxel2>
147  void CopyFrom(const HashImage<TVoxel2> &);
148 
149  /// Copy image data to GenericImage
150  template <class TVoxel2>
151  void CopyTo(GenericImage<TVoxel2> &) const;
152 
153  /// Assign constant value to each voxel
154  HashImage& operator= (VoxelType);
155 
156  /// Assignment operator with implicit cast to double and then VoxelType
158 
159  /// Assignment operator with implicit cast to double and then VoxelType
160  template <class TVoxel2>
162 
163  /// Assignment operator
165 
166  /// Assignment operator with implicit cast
167  template <class TVoxel2>
169 
170  /// Clear an image
171  void Clear();
172 
173  // ---------------------------------------------------------------------------
174  // Lattice
175 
176  /// Number of vector components per voxel
177  int N() const;
178 
179  /// Function to convert pixel to index
180  /// more efficient than overwritten base class implementation
181  int VoxelToIndex(int, int, int = 0, int = 0) const;
182 
183  // ---------------------------------------------------------------------------
184  // Image data access
185 
186  DataIterator Begin() const;
187  DataIterator End() const;
188 
189  int NumberOfNonDefaultVoxels() const;
190 
191  /// Function for pixel get access
192  VoxelType Get(int) const;
193 
194  /// Function for pixel get access
195  VoxelType Get(int, int, int = 0, int = 0) const;
196 
197  /// Function for pixel put access
198  void Put(int, VoxelType);
199 
200  /// Function for pixel put access
201  void Put(int, int, VoxelType);
202 
203  /// Function for pixel put access
204  void Put(int, int, int, VoxelType);
205 
206  /// Function for pixel put access
207  void Put(int, int, int, int, VoxelType);
208  // ---------------------------------------------------------------------------
209  // Type independent access to scalar image data
210 
211  /// Function for pixel get access as double
212  virtual double GetAsDouble(int) const;
213 
214  /// Function for pixel get access as double
215  virtual double GetAsDouble(int, int, int = 0, int = 0) const;
216 
217  /// Function for pixel put access
218  virtual void PutAsDouble(int, double);
219 
220  /// Function for pixel put access
221  virtual void PutAsDouble(int, int, double);
222 
223  /// Function for pixel put access
224  virtual void PutAsDouble(int, int, int, double);
225 
226  /// Function for pixel put access
227  virtual void PutAsDouble(int, int, int, int, double);
228 
229  /// Function for pixel get access as double
230  virtual void GetAsVector(Vector &, int) const;
231 
232  /// Function for pixel get access as double
233  virtual void GetAsVector(Vector &, int, int, int = 0, int = 0) const;
234 
235  /// Function for pixel get access as double
236  virtual Vector GetAsVector(int) const;
237 
238  /// Function for pixel get access as double
239  virtual Vector GetAsVector(int, int, int = 0, int = 0) const;
240 
241  /// Function for pixel put access
242  virtual void PutAsVector(int, const Vector &);
243 
244  /// Function for pixel put access
245  virtual void PutAsVector(int, int, const Vector &);
246 
247  /// Function for pixel put access
248  virtual void PutAsVector(int, int, int, const Vector &);
249 
250  /// Function for pixel put access
251  virtual void PutAsVector(int, int, int, int, const Vector &);
252 
253  // ---------------------------------------------------------------------------
254  // Access to raw image data
255 
256  /// Get raw pointer to contiguous image data
257  virtual void *GetDataPointer(int = 0);
258 
259  /// Get raw pointer to contiguous image data
260  virtual const void *GetDataPointer(int = 0) const;
261 
262  /// Get raw pointer to contiguous image data
263  virtual void *GetDataPointer(int, int, int = 0, int = 0);
264 
265  /// Get raw pointer to contiguous image data
266  virtual const void *GetDataPointer(int, int, int = 0, int = 0) const;
267 
268  /// Get enumeration value corresponding to voxel type
269  virtual int GetDataType() const;
270 
271  /// Get size of each voxel in bytes
272  virtual int GetDataTypeSize() const;
273 
274  /// Minimum value a pixel can hold without overflowing
275  virtual double GetDataTypeMin() const;
276 
277  /// Maximum value a pixel can hold without overflowing
278  virtual double GetDataTypeMax() const;
279 
280  // ---------------------------------------------------------------------------
281  // Region-of-interest extraction
282 
283  /// Get image consisting of specified 2D slice
284  HashImage GetRegion(int, int) const;
285 
286  /// Get image consisting of specified 2D slice
287  void GetRegion(HashImage &, int, int) const;
288 
289  /// Get image consisting of specified 2D slice
290  virtual void GetRegion(BaseImage *&, int, int) const;
291 
292  /// Get image consisting of specified 3D subregion
293  HashImage GetRegion(int, int, int,
294  int, int, int) const;
295 
296  /// Get image consisting of specified 3D subregion
297  void GetRegion(HashImage &, int, int, int,
298  int, int, int) const;
299 
300  /// Get image consisting of specified 3D subregion
301  virtual void GetRegion(BaseImage *&, int, int, int,
302  int, int, int) const;
303 
304  /// Get image consisting of specified 4D subregion
305  HashImage GetRegion(int, int, int, int,
306  int, int, int, int) const;
307 
308  /// Get image consisting of specified 4D subregion
309  void GetRegion(HashImage &, int, int, int, int,
310  int, int, int, int) const;
311 
312  /// Get image consisting of specified 4D subregion
313  virtual void GetRegion(BaseImage *&, int, int, int, int,
314  int, int, int, int) const;
315 
316  /// Get time instance (i.e., frame) or channel of image
317  HashImage GetFrame(int, int = -1) const;
318 
319  /// Get time instance (i.e., frame) or channel of image
320  void GetFrame(HashImage &, int, int = -1) const;
321 
322  /// Get time instance (i.e., frame) or channel of image
323  virtual void GetFrame(BaseImage *&, int, int = -1) const;
324 
325  // ---------------------------------------------------------------------------
326  // Image arithmetic
327  HashImage& operator+=(ScalarType); ///< Add scalar
328  HashImage& operator-=(ScalarType); ///< Subtract scalar
329  HashImage& operator*=(ScalarType); ///< Multiply by scalar
330  HashImage& operator/=(ScalarType); ///< Divide by scalar
331 
332  /// Equality operator
333  /// \note Use explicit negation for inequality comparison.
334  /// The overloaded != operator is used for binarization of the image.
335  template <class TVoxel2>
336  bool operator== (const HashImage<TVoxel2> &) const;
337 
338  HashImage& operator+=(const HashImage &); ///< Add image
339  HashImage& operator-=(const HashImage &); ///< Subtract image
340  HashImage& operator*=(const HashImage &); ///< Multipy voxels
341  HashImage& operator/=(const HashImage &); ///< Divide voxels
342 
343 
344  HashImage operator+ (const HashImage &) const; ///< Add images
345  HashImage operator- (const HashImage &) const; ///< Subtract images
346  HashImage operator* (const HashImage &) const; ///< Multiply images voxel-wise
347  HashImage operator/ (const HashImage &) const; ///< Divide images voxel-wise
348 
349  HashImage operator+ (ScalarType) const; ///< Add scalar to image
350  HashImage operator- (ScalarType) const; ///< Subtract scalar from image
351  HashImage operator* (ScalarType) const; ///< Multiply image by scalar
352  HashImage operator/ (ScalarType) const; ///< Divide image by scalar
353 
354  // ---------------------------------------------------------------------------
355  // Thresholding
356 
357  // Import other overload
359 
360  /// Put background value
361  virtual void PutBackgroundValueAsDouble(double, bool);
362 
363  // ---------------------------------------------------------------------------
364  // Common image statistics
365 
366  /// Minimum and maximum pixel values get accessor
367  void GetMinMax(VoxelType &, VoxelType &) const;
368 
369  /// Minimum and maximum pixel values get accessor with padding
370  void GetMinMax(VoxelType &, VoxelType &, VoxelType) const;
371 
372  /// Linearly rescale intensities
373  void PutMinMax(VoxelType, VoxelType);
374 
375  // ---------------------------------------------------------------------------
376  // Common image manipulations
377 
378  virtual void ReflectX(bool modify_axes = false); ///< Reflect image along x
379  virtual void ReflectY(bool modify_axes = false); ///< Reflect image along y
380  virtual void ReflectZ(bool modify_axes = false); ///< Reflect image along z
381  virtual void ReflectT(bool modify_axes = false); ///< Reflect image along t
382 
383  virtual void FlipXY(bool modify_origin = false); ///< Flip x and y axis, always also swaps voxel size
384  virtual void FlipXZ(bool modify_origin = false); ///< Flip x and z axis, always also swaps voxel size
385  virtual void FlipYZ(bool modify_origin = false); ///< Flip y and z axis, always also swaps voxel size
386  virtual void FlipXT(bool modify_origin = false); ///< Flip x and t axis, always also swaps voxel size
387  virtual void FlipYT(bool modify_origin = false); ///< Flip y and t axis, always also swaps voxel size
388  virtual void FlipZT(bool modify_origin = false); ///< Flip z and t axis, always also swaps voxel size
389 
390  virtual void SwapXY(bool modify_axes = true); ///< Swap x and y axis
391  virtual void SwapXZ(bool modify_axes = true); ///< Swap x and z axis
392  virtual void SwapYZ(bool modify_axes = true); ///< Swap y and z axis
393  virtual void SwapXT(bool modify_axes = true); ///< Swap x and t axis
394  virtual void SwapYT(bool modify_axes = true); ///< Swap y and t axis
395  virtual void SwapZT(bool modify_axes = true); ///< Swap z and t axis
396 
397  //bool CropPad(int margin = 0); ///< Crop/pad image background
398 
399  // ---------------------------------------------------------------------------
400  // VTK interface
401  #if defined(HAVE_VTK) && MIRTK_Image_WITH_VTK
402 
403  /// Convert image to VTK structured points
404  ///
405  /// \note Use only when MIRTK_Image_WITH_VTK is 1.
406  virtual void ImageToVTK(vtkStructuredPoints *) const;
407 
408  /// Convert VTK structured points to image
409  ///
410  /// \note Use only when MIRTK_Image_WITH_VTK is 1.
411  virtual void VTKToImage(vtkStructuredPoints *);
412 
413  #endif // MIRTK_Image_WITH_VTK
414 
415  // ---------------------------------------------------------------------------
416  // I/O
417 
418  /// Read image from file
419  virtual void Read(const char *);
420 
421  /// Write image to file
422  virtual void Write(const char *) const;
423 
424 
425  // ---------------------------------------------------------------------------
426  // Convertors
427  GenericImage<VoxelType> ToGenericImage() const;
428 
429  template <class TVoxel2>
430  void ToGenericImage(GenericImage<TVoxel2>& image) const;
431 
432  // ---------------------------------------------------------------------------
433  // Deprecated
434 
435  /// Minimum and maximum pixel values get accessor
436  /// \deprecated Use respective overloaded method of GetMinMax instead.
437  void GetMinMax(VoxelType *, VoxelType *) const;
438 
439  /// Minimum and maximum pixel values get accessor with padding
440  /// \deprecated Use respective overloaded method of GetMinMax instead.
441  void GetMinMax(VoxelType *, VoxelType *, VoxelType) const;
442 
443  /// Minimum and maximum pixel values get accessor with padding
444  /// \deprecated Use respective overloaded method of GetMinMax instead.
445  void GetMinMaxPad(VoxelType *, VoxelType *, VoxelType) const;
446 
447 };
448 
449 ////////////////////////////////////////////////////////////////////////////////
450 // Inline definitions
451 ////////////////////////////////////////////////////////////////////////////////
452 
453 // =============================================================================
454 // Initialization
455 // =============================================================================
456 
457 // -----------------------------------------------------------------------------
458 
459 // =============================================================================
460 // Lattice
461 // =============================================================================
462 
463 // -----------------------------------------------------------------------------
464 template <class VoxelType>
465 inline int HashImage<VoxelType>::N() const
466 {
467  return voxel_info<VoxelType>::vector_size();
468 }
469 
470 // -----------------------------------------------------------------------------
471 template <class VoxelType>
472 inline int HashImage<VoxelType>::VoxelToIndex(int x, int y, int z, int t) const
473 {
474  return x + y*_attr._x + z*_attr._x*_attr._y + t*_attr._x*_attr._y*_attr._z;
475 }
476 
477 // =============================================================================
478 // Image data access
479 // =============================================================================
480 
481 // -----------------------------------------------------------------------------
482 template <class VoxelType>
483 inline void HashImage<VoxelType>::Put(int index, VoxelType val)
484 {
485  if(index>=0){
486  if(val==_DefaultValue){
487  _Data.erase(index);
488  }else{
489  _Data[index]=val;
490  }
491  }
492 }
493 
494 // -----------------------------------------------------------------------------
495 template <class VoxelType>
496 inline void HashImage<VoxelType>::Put(int x, int y, VoxelType val)
497 {
498  Put(x,y,0,0,val);
499 }
500 
501 // -----------------------------------------------------------------------------
502 template <class VoxelType>
503 inline void HashImage<VoxelType>::Put(int x, int y, int z, VoxelType val)
504 {
505  Put(x,y,z,0,val);
506 }
507 
508 // -----------------------------------------------------------------------------
509 template <class VoxelType>
510 inline void HashImage<VoxelType>::Put(int x, int y, int z, int t, VoxelType val)
511 {
512  Put(VoxelToIndex(x, y, z, t) ,val);
513 }
514 
515 // -----------------------------------------------------------------------------
516 template <class VoxelType>
518 {
519  cerr << "HashImage::Access: Not implemented" << endl;
520  exit(1);
521 }
522 
523 // -----------------------------------------------------------------------------
524 
525 template <class VoxelType>
527 {
528  return _Data.begin();
529 }
530 
531 // -----------------------------------------------------------------------------
532 
533 template <class VoxelType>
535 {
536  return _Data.end();
537 }
538 
539 // -----------------------------------------------------------------------------
540 
541 template <class VoxelType>
543 {
544  return _Data.size();
545 }
546 
547 // -----------------------------------------------------------------------------
548 
549 template <class VoxelType>
550 inline VoxelType HashImage<VoxelType>::Get(int index) const
551 {
552  auto pos=_Data.find (index);
553  if ( pos == End() ) return _DefaultValue;
554  return voxel_cast<VoxelType>(pos->second);
555 }
556 
557 // -----------------------------------------------------------------------------
558 template <class VoxelType>
559 inline VoxelType HashImage<VoxelType>::Get(int x, int y, int z, int t) const
560 {
561  return Get(VoxelToIndex(x, y, z, t));
562 }
563 
564 // =============================================================================
565 // Type independent access to scalar image data
566 // =============================================================================
567 
568 // -----------------------------------------------------------------------------
569 template <class VoxelType>
570 inline void HashImage<VoxelType>::PutAsDouble(int index, double val)
571 {
572  Put(index, voxel_cast<VoxelType>(val));
573 }
574 
575 // -----------------------------------------------------------------------------
576 template <class VoxelType>
577 inline void HashImage<VoxelType>::PutAsDouble(int x, int y, double val)
578 {
579  Put(VoxelToIndex(x, y, 0, 0), voxel_cast<VoxelType>(val));
580 }
581 
582 // -----------------------------------------------------------------------------
583 template <class VoxelType>
584 inline void HashImage<VoxelType>::PutAsDouble(int x, int y, int z, double val)
585 {
586  Put(VoxelToIndex(x, y, z, 0), voxel_cast<VoxelType>(val));
587 }
588 
589 // -----------------------------------------------------------------------------
590 template <class VoxelType>
591 inline void HashImage<VoxelType>::PutAsDouble(int x, int y, int z, int t, double val)
592 {
593  Put(VoxelToIndex(x, y, z, t), voxel_cast<VoxelType>(val));
594 }
595 
596 // -----------------------------------------------------------------------------
597 template <class VoxelType>
598 inline double HashImage<VoxelType>::GetAsDouble(int index) const
599 {
600  return voxel_cast<double>(Get(index));
601 }
602 
603 // -----------------------------------------------------------------------------
604 template <class VoxelType>
605 inline double HashImage<VoxelType>::GetAsDouble(int x, int y, int z, int t) const
606 {
607  return voxel_cast<double>(Get(VoxelToIndex(x, y, z, t)));
608 }
609 
610 // -----------------------------------------------------------------------------
611 template <class VoxelType>
612 inline void HashImage<VoxelType>::PutAsVector(int index, const Vector &value)
613 {
614  Put(index, voxel_cast<VoxelType>(value));
615 }
616 
617 // -----------------------------------------------------------------------------
618 template <class VoxelType>
619 inline void HashImage<VoxelType>::PutAsVector(int x, int y, const Vector &value)
620 {
621  Put(VoxelToIndex(x, y, 0, 0), voxel_cast<VoxelType>(value));
622 }
623 
624 // -----------------------------------------------------------------------------
625 template <class VoxelType>
626 inline void HashImage<VoxelType>::PutAsVector(int x, int y, int z, const Vector &value)
627 {
628  Put(VoxelToIndex(x, y, z, 0), voxel_cast<VoxelType>(value));
629 }
630 
631 // -----------------------------------------------------------------------------
632 template <class VoxelType>
633 inline void HashImage<VoxelType>::PutAsVector(int x, int y, int z, int t, const Vector &value)
634 {
635  Put(VoxelToIndex(x, y, z, t), voxel_cast<VoxelType>(value));
636 }
637 
638 // -----------------------------------------------------------------------------
639 template <class VoxelType>
640 inline void HashImage<VoxelType>::GetAsVector(Vector &value, int index) const
641 {
642  value = voxel_cast<Vector>(Get(index));
643 }
644 
645 // -----------------------------------------------------------------------------
646 template <class VoxelType>
647 inline void HashImage<VoxelType>::GetAsVector(Vector &value, int x, int y, int z, int t) const
648 {
649  value = voxel_cast<Vector>(Get(VoxelToIndex(x, y, z, t)));
650 }
651 
652 // -----------------------------------------------------------------------------
653 template <class VoxelType>
655 {
656  return voxel_cast<Vector>(Get(index));
657 }
658 
659 // -----------------------------------------------------------------------------
660 template <class VoxelType>
661 inline Vector HashImage<VoxelType>::GetAsVector(int x, int y, int z, int t) const
662 {
663  return voxel_cast<Vector>(Get(VoxelToIndex(x, y, z, t)));
664 }
665 
666 // =============================================================================
667 // Access to raw image data
668 // =============================================================================
669 
670 // -----------------------------------------------------------------------------
671 
672 // -----------------------------------------------------------------------------
673 template <class VoxelType>
675 {
676  cerr << "HashImage<VoxelType>::GetDataPointer: Not implemented" << endl;
677  exit(1);
678 }
679 
680 // -----------------------------------------------------------------------------
681 template <class VoxelType>
682 inline const void *HashImage<VoxelType>::GetDataPointer(int i) const
683 {
684  cerr << "HashImage<VoxelType>::GetDataPointer: Not implemented" << endl;
685  exit(1);
686 }
687 
688 // -----------------------------------------------------------------------------
689 template <class VoxelType>
690 inline void *HashImage<VoxelType>::GetDataPointer(int x, int y, int z, int t)
691 {
692  cerr << "HashImage<VoxelType>::GetDataPointer: Not implemented" << endl;
693  exit(1);
694 }
695 
696 // -----------------------------------------------------------------------------
697 template <class VoxelType>
698 inline const void *HashImage<VoxelType>::GetDataPointer(int x, int y, int z, int t) const
699 {
700  cerr << "HashImage<VoxelType>::GetDataPointer: Not implemented" << endl;
701  exit(1);
702 }
703 
704 // -----------------------------------------------------------------------------
705 template <class VoxelType>
707 {
708  return voxel_info<VoxelType>::type();
709 }
710 
711 // -----------------------------------------------------------------------------
712 template <class VoxelType>
714 {
715  return static_cast<int>(sizeof(VoxelType));
716 }
717 
718 // -----------------------------------------------------------------------------
719 template <class VoxelType>
721 {
722  return voxel_limits<VoxelType>::min();
723 }
724 
725 // -----------------------------------------------------------------------------
726 template <class VoxelType>
728 {
729  return voxel_limits<VoxelType>::max();
730 }
731 
732 // =============================================================================
733 // Deprecated
734 // =============================================================================
735 
736 // -----------------------------------------------------------------------------
737 template <class VoxelType>
739 {
740  this->GetMinMax(*min, *max);
741 }
742 
743 // -----------------------------------------------------------------------------
744 template <class VoxelType>
746 {
747  this->GetMinMax(*min, *max, pad);
748 }
749 
750 // -----------------------------------------------------------------------------
751 template <class VoxelType>
753 {
754  this->GetMinMax(*min, *max, pad);
755 }
756 ////////////////////////////////////////////////////////////////////////////////
757 // Common specializations
758 ////////////////////////////////////////////////////////////////////////////////
759 
763 
764 } // namespace mirtk
765 
766 #include "mirtk/HashImage.hxx"
767 
768 #endif // MIRTK_HashImage_H
virtual int GetDataTypeSize() const
Get size of each voxel in bytes.
Definition: HashImage.h:713
HashImage & operator/=(ScalarType)
Divide by scalar.
Definition: HashImage.hxx:808
virtual void * GetDataPointer(int=0)
Get raw pointer to contiguous image data.
Definition: HashImage.h:674
int VoxelToIndex(int, int, int=0, int=0) const
Definition: HashImage.h:472
virtual void ReflectZ(bool modify_axes=false)
Reflect image along z.
Definition: HashImage.hxx:1074
void PutBackgroundValueAsDouble(double)
Put background value.
Definition: BaseImage.h:1394
virtual void SwapYT(bool modify_axes=true)
Swap y and t axis.
Definition: HashImage.hxx:1185
void CopyFrom(const BaseImage &)
Copy image data from other image of same size.
Definition: HashImage.hxx:238
~HashImage()
Destructor.
Definition: HashImage.hxx:164
virtual double GetAsDouble(int) const
Function for pixel get access as double.
Definition: HashImage.h:598
void Put(int, VoxelType)
Function for pixel put access.
Definition: HashImage.h:483
voxel_info< VoxelType >::ScalarType ScalarType
Scalar type corresponding to voxel type.
Definition: HashImage.h:62
virtual void FlipYT(bool modify_origin=false)
Flip y and t axis, always also swaps voxel size.
Definition: HashImage.hxx:1142
HashImage operator+(const HashImage &) const
Add images.
Definition: HashImage.hxx:826
HashImage operator*(const HashImage &) const
Multiply images voxel-wise.
Definition: HashImage.hxx:844
virtual int GetDataType() const
Get enumeration value corresponding to voxel type.
Definition: HashImage.h:706
void PutMinMax(VoxelType, VoxelType)
Linearly rescale intensities.
Definition: HashImage.hxx:1000
virtual void FlipZT(bool modify_origin=false)
Flip z and t axis, always also swaps voxel size.
Definition: HashImage.hxx:1149
int _y
Image y-dimension (in voxels)
void Clear()
Clear an image.
Definition: HashImage.hxx:171
HashImage GetFrame(int, int=-1) const
Get time instance (i.e., frame) or channel of image.
Definition: HashImage.hxx:648
virtual void ReflectX(bool modify_axes=false)
Reflect image along x.
Definition: HashImage.hxx:1032
voxel_info< VoxelType >::RealType RealType
Definition: HashImage.h:53
HashImage & operator*=(ScalarType)
Multiply by scalar.
Definition: HashImage.hxx:791
virtual void SwapYZ(bool modify_axes=true)
Swap y and z axis.
Definition: HashImage.hxx:1171
virtual void FlipXY(bool modify_origin=false)
Flip x and y axis, always also swaps voxel size.
Definition: HashImage.hxx:1114
virtual void SwapXT(bool modify_axes=true)
Swap x and t axis.
Definition: HashImage.hxx:1178
HashImage operator/(const HashImage &) const
Divide images voxel-wise.
Definition: HashImage.hxx:853
ImageAttributes _attr
Image attributes.
Definition: BaseImage.h:99
HashImage()
Default constructor.
Definition: HashImage.hxx:70
void AllocateImage()
Allocate image memory.
Definition: HashImage.hxx:59
VoxelType Get(int) const
Function for pixel get access.
Definition: HashImage.h:550
void GetMinMax(VoxelType &, VoxelType &) const
Minimum and maximum pixel values get accessor.
Definition: HashImage.hxx:949
void GetMinMaxPad(VoxelType *, VoxelType *, VoxelType) const
Definition: HashImage.h:752
virtual double GetDataTypeMin() const
Minimum value a pixel can hold without overflowing.
Definition: HashImage.h:720
virtual void SwapXZ(bool modify_axes=true)
Swap x and z axis.
Definition: HashImage.hxx:1164
Definition: IOConfig.h:41
UnorderedMap< int, VoxelType > DataMap
Data map (hashmap)
Definition: HashImage.h:56
virtual void FlipXT(bool modify_origin=false)
Flip x and t axis, always also swaps voxel size.
Definition: HashImage.hxx:1135
int _z
Image z-dimension (in voxels)
HashImage & operator-=(ScalarType)
Subtract scalar.
Definition: HashImage.hxx:778
virtual void PutAsDouble(int, double)
Function for pixel put access.
Definition: HashImage.h:570
virtual void Read(const char *)
Read image from file.
Definition: HashImage.hxx:1247
virtual void ReflectY(bool modify_axes=false)
Reflect image along y.
Definition: HashImage.hxx:1053
int N() const
Number of vector components per voxel.
Definition: HashImage.h:465
virtual double GetDataTypeMax() const
Maximum value a pixel can hold without overflowing.
Definition: HashImage.h:727
virtual void FlipXZ(bool modify_origin=false)
Flip x and z axis, always also swaps voxel size.
Definition: HashImage.hxx:1121
HashImage GetRegion(int, int) const
Get image consisting of specified 2D slice.
Definition: HashImage.hxx:441
virtual void FlipYZ(bool modify_origin=false)
Flip y and z axis, always also swaps voxel size.
Definition: HashImage.hxx:1128
bool operator==(const HashImage< TVoxel2 > &) const
double VoxelType
Definition: BaseImage.h:770
mirtkPublicAttributeMacro(DataMap, Data)
DataMap::const_iterator DataIterator
Data map iterator.
Definition: HashImage.h:59
HashImage & operator+=(ScalarType)
Add scalar.
Definition: HashImage.hxx:765
VoxelType Access(int)
Function for not const pixel get access.
Definition: HashImage.h:517
void CopyTo(GenericImage< TVoxel2 > &) const
Copy image data to GenericImage.
virtual void ReflectT(bool modify_axes=false)
Reflect image along t.
Definition: HashImage.hxx:1095
virtual void PutBackgroundValueAsDouble(double, bool)
Put background value.
Definition: HashImage.hxx:902
virtual void PutAsVector(int, const Vector &)
Function for pixel put access.
Definition: HashImage.h:612
virtual void Initialize()
Initialize a previously allocated image.
Definition: HashImage.hxx:191
virtual void SwapZT(bool modify_axes=true)
Swap z and t axis.
Definition: HashImage.hxx:1192
HashImage & operator=(VoxelType)
Assign constant value to each voxel.
Definition: HashImage.hxx:324
virtual void SwapXY(bool modify_axes=true)
Swap x and y axis.
Definition: HashImage.hxx:1157
int _x
Image x-dimension (in voxels)
HashImage operator-(const HashImage &) const
Subtract images.
Definition: HashImage.hxx:835
TVoxel VoxelType
Voxel type.
Definition: HashImage.h:49
virtual void Write(const char *) const
Write image to file.
Definition: HashImage.hxx:1267
virtual void GetAsVector(Vector &, int) const
Function for pixel get access as double.
Definition: HashImage.h:640
virtual BaseImage * Copy() const
Create copy of this image.
Definition: HashImage.hxx:185