BaseImage.h
1 /*
2  * Medical Image Registration ToolKit (MIRTK)
3  *
4  * Copyright 2008-2017 Imperial College London
5  * Copyright 2008-2013 Daniel Rueckert, Julia Schnabel
6  * Copyright 2013-2017 Andreas Schuh
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 
21 #ifndef MIRTK_BaseImage_H
22 #define MIRTK_BaseImage_H
23 
24 #include "mirtk/Object.h"
25 #include "mirtk/Voxel.h"
26 #include "mirtk/Point.h"
27 #include "mirtk/PointSet.h"
28 #include "mirtk/Vector.h"
29 #include "mirtk/Vector3.h"
30 #include "mirtk/Matrix.h"
31 #include "mirtk/ImageAttributes.h"
32 
33 
34 // When VTK support is enabled during the build of the Image module,
35 // the vtable of the image classes contains additional entries compared to
36 // a build without VTK! Therefore, MIRTK_Image_WITH_VTK must reflect whether
37 // the interface includes those VTK support functions or not.
38 #include "mirtk/ImageConfig.h"
39 #if MIRTK_Image_WITH_VTK
40 class vtkStructuredPoints;
41 #endif // MIRTK_Image_WITH_VTK
42 
43 
44 namespace mirtk {
45 
46 
47 ////////////////////////////////////////////////////////////////////////////////
48 // Forward declaration of used specialized image types
49 ////////////////////////////////////////////////////////////////////////////////
50 
51 // Forward declaration of generic image type
52 template <class VoxelType> class GenericImage;
53 
54 /// Binary image as used for masks (0: off, otherwise: on)
56 
57 /// FIXME: Use double3 as voxel type instead
59 
60 ////////////////////////////////////////////////////////////////////////////////
61 // Definition of base image class
62 ////////////////////////////////////////////////////////////////////////////////
63 
64 /**
65  * Abstract generic class for 2D or 3D images
66  *
67  * This abstract base class provides generic support for 2D and 3D image
68  * classes. It provides functions for accessing image dimension and origin
69  * as well as voxel dimensions. It also provides functions for conversion
70  * between image and world coordinates.
71  */
72 class BaseImage : public Object
73 {
74  mirtkAbstractMacro(BaseImage);
75 
76  // ---------------------------------------------------------------------------
77  // Types
78 
79 public:
80 
81  /// Orientation codes (same as defined in nifti1_io.h, e.g., NIFTI_L2R)
83  {
84  Orientation_Unknown = 0,
85  L2R = 1, ///< Left to Right
86  R2L = 2, ///< Right to Left
87  P2A = 3, ///< Posterior to Anterior
88  A2P = 4, ///< Anterior to Posterior
89  I2S = 5, ///< Inferior to Superior
90  S2I = 6 ///< Superior to Inferior
91  };
92 
93  // ---------------------------------------------------------------------------
94  // Attributes
95 
96 protected:
97 
98  /// Image attributes
100 
101  /// Total number of voxels
103 
104  /// Transformation matrix from image coordinates to (transformed) world coordinates
106 
107  /// Transformation matrix from (transformed) world coordinates to image coordinates
109 
110  /// Foreground mask
111  BinaryImage *_mask;
112 
113  /// Whether this image owns the mask image
114  ///
115  /// Set to a value above 1 when mask was generated by InitializeMask,
116  /// in which case the mask will be deleted by the n-th ClearMask call,
117  /// where n is the number of preceeding (nested) InitializeMask calls.
118  /// A value of 1 denotes a mask image set by the owner which this image
119  /// should delete upon destruction.
121 
122  /// Background value - may also be NaN for floating point images
123  double _bg;
124 
125  /// Whether a background value was set
126  bool _bgSet;
127 
128  // ---------------------------------------------------------------------------
129  // Construction/Destruction
130 
131  /// Default constructor
132  BaseImage();
133 
134  /// Constructor
135  BaseImage(const ImageAttributes &, int = -1);
136 
137  /// Copy constructor
138  BaseImage(const BaseImage &);
139 
140 public:
141 
142  /// Destructor
143  virtual ~BaseImage();
144 
145  // ---------------------------------------------------------------------------
146  // Initialization
147 
148  /// Read file and construct image
149  static BaseImage *New(const char *);
150 
151  /// Construct image copy of same type
152  static BaseImage *New(const BaseImage *);
153 
154  /// Construct image with given voxel type
155  static BaseImage *New(int);
156 
157  /// Create copy of this image
158  virtual BaseImage *Copy() const;
159 
160 protected:
161 
162  /// Update coordinate transformation
163  void UpdateMatrix();
164 
165  /// Puts attributes of image
166  void PutAttributes(const ImageAttributes &);
167 
168 public:
169 
170  /// Initialize image
171  virtual void Initialize(const ImageAttributes &, int = -1) = 0;
172 
173  /// Assignment operator
174  BaseImage &operator =(const BaseImage &);
175 
176  /// Clear image
177  virtual void Clear() = 0;
178 
179  // ---------------------------------------------------------------------------
180  // Lattice
181 
182  /// Gets the image attributes
183  const ImageAttributes &Attributes() const;
184 
185  /// Returns the total number of voxels
186  int NumberOfVoxels() const;
187 
188  /// Returns the total number of spatial voxels
189  int NumberOfSpatialVoxels() const;
190 
191  /// Returns the number of voxels in the x-direction
192  int X() const;
193 
194  /// Returns the number of voxels in the y-direction
195  int Y() const;
196 
197  /// Returns the number of voxels in the z-direction
198  int Z() const;
199 
200  /// Returns the number of voxels in the t-direction
201  int T() const;
202 
203  /// Returns the number of vector components (i.e., 1 for scalar images)
204  virtual int N() const;
205 
206  /// Returns the number of voxels in the x-direction
207  int GetX() const;
208 
209  /// Returns the number of voxels in the y-direction
210  int GetY() const;
211 
212  /// Returns the number of voxels in the z-direction
213  int GetZ() const;
214 
215  /// Returns the number of voxels in the t-direction
216  int GetT() const;
217 
218  /// Returns the size of a voxel in the x-direction
219  double XSize() const;
220 
221  /// Returns the size of a voxel in the y-direction
222  double YSize() const;
223 
224  /// Returns the size of a voxel in the z-direction
225  double ZSize() const;
226 
227  /// Returns the size of a voxel in the t-direction
228  double TSize() const;
229 
230  /// Returns the size of a voxel in the x-direction
231  double GetXSize() const;
232 
233  /// Returns the size of a voxel in the y-direction
234  double GetYSize() const;
235 
236  /// Returns the size of a voxel in the z-direction
237  double GetZSize() const;
238 
239  /// Returns the size of a voxel in the t-direction
240  double GetTSize() const;
241 
242  /// Set temporal voxel size, i.e., to zero for vector field and non-zero for temporal sequence
243  void PutTSize(double);
244 
245  /// Voxel dimensions get access
246  void GetPixelSize(double &, double &) const;
247 
248  /// Voxel dimensions get access
249  void GetPixelSize(double &, double &, double &) const;
250 
251  /// Voxel dimensions get access
252  void GetPixelSize(double &, double &, double &, double &) const;
253 
254  /// Voxel dimensions put access
255  void PutPixelSize(double, double, double);
256 
257  /// Voxel dimensions put access
258  void PutPixelSize(double, double, double, double);
259 
260  /// Image origin get access
261  Point GetOrigin() const;
262 
263  /// Image origin get access
264  void GetOrigin(double &, double &, double &) const;
265 
266  /// Image origin get access
267  void GetOrigin(double &, double &, double &, double &) const;
268 
269  /// Image origin put access
270  void PutOrigin(const Point &);
271 
272  /// Image origin put access
273  void PutOrigin(double, double, double);
274 
275  /// Image origin put access
276  void PutOrigin(double, double, double, double);
277 
278  /// Put temporal origin
279  void PutTOrigin(double);
280 
281  /// Get temporal origin
282  double GetTOrigin() const;
283 
284  /// Put image x- and y-axis and z-axis
285  void PutOrientation(double *, double *, double * = NULL);
286 
287  /// Get image x- and y-axis and z-axis
288  void GetOrientation(double *, double *, double * = NULL) const;
289 
290  /// Get orientation of axis relative to patient
292 
293  /// Put affine world coordinate transformation which is applied
294  /// after the image to world coordinate transformation derived from the
295  /// imaging geometry when mapping voxel indices to world coordinates.
296  /// This transformation can be the inverse of the affine transformation
297  /// obtained by an affine registration with this image as source.
298  void PutAffineMatrix(const Matrix &, bool = false);
299 
300  /// Reset affine world coordinate transformation which is applied
301  /// after the image to world coordinate transformation derived from the
302  /// imaging geometry when mapping voxel indices to world coordinates.
303  void ResetAffineMatrix();
304 
305  /// Get affine world coordinate transformation which is applied
306  /// after the image to world coordinate transformation derived from the
307  /// imaging geometry when mapping voxel indices to world coordinates
308  const Matrix &GetAffineMatrix() const;
309 
310  /// Function to convert pixel to index
311  int VoxelToIndex(int, int, int = 0, int = 0) const;
312 
313  /// Function to convert index to pixel coordinates
314  void IndexToVoxel(int, int &, int &) const;
315 
316  /// Function to convert index to pixel coordinates
317  void IndexToVoxel(int, int &, int &, int &) const;
318 
319  /// Function to convert index to pixel coordinates
320  void IndexToVoxel(int, int &, int &, int &, int &) const;
321 
322  /// Get world coordinates (in mm) of pixl
323  void IndexToWorld(int, double &, double &) const;
324 
325  /// Get world coordinates (in mm) of pixel
326  void IndexToWorld(int, double &, double &, double &) const;
327 
328  /// Get world coordinates (in mm) of pixel
329  void IndexToWorld(int, Point &) const;
330 
331  /// Get world coordinates (in mm) of pixel
332  Point IndexToWorld(int) const;
333 
334  /// Image to world coordinate conversion with two doubles
335  void ImageToWorld(double &, double &) const;
336 
337  /// Image to world coordinate conversion with three doubles
338  void ImageToWorld(double &, double &, double &) const;
339 
340  /// Image to world coordinate conversion with a given point
341  void ImageToWorld(Point &) const;
342 
343  /// Convert vector w.r.t. image axes to vector w.r.t. world axes
344  void ImageToWorld(Vector3 &) const;
345 
346  /// Image to world coordinate map for image domain
347  ///
348  /// \note Stores x, y, and z components as vector image,
349  /// i.e., in t dimension of image.
350  ///
351  /// \param[out] i2w Vector image with world coordinates of voxels.
352  /// Need not be initialized before. No reallocation
353  /// takes place if the image has already the right size.
354  /// \param[in] _3D If \c false, only the x and y coordinates are
355  /// stored if the image is two dimensional. Otherwise,
356  /// all three x, y, and z components are stored.
357  void ImageToWorld(WorldCoordsImage &i2w, bool _3D = true) const;
358 
359  /// Image to world coordinate map for image domain
360  ///
361  /// \note Stores x, y, and z components at consecutive memory
362  /// locations for faster access.
363  ///
364  /// \param[out] i2w Memory for pre-computed world coordinates.
365  /// \param[in] _3D If \c false, only the x and y coordinates are
366  /// stored if the image is two dimensional. Otherwise,
367  /// all three x, y, and z components are stored.
368  void ImageToWorld(double *i2w, bool _3D = true) const;
369 
370  /// Adds world coordinates of each voxel to given point set
371  void ImageToWorld(PointSet &) const;
372 
373  /// World to image coordinate conversion with two doubles
374  void WorldToImage(double &, double &) const;
375 
376  /// World to image coordinate conversion with three doubles
377  void WorldToImage(double &, double &, double &) const;
378 
379  /// World to image coordinate conversion with a given point
380  void WorldToImage(Point &) const;
381 
382  /// Convert vector w.r.t. world axes to vector w.r.t. image axes
383  void WorldToImage(Vector3 &) const;
384 
385  /// Return transformation matrix for image to world coordinates
386  const Matrix &GetImageToWorldMatrix() const;
387 
388  /// Return transformation matrix for world to image coordinates
389  const Matrix &GetWorldToImageMatrix() const;
390 
391  /// Image to time coordinate conversion
392  double ImageToTime(double) const;
393 
394  /// Time to image coordinate conversion
395  double TimeToImage(double) const;
396 
397  /// Checks if this image shares the same spatial attributes with another image
398  bool HasSpatialAttributesOf(const BaseImage *) const;
399 
400  /// Returns true if point is within the field of view of image
401  bool IsInFOV(double, double, double);
402 
403  /// Whether image is uninitialized
404  bool IsEmpty() const;
405 
406  // ---------------------------------------------------------------------------
407  // Type independent access to image data
408 
409  /// Function for pixel get access as double
410  virtual double GetAsDouble(int) const;
411 
412  /// Function for pixel get access as double
413  virtual double GetAsDouble(int, int, int = 0, int = 0) const = 0;
414 
415  /// Function for pixel put access
416  virtual void PutAsDouble(int, double);
417 
418  /// Function for pixel put access
419  virtual void PutAsDouble(int, int, double);
420 
421  /// Function for pixel put access
422  virtual void PutAsDouble(int, int, int, double);
423 
424  /// Function for pixel put access
425  virtual void PutAsDouble(int, int, int, int, double) = 0;
426 
427  /// Function for pixel get access as double
428  virtual void GetAsVector(Vector &, int) const;
429 
430  /// Function for pixel get access as double
431  virtual void GetAsVector(Vector &, int, int, int = 0, int = 0) const = 0;
432 
433  /// Function for pixel get access as double
434  virtual Vector GetAsVector(int) const;
435 
436  /// Function for pixel get access as double
437  virtual Vector GetAsVector(int, int, int = 0, int = 0) const;
438 
439  /// Function for pixel put access
440  virtual void PutAsVector(int, const Vector &);
441 
442  /// Function for pixel put access
443  virtual void PutAsVector(int, int, const Vector &);
444 
445  /// Function for pixel put access
446  virtual void PutAsVector(int, int, int, const Vector &);
447 
448  /// Function for pixel put access
449  virtual void PutAsVector(int, int, int, int, const Vector &) = 0;
450 
451  // ---------------------------------------------------------------------------
452  // Foreground region
453 
454  /// Set foreground mask
455  void PutMask(BinaryImage *, bool = false);
456 
457  /// Get foreground mask (optionally, take over ownership)
458  BinaryImage *GetMask(bool = false);
459 
460  /// Get foreground mask
461  const BinaryImage *GetMask() const;
462 
463  /// Whether this image has a foreground mask which has been
464  /// either set via PutMask or created upon InitializeMask
465  bool HasMask() const;
466 
467  /// Whether this image has a foreground mask
468  /// either set via PutMask with ownership transver or created upon InitializeMask
469  bool OwnsMask() const;
470 
471  /// Initialize mask if not done yet or none is set
472  void InitializeMask(int t = -1, bool = false);
473 
474  /// Clear mask upon n-th call after n preceeding InitializeMask calls
475  void ClearMask(bool = false);
476 
477  /// Put background value
478  void PutBackgroundValueAsDouble(double);
479 
480  /// Put background value
481  virtual void PutBackgroundValueAsDouble(double, bool);
482 
483  /// Get background value
484  double GetBackgroundValueAsDouble() const;
485 
486  /// Change background value
487  ///
488  /// When a background value has been set before, this function replaces all image
489  /// values equal to this previous background value by the new background value.
490  /// Otherwise, it is equivalent to PutBackgroundValueAsDouble.
491  void ResetBackgroundValueAsDouble(double);
492 
493  /// Clear background value
494  void ClearBackgroundValue();
495 
496  /// Whether a background value has been set
497  bool HasBackgroundValue() const;
498 
499  /// Whether voxel is within foreground without index-out-of-bounds check
500  bool IsForeground(int) const;
501 
502  /// Whether voxel is within foreground without index-out-of-bounds check
503  bool IsForeground(int, int, int = 0, int = 0) const;
504 
505  /// Whether voxel is within background without index-out-of-bounds check
506  bool IsBackground(int) const;
507 
508  /// Whether voxel is within background without index-out-of-bounds check
509  bool IsBackground(int, int, int = 0, int = 0) const;
510 
511  /// Whether voxel index is within finite image domain
512  bool IsInside(int) const;
513 
514  /// Whether voxel indices are within finite 2D image domain
515  bool IsInside(int, int) const;
516 
517  /// Whether voxel indices are within finite 3D image domain
518  bool IsInside(int, int, int) const;
519 
520  /// Whether voxel indices are within finite 4D image domain
521  bool IsInside(int, int, int, int) const;
522 
523  /// Whether voxel is index is outside finite image domain
524  bool IsOutside(int) const;
525 
526  /// Whether voxel indices are outside finite 4D image domain
527  bool IsOutside(int, int) const;
528 
529  /// Whether voxel indices are outside finite 4D image domain
530  bool IsOutside(int, int, int) const;
531 
532  /// Whether voxel indices are outside finite 4D image domain
533  bool IsOutside(int, int, int, int) const;
534 
535  /// Whether voxel index is at boundary of finite image domain
536  bool IsBoundary(int) const;
537 
538  /// Whether voxel indices are at boundary of finite 2D image domain
539  bool IsBoundary(int, int) const;
540 
541  /// Whether voxel indices are at boundary of finite 3D image domain
542  bool IsBoundary(int, int, int) const;
543 
544  /// Whether voxel indices are at boundary of finite 4D image domain
545  bool IsBoundary(int, int, int, int) const;
546 
547  /// Whether voxel is index is within finite image domain and part of foreground region
548  bool IsInsideForeground(int) const;
549 
550  /// Whether voxel indices are within finite image domain and part of foreground region
551  bool IsInsideForeground(int, int, int = 0, int = 0) const;
552 
553  /// Whether voxel is index is outside finite image domain or part of background region
554  bool IsOutsideForeground(int) const;
555 
556  /// Whether voxel indices are outside finite image domain or part of background region
557  bool IsOutsideForeground(int, int, int = 0, int = 0) const;
558 
559  /// Whether all voxels within a 2D bounding region are inside foreground region
560  bool IsBoundingBoxInsideForeground(int, int, int, int) const;
561 
562  /// Whether all voxels within a 3D bounding region are inside foreground region
563  bool IsBoundingBoxInsideForeground(int, int, int, int, int, int) const;
564 
565  /// Whether all voxels within a 4D bounding region are inside foreground region
566  bool IsBoundingBoxInsideForeground(int, int, int, int, int, int, int, int) const;
567 
568  /// Whether at least one neighboring voxel is outside the finite foreground region
569  bool IsNextToBackground(int) const;
570 
571  /// Whether at least one neighboring voxel is outside the finite foreground region
572  bool IsNextToBackground(int, int, int = 0, int = 0) const;
573 
574  /// Whether at least one neighboring voxel is inside the finite foreground region
575  bool IsNextToForeground(int) const;
576 
577  /// Whether at least one neighboring voxel is inside the finite foreground region
578  bool IsNextToForeground(int, int, int = 0, int = 0) const;
579 
580  /// Whether any voxel is within background
581  bool HasBackground() const;
582 
583  /// Get 2D bounding box of image foreground
584  void BoundingBox(int &, int &, int &, int &) const;
585 
586  /// Get 3D bounding box of image foreground
587  void BoundingBox(int &, int &, int &, int &, int &, int &) const;
588 
589  /// Get 3D+t bounding box of image foreground
590  void BoundingBox(int &, int &, int &, int &, int &, int &, int &, int &) const;
591 
592  /// Determine center of mass of image foreground
593  ///
594  /// \param[out] center Centroid of image foreground.
595  ///
596  /// \returns Number of foreground intensities encountered or zero if the image does
597  /// not contain any foreground, in which case the \p center is invalid.
598  int CenterOfForeground(Point &center) const;
599 
600  /// Determine center of mass of image foreground
601  ///
602  /// \param[out] center Centroid of image foreground.
603  /// \param[in] padding Padding value. Voxels with a value less or equal are considered background.
604  /// When this value is NaN, all non-NaN image values are considered.
605  ///
606  /// \returns Number of foreground intensities encountered or zero if the image does
607  /// not contain any foreground, in which case the \p center is invalid.
608  int CenterOfForeground(Point &center, double padding) const;
609 
610  /// Get cropped image foreground bounding region
611  ///
612  /// \param[in] i1 Lower voxel index in x direction.
613  /// \param[in] j1 Lower voxel index in y direction.
614  /// \param[in] k1 Lower voxel index in z direction.
615  /// \param[in] i2 Upper voxel index in x direction.
616  /// \param[in] j2 Upper voxel index in y direction.
617  /// \param[in] k2 Upper voxel index in z direction.
618  /// \param[in] orthogonal Whether to orthogonalize image axes. Useful only in case
619  /// of input images where a previous affine (12 DoFs) alignment
620  /// has been applied to the attributes.
621  ///
622  /// \returns Attributes of foreground region.
623  ImageAttributes ForegroundDomain(int i1, int j1, int k1,
624  int i2, int j2, int k2,
625  bool orthogonal = true) const;
626 
627  /// Determine minimal axes-aligned foreground bounding region
628  ///
629  /// \param[in] orthogonal Whether to orthogonalize image axes. Useful only in case
630  /// of input images where a previous affine (12 DoFs) alignment
631  /// has been applied to the attributes.
632  ///
633  /// \returns Attributes of foreground region.
634  ImageAttributes ForegroundDomain(bool orthogonal = true) const;
635 
636  /// Determine minimal axes-aligned foreground bounding region
637  ///
638  /// \param[in] padding Padding value. Voxels with a value less or equal the specified
639  /// value are considered background. When the padding value is NaN,
640  /// all NaN image values are considered background.
641  /// \param[in] orthogonal Whether to orthogonalize image axes. Useful only in case
642  /// of input images where a previous affine (12 DoFs) alignment
643  /// has been applied to the attributes.
644  ///
645  /// \returns Attributes of foreground region.
646  ImageAttributes ForegroundDomain(double padding, bool orthogonal = true) const;
647 
648  // ---------------------------------------------------------------------------
649  // Region-of-interest extraction
650 
651  /// Get image consisting of specified 2D slice
652  virtual void GetRegion(BaseImage *&, int, int) const = 0;
653 
654  /// Get image consisting of specified 3D subregion
655  virtual void GetRegion(BaseImage *&, int, int, int, int, int, int) const = 0;
656 
657  /// Get image consisting of specified 4D subregion
658  virtual void GetRegion(BaseImage *&, int, int, int, int, int, int, int, int) const = 0;
659 
660  /// Get time instance (i.e., frame) or channel of image
661  virtual void GetFrame(BaseImage *&, int, int = -1) const = 0;
662 
663  // ---------------------------------------------------------------------------
664  // Common image statistics
665 
666  /// Minimum and maximum pixel values get accessor
667  virtual void GetMinMaxAsDouble(double &, double &) const;
668 
669  /// Minimum and maximum pixel values put accessor
670  virtual void PutMinMaxAsDouble(double, double);
671 
672  // ---------------------------------------------------------------------------
673  // Access to raw image data
674 
675  /// Function for pixel access via pointers
676  virtual void *GetDataPointer(int = 0) = 0;
677 
678  /// Function for pixel access via pointers
679  virtual const void *GetDataPointer(int = 0) const = 0;
680 
681  /// Function for pixel access via pointers
682  virtual void *GetDataPointer(int, int, int = 0, int = 0) = 0;
683 
684  /// Function for pixel access via pointers
685  virtual const void *GetDataPointer(int, int, int = 0, int = 0) const = 0;
686 
687  /// Function which returns pixel scalar type
688  virtual int GetDataType() const = 0;
689 
690  /// Function which returns size of pixel scalar type in bytes
691  virtual int GetDataTypeSize() const = 0;
692 
693  /// Function which returns the minimum value the pixel can hold without overflowing
694  virtual double GetDataTypeMin() const = 0;
695 
696  /// Function which returns the minimum value the pixel can hold without overflowing
697  virtual double GetDataTypeMax() const = 0;
698 
699  // ---------------------------------------------------------------------------
700  // Common image manipulations
701 
702  virtual void ReflectX(bool modify_axes = false) = 0; ///< Reflect image along x
703  virtual void ReflectY(bool modify_axes = false) = 0; ///< Reflect image along y
704  virtual void ReflectZ(bool modify_axes = false) = 0; ///< Reflect image along z
705  virtual void ReflectT(bool modify_axes = false) = 0; ///< Reflect image along t
706 
707  virtual void FlipXY(bool modify_origin = false) = 0; ///< Flip x and y axis, always also swaps voxel size
708  virtual void FlipXZ(bool modify_origin = false) = 0; ///< Flip x and z axis, always also swaps voxel size
709  virtual void FlipYZ(bool modify_origin = false) = 0; ///< Flip y and z axis, always also swaps voxel size
710  virtual void FlipXT(bool modify_origin = false) = 0; ///< Flip x and t axis, always also swaps voxel size
711  virtual void FlipYT(bool modify_origin = false) = 0; ///< Flip y and t axis, always also swaps voxel size
712  virtual void FlipZT(bool modify_origin = false) = 0; ///< Flip z and t axis, always also swaps voxel size
713 
714  virtual void SwapXY(bool modify_axes = true) = 0; ///< Swap x and y axis
715  virtual void SwapXZ(bool modify_axes = true) = 0; ///< Swap x and z axis
716  virtual void SwapYZ(bool modify_axes = true) = 0; ///< Swap y and z axis
717  virtual void SwapXT(bool modify_axes = true) = 0; ///< Swap x and t axis
718  virtual void SwapYT(bool modify_axes = true) = 0; ///< Swap y and t axis
719  virtual void SwapZT(bool modify_axes = true) = 0; ///< Swap z and t axis
720 
721  // ---------------------------------------------------------------------------
722  // VTK interface
723  #if MIRTK_Image_WITH_VTK
724 
725  /// Return the corresponding VTK scalar type
726  ///
727  /// \note Use only when MIRTK_Image_WITH_VTK is 1.
728  int ImageToVTKScalarType() const;
729 
730  /// Convert image to VTK structured points
731  ///
732  /// \note Use only when MIRTK_Image_WITH_VTK is 1.
733  virtual void ImageToVTK(vtkStructuredPoints *) const;
734 
735  /// Convert VTK structured points to image
736  ///
737  /// \note Use only when MIRTK_Image_WITH_VTK is 1.
738  virtual void VTKToImage(vtkStructuredPoints *);
739 
740  #endif // MIRTK_Image_WITH_VTK
741  // ---------------------------------------------------------------------------
742  // I/O
743 
744  /// Read image from file
745  virtual void Read(const char *) = 0;
746 
747  /// Write image to file
748  virtual void Write(const char *) const = 0;
749 
750  /// Print image information
751  virtual void Print(Indent = 0) const;
752 
753  // ---------------------------------------------------------------------------
754  // Emulation of GenericImage<VoxelType>
755 
756  // The following type definitions and "generic" voxel type specific member
757  // function are required by image functions/filters which are templated
758  // over the image type. If BaseImage is provided as template argument,
759  // these functions and filters access the image data (indirectly) through the
760  // abstract interface methods with implicit conversion to Vector.
761  // For improved performance and no data conversion, these image functions
762  // and filters can, however, be instantiated with a specific image type
763  // such as GreyImage in which case no data conversion takes place.
764  //
765  // \sa GenericExtrapolateImageFunction, GenericInterpolateImageFunction
766 
767  /// Default voxel type used by generic interpolate/extrapolate image functions
768  /// when instantiated with BaseImage as template argument as done by the
769  /// general interpolate image functions which thus can interpolate any scalar image.
770  typedef double VoxelType;
771  typedef voxel_info<VoxelType>::ScalarType ScalarType;
772  typedef voxel_info<VoxelType>::RealType RealType;
773  typedef voxel_info<RealType>::ScalarType RealScalarType;
774 
775  /// Get pixel value at voxel with given index
776  VoxelType Get(int) const;
777 
778  /// Get pixel value at voxel with given lattice coordinates
779  VoxelType Get(int, int, int = 0, int = 0) const;
780 
781  // ---------------------------------------------------------------------------
782  // Deprecated
783 
784  /// Gets the image attributes
785  /// \deprecated Use Attributes instead.
786  const ImageAttributes &GetImageAttributes() const;
787 
788  /// Returns the total number of voxels
789  /// \deprecated Use NumberOfVoxels instead.
790  int GetNumberOfVoxels() const;
791 
792  /// Voxel dimensions get access
793  void GetPixelSize(double *, double *, double *) const;
794 
795  /// Voxel dimensions get access
796  void GetPixelSize(double *, double *, double *, double *) const;
797 
798  /// Minimum and maximum pixel values get accessor
799  void GetMinMaxAsDouble(double *, double *) const;
800 
801  /// \returns Raw pointer to contiguous image data.
802  /// \deprecated Use GetDataPointer instead.
803  void *GetScalarPointer(int = 0, int = 0, int = 0, int = 0);
804 
805  /// \returns Raw pointer to contiguous image data.
806  /// \deprecated Use GetDataPointer instead.
807  const void *GetScalarPointer(int = 0, int = 0, int = 0, int = 0) const;
808 
809  /// \returns Enumeration value corresponding to pixel scalar type.
810  /// \deprecated Use GetVoxelType instead.
811  int GetScalarType() const;
812 
813  /// \returns Size of pixel scalar type in bytes.
814  /// \deprecated Use GetVoxelTypeSize instead.
815  int GetScalarTypeSize() const;
816 
817  /// \returns Minimum value a pixel can hold without overflowing.
818  /// \deprecated Use GetVoxelTypeMin instead.
819  double GetScalarTypeMin() const;
820 
821  /// \returns Maximum value a pixel can hold without overflowing.
822  /// \deprecated Use GetVoxelTypeMax instead.
823  double GetScalarTypeMax() const;
824 
825 };
826 
827 /// Alternative/backwards compatible type name
828 typedef BaseImage Image;
829 
830 
831 } // namespace mirtk
832 
833 #endif // MIRTK_BaseImage_H
834 
835 ////////////////////////////////////////////////////////////////////////////////
836 // Inline definitions of BaseImage
837 ////////////////////////////////////////////////////////////////////////////////
838 
839 #ifndef MIRTK_BaseImage_HH
840 #define MIRTK_BaseImage_HH
841 
842 // BinaryImage must be completely defined here already such that it can
843 // be used in the inline definitions. The methods using the mask must be inline
844 // in order for them to be efficient enough as they will be called for each voxel
845 #include "mirtk/GenericImage.h"
846 #include "mirtk/Math.h"
847 
848 
849 namespace mirtk {
850 
851 // =============================================================================
852 // Lattice
853 // =============================================================================
854 
855 // -----------------------------------------------------------------------------
857 {
858  return _attr;
859 }
860 
861 // -----------------------------------------------------------------------------
862 inline int BaseImage::NumberOfVoxels() const
863 {
864  return _NumberOfVoxels;
865 }
866 
867 // -----------------------------------------------------------------------------
869 {
870  return _attr.NumberOfSpatialPoints();
871 }
872 
873 // -----------------------------------------------------------------------------
874 inline int BaseImage::X() const
875 {
876  return _attr._x;
877 }
878 
879 // -----------------------------------------------------------------------------
880 inline int BaseImage::Y() const
881 {
882  return _attr._y;
883 }
884 
885 // -----------------------------------------------------------------------------
886 inline int BaseImage::Z() const
887 {
888  return _attr._z;
889 }
890 
891 // -----------------------------------------------------------------------------
892 inline int BaseImage::T() const
893 {
894  return _attr._t;
895 }
896 
897 // -----------------------------------------------------------------------------
898 inline int BaseImage::N() const
899 {
900  return 1;
901 }
902 
903 // -----------------------------------------------------------------------------
904 inline int BaseImage::GetX() const
905 {
906  return _attr._x;
907 }
908 
909 // -----------------------------------------------------------------------------
910 inline int BaseImage::GetY() const
911 {
912  return _attr._y;
913 }
914 
915 // -----------------------------------------------------------------------------
916 inline int BaseImage::GetZ() const
917 {
918  return _attr._z;
919 }
920 
921 // -----------------------------------------------------------------------------
922 inline int BaseImage::GetT() const
923 {
924  return _attr._t;
925 }
926 
927 // -----------------------------------------------------------------------------
928 inline double BaseImage::XSize() const
929 {
930  return _attr._dx;
931 }
932 
933 // -----------------------------------------------------------------------------
934 inline double BaseImage::YSize() const
935 {
936  return _attr._dy;
937 }
938 
939 // -----------------------------------------------------------------------------
940 inline double BaseImage::ZSize() const
941 {
942  return _attr._dz;
943 }
944 
945 // -----------------------------------------------------------------------------
946 inline double BaseImage::TSize() const
947 {
948  return _attr._dt;
949 }
950 
951 // -----------------------------------------------------------------------------
952 inline double BaseImage::GetXSize() const
953 {
954  return _attr._dx;
955 }
956 
957 // -----------------------------------------------------------------------------
958 inline double BaseImage::GetYSize() const
959 {
960  return _attr._dy;
961 }
962 
963 // -----------------------------------------------------------------------------
964 inline double BaseImage::GetZSize() const
965 {
966  return _attr._dz;
967 }
968 
969 // -----------------------------------------------------------------------------
970 inline double BaseImage::GetTSize() const
971 {
972  return _attr._dt;
973 }
974 
975 // -----------------------------------------------------------------------------
976 inline void BaseImage::PutTSize(double dt)
977 {
978  _attr._dt = dt;
979 }
980 
981 // -----------------------------------------------------------------------------
982 inline void BaseImage::PutPixelSize(double dx, double dy, double dz)
983 {
984  _attr._dx = dx;
985  _attr._dy = dy;
986  _attr._dz = dz;
987  UpdateMatrix();
988 }
989 
990 // -----------------------------------------------------------------------------
991 inline void BaseImage::PutPixelSize(double dx, double dy, double dz, double dt)
992 {
993  _attr._dx = dx;
994  _attr._dy = dy;
995  _attr._dz = dz;
996  _attr._dt = dt;
997  UpdateMatrix();
998 }
999 
1000 // -----------------------------------------------------------------------------
1001 inline void BaseImage::GetPixelSize(double &dx, double &dy) const
1002 {
1003  dx = _attr._dx;
1004  dy = _attr._dy;
1005 }
1006 
1007 // -----------------------------------------------------------------------------
1008 inline void BaseImage::GetPixelSize(double &dx, double &dy, double &dz) const
1009 {
1010  dx = _attr._dx;
1011  dy = _attr._dy;
1012  dz = _attr._dz;
1013 }
1014 
1015 // -----------------------------------------------------------------------------
1016 inline void BaseImage::GetPixelSize(double &dx, double &dy, double &dz, double &dt) const
1017 {
1018  dx = _attr._dx;
1019  dy = _attr._dy;
1020  dz = _attr._dz;
1021  dt = _attr._dt;
1022 }
1023 
1024 // -----------------------------------------------------------------------------
1025 inline void BaseImage::PutOrigin(const Point &p)
1026 {
1027  _attr._xorigin = p._x;
1028  _attr._yorigin = p._y;
1029  _attr._zorigin = p._z;
1030  UpdateMatrix();
1031 }
1032 
1033 // -----------------------------------------------------------------------------
1034 inline void BaseImage::PutOrigin(double x, double y, double z)
1035 {
1036  _attr._xorigin = x;
1037  _attr._yorigin = y;
1038  _attr._zorigin = z;
1039  UpdateMatrix();
1040 }
1041 
1042 // -----------------------------------------------------------------------------
1043 inline void BaseImage::PutOrigin(double x, double y, double z, double t)
1044 {
1045  _attr._xorigin = x;
1046  _attr._yorigin = y;
1047  _attr._zorigin = z;
1048  _attr._torigin = t;
1049  UpdateMatrix();
1050 }
1051 
1052 // -----------------------------------------------------------------------------
1053 inline void BaseImage::GetOrigin(double &x, double &y, double &z) const
1054 {
1055  x = _attr._xorigin;
1056  y = _attr._yorigin;
1057  z = _attr._zorigin;
1058 }
1059 
1060 // -----------------------------------------------------------------------------
1061 inline void BaseImage::GetOrigin(double &x, double &y, double &z, double &t) const
1062 {
1063  x = _attr._xorigin;
1064  y = _attr._yorigin;
1065  z = _attr._zorigin;
1066  t = _attr._torigin;
1067 }
1068 
1069 // -----------------------------------------------------------------------------
1071 {
1073 }
1074 
1075 // -----------------------------------------------------------------------------
1076 inline void BaseImage::PutTOrigin(double t)
1077 {
1078  _attr._torigin = t;
1079 }
1080 
1081 // -----------------------------------------------------------------------------
1082 inline double BaseImage::GetTOrigin() const
1083 {
1084  return _attr._torigin;
1085 }
1086 
1087 // -----------------------------------------------------------------------------
1088 inline void BaseImage::PutOrientation(double *xaxis, double *yaxis, double *zaxis)
1089 {
1090  const size_t n = 3 * sizeof(double);
1091  memcpy(_attr._xaxis, xaxis, n);
1092  memcpy(_attr._yaxis, yaxis, n);
1093  if (zaxis) memcpy(_attr._zaxis, zaxis, n);
1094  else {
1095  _attr._zaxis[0] = _attr._xaxis[1] * _attr._yaxis[2] - _attr._xaxis[2] * _attr._yaxis[1];
1096  _attr._zaxis[1] = _attr._xaxis[2] * _attr._yaxis[0] - _attr._xaxis[0] * _attr._yaxis[2];
1097  _attr._zaxis[2] = _attr._xaxis[0] * _attr._yaxis[1] - _attr._xaxis[1] * _attr._yaxis[0];
1098  }
1099  UpdateMatrix();
1100 }
1101 
1102 // -----------------------------------------------------------------------------
1103 inline void BaseImage::GetOrientation(double *xaxis, double *yaxis, double *zaxis) const
1104 {
1105  const size_t n = 3 * sizeof(double);
1106  memcpy(xaxis, _attr._xaxis, n);
1107  memcpy(yaxis, _attr._yaxis, n);
1108  if (zaxis) memcpy(zaxis, _attr._zaxis, n);
1109 }
1110 
1111 // -----------------------------------------------------------------------------
1112 inline void BaseImage::PutAffineMatrix(const Matrix &mat, bool apply)
1113 {
1114  _attr.PutAffineMatrix(mat, apply);
1115  this->UpdateMatrix();
1116 }
1117 
1118 // -----------------------------------------------------------------------------
1119 inline const Matrix &BaseImage::GetAffineMatrix() const
1120 {
1121  return _attr._smat;
1122 }
1123 
1124 // -----------------------------------------------------------------------------
1126 {
1127  _attr._smat.Ident();
1128  this->UpdateMatrix();
1129 }
1130 
1131 // -----------------------------------------------------------------------------
1132 inline int BaseImage::VoxelToIndex(int i, int j, int k, int l) const
1133 {
1134  return _attr.LatticeToIndex(i, j, k, l);
1135 }
1136 
1137 // -----------------------------------------------------------------------------
1138 inline void BaseImage::IndexToVoxel(int idx, int &i, int &j) const
1139 {
1140  _attr.IndexToLattice(idx, i, j);
1141 }
1142 
1143 // -----------------------------------------------------------------------------
1144 inline void BaseImage::IndexToVoxel(int idx, int &i, int &j, int &k) const
1145 {
1146  _attr.IndexToLattice(idx, i, j, k);
1147 }
1148 
1149 // -----------------------------------------------------------------------------
1150 inline void BaseImage::IndexToVoxel(int idx, int &i, int &j, int &k, int &l) const
1151 {
1152  _attr.IndexToLattice(idx, i, j, k, l);
1153 }
1154 
1155 // -----------------------------------------------------------------------------
1156 inline void BaseImage::IndexToWorld(int idx, double &x, double &y) const
1157 {
1158  _attr.IndexToWorld(idx, x, y);
1159 }
1160 
1161 // -----------------------------------------------------------------------------
1162 inline void BaseImage::IndexToWorld(int idx, double &x, double &y, double &z) const
1163 {
1164  _attr.IndexToWorld(idx, x, y, z);
1165 }
1166 
1167 // -----------------------------------------------------------------------------
1168 inline void BaseImage::IndexToWorld(int idx, Point &p) const
1169 {
1170  _attr.IndexToWorld(idx, p);
1171 }
1172 
1173 // -----------------------------------------------------------------------------
1174 inline Point BaseImage::IndexToWorld(int idx) const
1175 {
1176  return _attr.IndexToWorld(idx);
1177 }
1178 
1179 // -----------------------------------------------------------------------------
1180 inline void BaseImage::ImageToWorld(double &x, double &y) const
1181 {
1182  double a = _matI2W(0, 0) * x + _matI2W(0, 1) * y + _matI2W(0, 3);
1183  double b = _matI2W(1, 0) * x + _matI2W(1, 1) * y + _matI2W(1, 3);
1184  x = a, y = b;
1185 }
1186 
1187 // -----------------------------------------------------------------------------
1188 inline void BaseImage::ImageToWorld(double &x, double &y, double &z) const
1189 {
1190  double a = _matI2W(0, 0) * x + _matI2W(0, 1) * y + _matI2W(0, 2) * z + _matI2W(0, 3);
1191  double b = _matI2W(1, 0) * x + _matI2W(1, 1) * y + _matI2W(1, 2) * z + _matI2W(1, 3);
1192  double c = _matI2W(2, 0) * x + _matI2W(2, 1) * y + _matI2W(2, 2) * z + _matI2W(2, 3);
1193  x = a, y = b, z = c;
1194 }
1195 
1196 // -----------------------------------------------------------------------------
1197 inline void BaseImage::ImageToWorld(Point &p) const
1198 {
1199  ImageToWorld(p._x, p._y, p._z);
1200 }
1201 
1202 // -----------------------------------------------------------------------------
1203 inline void BaseImage::ImageToWorld(Vector3 &v) const
1204 {
1205  double a = _matI2W(0, 0) * v._x + _matI2W(0, 1) * v._y + _matI2W(0, 2) * v._z;
1206  double b = _matI2W(1, 0) * v._x + _matI2W(1, 1) * v._y + _matI2W(1, 2) * v._z;
1207  double c = _matI2W(2, 0) * v._x + _matI2W(2, 1) * v._y + _matI2W(2, 2) * v._z;
1208  v._x = a, v._y = b, v._z = c;
1209 }
1210 
1211 // -----------------------------------------------------------------------------
1212 inline void BaseImage::WorldToImage(double &x, double &y) const
1213 {
1214  double a = _matW2I(0, 0) * x + _matW2I(0, 1) * y + _matW2I(0, 3);
1215  double b = _matW2I(1, 0) * x + _matW2I(1, 1) * y + _matW2I(1, 3);
1216  x = a, y = b;
1217 }
1218 
1219 // -----------------------------------------------------------------------------
1220 inline void BaseImage::WorldToImage(double &x, double &y, double &z) const
1221 {
1222  double a = _matW2I(0, 0) * x + _matW2I(0, 1) * y + _matW2I(0, 2) * z + _matW2I(0, 3);
1223  double b = _matW2I(1, 0) * x + _matW2I(1, 1) * y + _matW2I(1, 2) * z + _matW2I(1, 3);
1224  double c = _matW2I(2, 0) * x + _matW2I(2, 1) * y + _matW2I(2, 2) * z + _matW2I(2, 3);
1225  x = a, y = b, z = c;
1226 }
1227 
1228 // -----------------------------------------------------------------------------
1229 inline void BaseImage::WorldToImage(Point &p) const
1230 {
1231  WorldToImage(p._x, p._y, p._z);
1232 }
1233 
1234 // -----------------------------------------------------------------------------
1235 inline void BaseImage::WorldToImage(Vector3 &v) const
1236 {
1237  double a = _matW2I(0, 0) * v._x + _matW2I(0, 1) * v._y + _matW2I(0, 2) * v._z;
1238  double b = _matW2I(1, 0) * v._x + _matW2I(1, 1) * v._y + _matW2I(1, 2) * v._z;
1239  double c = _matW2I(2, 0) * v._x + _matW2I(2, 1) * v._y + _matW2I(2, 2) * v._z;
1240  v._x = a, v._y = b, v._z = c;
1241 }
1242 
1243 // -----------------------------------------------------------------------------
1245 {
1246  return _matI2W;
1247 }
1248 
1249 // -----------------------------------------------------------------------------
1251 {
1252  return _matW2I;
1253 }
1254 
1255 // -----------------------------------------------------------------------------
1256 inline double BaseImage::ImageToTime(double t) const
1257 {
1258  return _attr._torigin + t * _attr._dt;
1259 }
1260 
1261 // -----------------------------------------------------------------------------
1262 inline double BaseImage::TimeToImage(double t) const
1263 {
1264  return (_attr._dt ? ((t - _attr._torigin) / _attr._dt) : .0);
1265 }
1266 
1267 // -----------------------------------------------------------------------------
1268 inline bool BaseImage::HasSpatialAttributesOf(const BaseImage *other) const
1269 {
1270  return _attr.EqualInSpace(other->GetImageAttributes());
1271 }
1272 
1273 // -----------------------------------------------------------------------------
1274 inline bool BaseImage::IsInFOV(double x, double y, double z)
1275 {
1276  this->WorldToImage(x, y, z);
1277  return (-0.5 <= x && x < _attr._x - 0.5) &&
1278  (-0.5 <= y && y < _attr._y - 0.5) &&
1279  (-0.5 <= z && z < _attr._z - 0.5);
1280 }
1281 
1282 // -----------------------------------------------------------------------------
1283 inline bool BaseImage::IsEmpty() const
1284 {
1285  return ((_attr._x < 1) || (_attr._y < 1) || (_attr._z < 1) || (_attr._t < 1));
1286 }
1287 
1288 // =============================================================================
1289 // Type independent access to image data
1290 // =============================================================================
1291 
1292 // -----------------------------------------------------------------------------
1293 inline double BaseImage::GetAsDouble(int idx) const
1294 {
1295  int i, j, k, l;
1296  IndexToVoxel(idx, i, j, k, l);
1297  return this->GetAsDouble(i, j, k, l);
1298 }
1299 
1300 // -----------------------------------------------------------------------------
1301 inline void BaseImage::PutAsDouble(int idx, double v)
1302 {
1303  int i, j, k, l;
1304  IndexToVoxel(idx, i, j, k, l);
1305  this->PutAsDouble(i, j, k, l, v);
1306 }
1307 
1308 // -----------------------------------------------------------------------------
1309 inline void BaseImage::PutAsDouble(int i, int j, double v)
1310 {
1311  this->PutAsDouble(i, j, 0, 0, v);
1312 }
1313 
1314 // -----------------------------------------------------------------------------
1315 inline void BaseImage::PutAsDouble(int i, int j, int k, double v)
1316 {
1317  this->PutAsDouble(i, j, k, 0, v);
1318 }
1319 
1320 // -----------------------------------------------------------------------------
1321 inline void BaseImage::GetAsVector(Vector &v, int idx) const
1322 {
1323  int i, j, k, l;
1324  IndexToVoxel(idx, i, j, k, l);
1325  this->GetAsVector(v, i, j, k, l);
1326 }
1327 
1328 // -----------------------------------------------------------------------------
1329 inline Vector BaseImage::GetAsVector(int idx) const
1330 {
1331  Vector v;
1332  this->GetAsVector(v, idx);
1333  return v;
1334 }
1335 
1336 // -----------------------------------------------------------------------------
1337 inline Vector BaseImage::GetAsVector(int i, int j, int k, int l) const
1338 {
1339  Vector v;
1340  this->GetAsVector(v, i, j, k, l);
1341  return v;
1342 }
1343 
1344 // -----------------------------------------------------------------------------
1345 inline void BaseImage::PutAsVector(int idx, const Vector &v)
1346 {
1347  int i, j, k, l;
1348  IndexToVoxel(idx, i, j, k, l);
1349  this->PutAsVector(i, j, k, l, v);
1350 }
1351 
1352 // -----------------------------------------------------------------------------
1353 inline void BaseImage::PutAsVector(int i, int j, const Vector &v)
1354 {
1355  this->PutAsVector(i, j, 0, 0, v);
1356 }
1357 
1358 // -----------------------------------------------------------------------------
1359 inline void BaseImage::PutAsVector(int i, int j, int k, const Vector &v)
1360 {
1361  this->PutAsVector(i, j, k, 0, v);
1362 }
1363 
1364 // =============================================================================
1365 // Foreground region
1366 // =============================================================================
1367 
1368 // -----------------------------------------------------------------------------
1369 inline BinaryImage *BaseImage::GetMask(bool surrender_ownership)
1370 {
1371  if (surrender_ownership) _maskOwner = false;
1372  return _mask;
1373 }
1374 
1375 // -----------------------------------------------------------------------------
1376 inline const BinaryImage *BaseImage::GetMask() const
1377 {
1378  return _mask;
1379 }
1380 
1381 // -----------------------------------------------------------------------------
1382 inline bool BaseImage::HasMask() const
1383 {
1384  return _mask != NULL;
1385 }
1386 
1387 // -----------------------------------------------------------------------------
1388 inline bool BaseImage::OwnsMask() const
1389 {
1390  return _mask != NULL && _maskOwner;
1391 }
1392 
1393 // -----------------------------------------------------------------------------
1394 inline void BaseImage::PutBackgroundValueAsDouble(double value)
1395 {
1396  _bg = value;
1397  _bgSet = true;
1398 }
1399 
1400 // -----------------------------------------------------------------------------
1401 inline void BaseImage::PutBackgroundValueAsDouble(double value, bool threshold)
1402 {
1403  _bg = value;
1404  _bgSet = true;
1405  if (threshold && !IsNaN(_bg)) {
1406  for (int idx = 0; idx < _NumberOfVoxels; idx++) {
1407  if (this->GetAsDouble(idx) < _bg) this->PutAsDouble(idx, _bg);
1408  }
1409  }
1410 }
1411 
1412 // -----------------------------------------------------------------------------
1414 {
1415  return _bg;
1416 }
1417 
1418 // -----------------------------------------------------------------------------
1420 {
1421  _bgSet = false;
1422 }
1423 
1424 // -----------------------------------------------------------------------------
1426 {
1427  return _bgSet;
1428 }
1429 
1430 // -----------------------------------------------------------------------------
1431 inline bool BaseImage::IsBackground(int idx) const
1432 {
1433  if (_mask) {
1434  if (_mask->T() != _attr._t) idx = idx % (_attr._x * _attr._y * _attr._z);
1435  return (_mask->Get(idx) == BinaryPixel(0));
1436  } else if (_bgSet) {
1437  return AreEqualOrNaN(this->GetAsDouble(idx), _bg, 1e-6);
1438  }
1439  return false;
1440 }
1441 
1442 // -----------------------------------------------------------------------------
1443 inline bool BaseImage::IsBackground(int i, int j, int k, int l) const
1444 {
1445  if (_mask) {
1446  if (_mask->T() != _attr._t) l = 0;
1447  return (_mask->Get(i, j, k, l) == BinaryPixel(0));
1448  } else if (_bgSet) {
1449  return AreEqualOrNaN(this->GetAsDouble(i, j, k, l), _bg, 1e-6);
1450  }
1451  return false;
1452 }
1453 
1454 // -----------------------------------------------------------------------------
1455 inline bool BaseImage::IsForeground(int idx) const
1456 {
1457  return !IsBackground(idx);
1458 }
1459 
1460 // -----------------------------------------------------------------------------
1461 inline bool BaseImage::IsForeground(int i, int j, int k, int l) const
1462 {
1463  return !IsBackground(i, j, k, l);
1464 }
1465 
1466 // -----------------------------------------------------------------------------
1467 inline bool BaseImage::IsInside(int idx) const
1468 {
1469  return (0 <= idx && idx < _NumberOfVoxels);
1470 }
1471 
1472 // -----------------------------------------------------------------------------
1473 inline bool BaseImage::IsInside(int i, int j) const
1474 {
1475  return _attr.IsInside(i, j);
1476 }
1477 
1478 // -----------------------------------------------------------------------------
1479 inline bool BaseImage::IsInside(int i, int j, int k) const
1480 {
1481  return _attr.IsInside(i, j, k);
1482 }
1483 
1484 // -----------------------------------------------------------------------------
1485 inline bool BaseImage::IsInside(int i, int j, int k, int l) const
1486 {
1487  return _attr.IsInside(i, j, k, l);
1488 }
1489 
1490 // -----------------------------------------------------------------------------
1491 inline bool BaseImage::IsOutside(int idx) const
1492 {
1493  return !IsInside(idx);
1494 }
1495 
1496 // -----------------------------------------------------------------------------
1497 inline bool BaseImage::IsOutside(int i, int j) const
1498 {
1499  return !IsInside(i, j);
1500 }
1501 
1502 // -----------------------------------------------------------------------------
1503 inline bool BaseImage::IsOutside(int i, int j, int k) const
1504 {
1505  return !IsInside(i, j, k);
1506 }
1507 
1508 // -----------------------------------------------------------------------------
1509 inline bool BaseImage::IsOutside(int i, int j, int k, int l) const
1510 {
1511  return !IsInside(i, j, k, l);
1512 }
1513 
1514 // -----------------------------------------------------------------------------
1515 inline bool BaseImage::IsBoundary(int idx) const
1516 {
1517  return _attr.IsBoundary(idx);
1518 }
1519 
1520 // -----------------------------------------------------------------------------
1521 inline bool BaseImage::IsBoundary(int i, int j) const
1522 {
1523  return _attr.IsBoundary(i, j);
1524 }
1525 
1526 // -----------------------------------------------------------------------------
1527 inline bool BaseImage::IsBoundary(int i, int j, int k) const
1528 {
1529  return _attr.IsBoundary(i, j, k);
1530 }
1531 
1532 // -----------------------------------------------------------------------------
1533 inline bool BaseImage::IsBoundary(int i, int j, int k, int l) const
1534 {
1535  return _attr.IsBoundary(i, j, k, l);
1536 }
1537 
1538 // -----------------------------------------------------------------------------
1539 inline bool BaseImage::IsInsideForeground(int idx) const
1540 {
1541  return IsInside(idx) && IsForeground(idx);
1542 }
1543 
1544 // -----------------------------------------------------------------------------
1545 inline bool BaseImage::IsInsideForeground(int i, int j, int k, int l) const
1546 {
1547  return IsInside(i, j, k, l) && IsForeground(i, j, k, l);
1548 }
1549 
1550 // -----------------------------------------------------------------------------
1551 inline bool BaseImage::IsOutsideForeground(int idx) const
1552 {
1553  return !IsInsideForeground(idx);
1554 }
1555 
1556 // -----------------------------------------------------------------------------
1557 inline bool BaseImage::IsOutsideForeground(int i, int j, int k, int l) const
1558 {
1559  return !IsInsideForeground(i, j, k, l);
1560 }
1561 
1562 // -----------------------------------------------------------------------------
1563 inline bool BaseImage::IsBoundingBoxInsideForeground(int i1, int j1,
1564  int i2, int j2) const
1565 {
1566  if (i1 < 0 || i2 >= _attr._x ||
1567  j1 < 0 || j2 >= _attr._y) return false;
1568  if (_mask) {
1569  for (int j = j1; j != j2; j++) {
1570  for (int i = i1; i != i2; i++) {
1571  if (!_mask->Get(i, j)) return false;
1572  }
1573  }
1574  } else if (_bgSet) {
1575  for (int j = j1; j != j2; j++) {
1576  for (int i = i1; i != i2; i++) {
1577  if (AreEqualOrNaN(this->GetAsDouble(i, j), _bg, 1e-6)) return false;
1578  }
1579  }
1580  }
1581  return true;
1582 }
1583 
1584 // -----------------------------------------------------------------------------
1585 inline bool BaseImage::IsBoundingBoxInsideForeground(int i1, int j1, int k1,
1586  int i2, int j2, int k2) const
1587 {
1588  if (i1 < 0 || i2 >= _attr._x ||
1589  j1 < 0 || j2 >= _attr._y ||
1590  k1 < 0 || k2 >= _attr._z) return false;
1591  if (_mask) {
1592  for (int k = k1; k != k2; k++) {
1593  for (int j = j1; j != j2; j++) {
1594  for (int i = i1; i != i2; i++) {
1595  if (!_mask->Get(i, j, k)) return false;
1596  }
1597  }
1598  }
1599  } else if (_bgSet) {
1600  for (int k = k1; k != k2; k++) {
1601  for (int j = j1; j != j2; j++) {
1602  for (int i = i1; i != i2; i++) {
1603  if (AreEqualOrNaN(this->GetAsDouble(i, j, k), _bg, 1e-6)) return false;
1604  }
1605  }
1606  }
1607  }
1608  return true;
1609 }
1610 
1611 // -----------------------------------------------------------------------------
1612 inline bool BaseImage::IsBoundingBoxInsideForeground(int i1, int j1, int k1, int l1,
1613  int i2, int j2, int k2, int l2) const
1614 {
1615  if (i1 < 0 || i2 >= _attr._x ||
1616  j1 < 0 || j2 >= _attr._y ||
1617  k1 < 0 || k2 >= _attr._z ||
1618  l1 < 0 || l2 >= _attr._t) return false;
1619  if (_mask) {
1620  if (_mask->T() == 1) {
1621  for (int k = k1; k != k2; k++) {
1622  for (int j = j1; j != j2; j++) {
1623  for (int i = i1; i != i2; i++) {
1624  if (!_mask->Get(i, j, k)) return false;
1625  }
1626  }
1627  }
1628  } else {
1629  for (int l = l1; l != l2; l++) {
1630  for (int k = k1; k != k2; k++) {
1631  for (int j = j1; j != j2; j++) {
1632  for (int i = i1; i != i2; i++) {
1633  if (!_mask->Get(i, j, k, l)) return false;
1634  }
1635  }
1636  }
1637  }
1638  }
1639  } else if (_bgSet) {
1640  double value;
1641  for (int l = l1; l != l2; l++) {
1642  for (int k = k1; k != k2; k++) {
1643  for (int j = j1; j != j2; j++) {
1644  for (int i = i1; i != i2; i++) {
1645  value = this->GetAsDouble(i, j, k, l);
1646  if (AreEqualOrNaN(this->GetAsDouble(i, j, k, l), _bg, 1e-6)) return false;
1647  }
1648  }
1649  }
1650  }
1651  }
1652  return true;
1653 }
1654 
1655 // -----------------------------------------------------------------------------
1656 inline bool BaseImage::IsNextToBackground(int i, int j, int k, int l) const
1657 {
1658  for (int nl = l - 1; nl <= l + 1; ++nl)
1659  for (int nk = k - 1; nk <= k + 1; ++nk)
1660  for (int nj = j - 1; nj <= j + 1; ++nj)
1661  for (int ni = i - 1; ni <= i + 1; ++ni) {
1662  if (ni != 0 || nj != 0 || nk != 0 || nl != 0) {
1663  if (IsOutsideForeground(ni, nj, nk, nl)) {
1664  return true;
1665  }
1666  }
1667  }
1668  return false;
1669 }
1670 
1671 // -----------------------------------------------------------------------------
1672 inline bool BaseImage::IsNextToBackground(int idx) const
1673 {
1674  int i, j, k, l;
1675  IndexToVoxel(idx, i, j, k, l);
1676  return IsNextToBackground(i, j, k, l);
1677 }
1678 
1679 // -----------------------------------------------------------------------------
1680 inline bool BaseImage::IsNextToForeground(int i, int j, int k, int l) const
1681 {
1682  for (int nl = l - 1; nl <= l + 1; ++nl)
1683  for (int nk = k - 1; nk <= k + 1; ++nk)
1684  for (int nj = j - 1; nj <= j + 1; ++nj)
1685  for (int ni = i - 1; ni <= i + 1; ++ni) {
1686  if (ni != 0 || nj != 0 || nk != 0 || nl != 0) {
1687  if (IsInsideForeground(ni, nj, nk, nl)) {
1688  return true;
1689  }
1690  }
1691  }
1692  return false;
1693 }
1694 
1695 // -----------------------------------------------------------------------------
1696 inline bool BaseImage::IsNextToForeground(int idx) const
1697 {
1698  int i, j, k, l;
1699  IndexToVoxel(idx, i, j, k, l);
1700  return IsNextToForeground(i, j, k, l);
1701 }
1702 
1703 // -----------------------------------------------------------------------------
1704 inline bool BaseImage::HasBackground() const
1705 {
1706  if (HasBackgroundValue() || GetMask()) {
1707  for (int i = 0; i < _NumberOfVoxels; i++) {
1708  if (IsBackground(i)) return true;
1709  }
1710  }
1711  return false;
1712 }
1713 
1714 // =============================================================================
1715 // Emulation of GenericImage<VoxelType>
1716 // =============================================================================
1717 
1718 // -----------------------------------------------------------------------------
1719 inline double BaseImage::Get(int idx) const
1720 {
1721  return this->GetAsDouble(idx);
1722 }
1723 
1724 // -----------------------------------------------------------------------------
1725 inline double BaseImage::Get(int i, int j, int k, int l) const
1726 {
1727  return this->GetAsDouble(i, j, k, l);
1728 }
1729 
1730 // =============================================================================
1731 // Deprecated
1732 // =============================================================================
1733 
1734 // -----------------------------------------------------------------------------
1736 {
1737  return Attributes();
1738 }
1739 
1740 // -----------------------------------------------------------------------------
1742 {
1743  return NumberOfVoxels();
1744 }
1745 
1746 // -----------------------------------------------------------------------------
1747 inline void BaseImage::GetPixelSize(double *dx, double *dy, double *dz) const
1748 {
1749  *dx = _attr._dx;
1750  *dy = _attr._dy;
1751  *dz = _attr._dz;
1752 }
1753 
1754 // -----------------------------------------------------------------------------
1755 inline void BaseImage::GetPixelSize(double *dx, double *dy, double *dz, double *dt) const
1756 {
1757  *dx = _attr._dx;
1758  *dy = _attr._dy;
1759  *dz = _attr._dz;
1760  *dt = _attr._dt;
1761 }
1762 
1763 // -----------------------------------------------------------------------------
1764 inline void BaseImage::GetMinMaxAsDouble(double *min, double *max) const
1765 {
1766  this->GetMinMaxAsDouble(*min, *max);
1767 }
1768 
1769 // -----------------------------------------------------------------------------
1770 inline void *BaseImage::GetScalarPointer(int i, int j, int k, int l)
1771 {
1772  return this->GetDataPointer(i, j, k, l);
1773 }
1774 
1775 // -----------------------------------------------------------------------------
1776 inline const void *BaseImage::GetScalarPointer(int i, int j, int k, int l) const
1777 {
1778  return this->GetDataPointer(i, j, k, l);
1779 }
1780 
1781 // -----------------------------------------------------------------------------
1782 inline int BaseImage::GetScalarType() const
1783 {
1784  return this->GetDataType();
1785 }
1786 
1787 // -----------------------------------------------------------------------------
1789 {
1790  return this->GetDataTypeSize();
1791 }
1792 
1793 // -----------------------------------------------------------------------------
1794 inline double BaseImage::GetScalarTypeMin() const
1795 {
1796  return this->GetDataTypeMin();
1797 }
1798 
1799 // -----------------------------------------------------------------------------
1800 inline double BaseImage::GetScalarTypeMax() const
1801 {
1802  return this->GetDataTypeMax();
1803 }
1804 
1805 
1806 } // namespace mirtk
1807 
1808 #endif // MIRTK_BaseImage_HH
virtual void PutAsVector(int, const Vector &)
Function for pixel put access.
Definition: BaseImage.h:1345
double _dt
Voxel t-dimensions (in ms)
int GetScalarType() const
Definition: BaseImage.h:1782
int _NumberOfVoxels
Total number of voxels.
Definition: BaseImage.h:102
bool IsOutsideForeground(int) const
Whether voxel is index is outside finite image domain or part of background region.
Definition: BaseImage.h:1551
virtual int GetDataTypeSize() const =0
Function which returns size of pixel scalar type in bytes.
double _xaxis[3]
Direction of x-axis.
void InitializeMask(int t=-1, bool=false)
Initialize mask if not done yet or none is set.
bool HasBackgroundValue() const
Whether a background value has been set.
Definition: BaseImage.h:1425
double GetBackgroundValueAsDouble() const
Get background value.
Definition: BaseImage.h:1413
bool IsBoundingBoxInsideForeground(int, int, int, int) const
Whether all voxels within a 2D bounding region are inside foreground region.
Definition: BaseImage.h:1563
bool IsBackground(int) const
Whether voxel is within background without index-out-of-bounds check.
Definition: BaseImage.h:1431
void ClearBackgroundValue()
Clear background value.
Definition: BaseImage.h:1419
const Matrix & GetAffineMatrix() const
Definition: BaseImage.h:1119
BinaryImage * _mask
Foreground mask.
Definition: BaseImage.h:111
int VoxelToIndex(int, int, int=0, int=0) const
Function to convert pixel to index.
Definition: BaseImage.h:1132
double GetScalarTypeMax() const
Definition: BaseImage.h:1800
static BaseImage * New(const char *)
Read file and construct image.
virtual void FlipXY(bool modify_origin=false)=0
Flip x and y axis, always also swaps voxel size.
void PutBackgroundValueAsDouble(double)
Put background value.
Definition: BaseImage.h:1394
Right to Left.
Definition: BaseImage.h:86
virtual void FlipYT(bool modify_origin=false)=0
Flip y and t axis, always also swaps voxel size.
const ImageAttributes & Attributes() const
Gets the image attributes.
Definition: BaseImage.h:856
bool IsOutside(int) const
Whether voxel is index is outside finite image domain.
Definition: BaseImage.h:1491
Anterior to Posterior.
Definition: BaseImage.h:88
double GetYSize() const
Returns the size of a voxel in the y-direction.
Definition: BaseImage.h:958
void PutOrientation(double *, double *, double *=NULL)
Put image x- and y-axis and z-axis.
Definition: BaseImage.h:1088
void PutAttributes(const ImageAttributes &)
Puts attributes of image.
bool IsEmpty() const
Whether image is uninitialized.
Definition: BaseImage.h:1283
void WorldToImage(double &, double &) const
World to image coordinate conversion with two doubles.
Definition: BaseImage.h:1212
Inferior to Superior.
Definition: BaseImage.h:89
Matrix _smat
Affine transformation matrix.
bool HasSpatialAttributesOf(const BaseImage *) const
Checks if this image shares the same spatial attributes with another image.
Definition: BaseImage.h:1268
void PutMask(BinaryImage *, bool=false)
Set foreground mask.
void PutAffineMatrix(const Matrix &m, bool apply=false)
virtual double GetDataTypeMax() const =0
Function which returns the minimum value the pixel can hold without overflowing.
BaseImage()
Default constructor.
double _torigin
Image t-origin (in ms)
double _x
x coordinate of Point
Definition: Point.h:46
int _y
Image y-dimension (in voxels)
virtual void GetAsVector(Vector &, int) const
Function for pixel get access as double.
Definition: BaseImage.h:1321
MIRTKCU_API bool IsNaN(double x)
Check if floating point value is not a number (NaN)
Definition: Math.h:91
double ZSize() const
Returns the size of a voxel in the z-direction.
Definition: BaseImage.h:940
bool HasBackground() const
Whether any voxel is within background.
Definition: BaseImage.h:1704
double GetScalarTypeMin() const
Definition: BaseImage.h:1794
virtual int GetDataType() const =0
Function which returns pixel scalar type.
const ImageAttributes & GetImageAttributes() const
Definition: BaseImage.h:1735
virtual void FlipZT(bool modify_origin=false)=0
Flip z and t axis, always also swaps voxel size.
bool HasMask() const
Definition: BaseImage.h:1382
void ResetBackgroundValueAsDouble(double)
virtual void PutMinMaxAsDouble(double, double)
Minimum and maximum pixel values put accessor.
virtual void GetRegion(BaseImage *&, int, int) const =0
Get image consisting of specified 2D slice.
Matrix _matW2I
Transformation matrix from (transformed) world coordinates to image coordinates.
Definition: BaseImage.h:108
void GetPixelSize(double &, double &) const
Voxel dimensions get access.
Definition: BaseImage.h:1001
virtual void SwapZT(bool modify_axes=true)=0
Swap z and t axis.
virtual BaseImage * Copy() const
Create copy of this image.
double _xorigin
Image x-origin (in mm)
double _bg
Background value - may also be NaN for floating point images.
Definition: BaseImage.h:123
Matrix & Ident()
Set to identity matrix.
bool IsForeground(int) const
Whether voxel is within foreground without index-out-of-bounds check.
Definition: BaseImage.h:1455
void PutOrigin(const Point &)
Image origin put access.
Definition: BaseImage.h:1025
virtual void Clear()=0
Clear image.
virtual void Read(const char *)=0
Read image from file.
virtual void SwapXT(bool modify_axes=true)=0
Swap x and t axis.
ImageAttributes _attr
Image attributes.
Definition: BaseImage.h:99
MIRTKCU_API bool AreEqualOrNaN(double a, double b, double tol=1e-12)
Determine equality of two floating point numbers including check if both are NaN. ...
Definition: Math.h:122
void Orientation(OrientationCode &, OrientationCode &, OrientationCode &) const
Get orientation of axis relative to patient.
virtual void Initialize(const ImageAttributes &, int=-1)=0
Initialize image.
Definition: IOConfig.h:41
void IndexToWorld(int, double &, double &) const
Get world coordinates (in mm) of lattice point.
virtual void Write(const char *) const =0
Write image to file.
int GetX() const
Returns the number of voxels in the x-direction.
Definition: BaseImage.h:904
void PutAffineMatrix(const Matrix &, bool=false)
Definition: BaseImage.h:1112
BaseImage & operator=(const BaseImage &)
Assignment operator.
void ImageToWorld(double &, double &) const
Image to world coordinate conversion with two doubles.
Definition: BaseImage.h:1180
double GetTOrigin() const
Get temporal origin.
Definition: BaseImage.h:1082
int _z
Image z-dimension (in voxels)
double _dz
Voxel z-dimensions (in mm)
virtual double GetAsDouble(int) const
Function for pixel get access as double.
Definition: BaseImage.h:1293
void ResetAffineMatrix()
Definition: BaseImage.h:1125
bool OwnsMask() const
Definition: BaseImage.h:1388
const Matrix & GetWorldToImageMatrix() const
Return transformation matrix for world to image coordinates.
Definition: BaseImage.h:1250
int _t
Image t-dimension (in voxels)
virtual void GetFrame(BaseImage *&, int, int=-1) const =0
Get time instance (i.e., frame) or channel of image.
void UpdateMatrix()
Update coordinate transformation.
int GetT() const
Returns the number of voxels in the t-direction.
Definition: BaseImage.h:922
double TimeToImage(double) const
Time to image coordinate conversion.
Definition: BaseImage.h:1262
virtual void SwapXZ(bool modify_axes=true)=0
Swap x and z axis.
int GetY() const
Returns the number of voxels in the y-direction.
Definition: BaseImage.h:910
double _zorigin
Image z-origin (in mm)
virtual double GetDataTypeMin() const =0
Function which returns the minimum value the pixel can hold without overflowing.
double GetZSize() const
Returns the size of a voxel in the z-direction.
Definition: BaseImage.h:964
virtual void FlipXT(bool modify_origin=false)=0
Flip x and t axis, always also swaps voxel size.
virtual void * GetDataPointer(int=0)=0
Function for pixel access via pointers.
bool IsInsideForeground(int) const
Whether voxel is index is within finite image domain and part of foreground region.
Definition: BaseImage.h:1539
bool IsInside(int) const
Whether voxel index is within finite image domain.
Definition: BaseImage.h:1467
int Y() const
Returns the number of voxels in the y-direction.
Definition: BaseImage.h:880
virtual void SwapYZ(bool modify_axes=true)=0
Swap y and z axis.
int GetNumberOfVoxels() const
Definition: BaseImage.h:1741
double ImageToTime(double) const
Image to time coordinate conversion.
Definition: BaseImage.h:1256
virtual int N() const
Returns the number of vector components (i.e., 1 for scalar images)
Definition: BaseImage.h:898
int LatticeToIndex(int, int, int=0, int=0) const
Get Index from Lattice.
const BinaryImage * GetMask() const
Get foreground mask.
Definition: BaseImage.h:1376
void * GetScalarPointer(int=0, int=0, int=0, int=0)
Definition: BaseImage.h:1770
virtual ~BaseImage()
Destructor.
int X() const
Returns the number of voxels in the x-direction.
Definition: BaseImage.h:874
bool IsNextToBackground(int) const
Whether at least one neighboring voxel is outside the finite foreground region.
Definition: BaseImage.h:1672
virtual void ReflectZ(bool modify_axes=false)=0
Reflect image along z.
Point GetOrigin() const
Image origin get access.
Definition: BaseImage.h:1070
double VoxelType
Definition: BaseImage.h:770
int NumberOfSpatialPoints() const
Number of spatial lattice points.
void IndexToWorld(int, double &, double &) const
Get world coordinates (in mm) of pixl.
Definition: BaseImage.h:1156
double _zaxis[3]
Direction of z-axis.
virtual void Print(Indent=0) const
Print image information.
bool EqualInSpace(const ImageAttributes &attr) const
Whether spatial attributes are equal.
virtual void FlipYZ(bool modify_origin=false)=0
Flip y and z axis, always also swaps voxel size.
double _yorigin
Image y-origin (in mm)
void PutPixelSize(double, double, double)
Voxel dimensions put access.
Definition: BaseImage.h:982
double TSize() const
Returns the size of a voxel in the t-direction.
Definition: BaseImage.h:946
GenericImage< BinaryPixel > BinaryImage
Binary image as used for masks (0: off, otherwise: on)
Definition: BaseImage.h:52
double _dy
Voxel y-dimensions (in mm)
VoxelType Get(int) const
Get pixel value at voxel with given index.
Definition: BaseImage.h:1719
void PutTSize(double)
Set temporal voxel size, i.e., to zero for vector field and non-zero for temporal sequence...
Definition: BaseImage.h:976
virtual void ReflectY(bool modify_axes=false)=0
Reflect image along y.
double GetXSize() const
Returns the size of a voxel in the x-direction.
Definition: BaseImage.h:952
double GetTSize() const
Returns the size of a voxel in the t-direction.
Definition: BaseImage.h:970
int T() const
Returns the number of voxels in the t-direction.
Definition: BaseImage.h:892
Superior to Inferior.
Definition: BaseImage.h:90
bool IsNextToForeground(int) const
Whether at least one neighboring voxel is inside the finite foreground region.
Definition: BaseImage.h:1696
int NumberOfVoxels() const
Returns the total number of voxels.
Definition: BaseImage.h:862
virtual void PutAsDouble(int, double)
Function for pixel put access.
Definition: BaseImage.h:1301
double XSize() const
Returns the size of a voxel in the x-direction.
Definition: BaseImage.h:928
VoxelType Get(int) const
Function for pixel get access.
Definition: GenericImage.h:573
double _z
z coordinate of Point
Definition: Point.h:48
virtual void ReflectX(bool modify_axes=false)=0
Reflect image along x.
void IndexToLattice(int, int *, int *, int *=NULL, int *=NULL) const
Get Index from Lattice.
void IndexToVoxel(int, int &, int &) const
Function to convert index to pixel coordinates.
Definition: BaseImage.h:1138
GenericImage< double > WorldCoordsImage
FIXME: Use double3 as voxel type instead.
Definition: BaseImage.h:58
Posterior to Anterior.
Definition: BaseImage.h:87
int _x
Image x-dimension (in voxels)
bool _bgSet
Whether a background value was set.
Definition: BaseImage.h:126
bool IsInside(int) const
Whether voxel index is within finite image domain.
virtual void SwapYT(bool modify_axes=true)=0
Swap y and t axis.
Matrix _matI2W
Transformation matrix from image coordinates to (transformed) world coordinates.
Definition: BaseImage.h:105
virtual void GetMinMaxAsDouble(double &, double &) const
Minimum and maximum pixel values get accessor.
virtual void FlipXZ(bool modify_origin=false)=0
Flip x and z axis, always also swaps voxel size.
double _y
y coordinate of Point
Definition: Point.h:47
void GetOrientation(double *, double *, double *=NULL) const
Get image x- and y-axis and z-axis.
Definition: BaseImage.h:1103
int GetZ() const
Returns the number of voxels in the z-direction.
Definition: BaseImage.h:916
int CenterOfForeground(Point &center) const
bool IsInFOV(double, double, double)
Returns true if point is within the field of view of image.
Definition: BaseImage.h:1274
bool IsBoundary(int) const
Whether voxel index is at boundary of finite image domain.
virtual void SwapXY(bool modify_axes=true)=0
Swap x and y axis.
virtual void ReflectT(bool modify_axes=false)=0
Reflect image along t.
bool IsBoundary(int) const
Whether voxel index is at boundary of finite image domain.
Definition: BaseImage.h:1515
Left to Right.
Definition: BaseImage.h:85
double _dx
Voxel x-dimensions (in mm)
int NumberOfSpatialVoxels() const
Returns the total number of spatial voxels.
Definition: BaseImage.h:868
ImageAttributes ForegroundDomain(int i1, int j1, int k1, int i2, int j2, int k2, bool orthogonal=true) const
BaseImage Image
Alternative/backwards compatible type name.
Definition: BaseImage.h:828
int GetScalarTypeSize() const
Definition: BaseImage.h:1788
OrientationCode
Orientation codes (same as defined in nifti1_io.h, e.g., NIFTI_L2R)
Definition: BaseImage.h:82
void ClearMask(bool=false)
Clear mask upon n-th call after n preceeding InitializeMask calls.
int Z() const
Returns the number of voxels in the z-direction.
Definition: BaseImage.h:886
const Matrix & GetImageToWorldMatrix() const
Return transformation matrix for image to world coordinates.
Definition: BaseImage.h:1244
double YSize() const
Returns the size of a voxel in the y-direction.
Definition: BaseImage.h:934
void PutTOrigin(double)
Put temporal origin.
Definition: BaseImage.h:1076
double _yaxis[3]
Direction of y-axis.
void BoundingBox(int &, int &, int &, int &) const
Get 2D bounding box of image foreground.