NifTK  16.4.1 - 0798f20
CMIC's Translational Medical Imaging Platform
niftkUndistortion.h
Go to the documentation of this file.
1 /*=============================================================================
2 
3  NifTK: A software platform for medical image computing.
4 
5  Copyright (c) University College London (UCL). All rights reserved.
6 
7  This software is distributed WITHOUT ANY WARRANTY; without even
8  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
9  PURPOSE.
10 
11  See LICENSE.txt in the top level directory for details.
12 
13 =============================================================================*/
14 
15 #ifndef Undistortion_h
16 #define Undistortion_h
17 
18 #include "niftkOpenCVExports.h"
19 #include <mitkDataStorage.h>
20 #include <mitkCameraIntrinsics.h>
21 #include <opencv2/core/types_c.h>
22 #include <mitkImage.h>
23 
24 
25 namespace niftk
26 {
27 
67 {
68 public:
69  static const char* s_ImageIsUndistortedPropertyName; // mitk::BoolProperty
70 
71  // FIXME: this one should go to our calibration class/module, not here
72  static const char* s_CameraCalibrationPropertyName; // mitk::CameraIntrinsicsProperty
73  // FIXME: i dont think this is the best place to keep these. i'm up for suggestions!
74  static const char* s_ImageIsRectifiedPropertyName; // mitk::BoolProperty
75  static const char* s_StereoRigTransformationPropertyName; // niftk::MatrixProperty
76 
77  // used for stereo-rig transformation, i.e. between left and right camera
78  typedef mitk::GenericProperty<itk::Matrix<float, 4, 4> > MatrixProperty;
79 
80 public:
85  Undistortion(const mitk::DataNode::Pointer& node);
86 
90  Undistortion(const mitk::Image::Pointer& image);
91 
92  virtual ~Undistortion();
93 
94 public:
95  // loads calibration from a text file (not the opencv xml format!).
96  // if filename is empty then it will dream up some parameters for the given image.
97  static void LoadIntrinsicCalibration(const std::string& filename, mitk::DataNode::Pointer node);
98  static void LoadIntrinsicCalibration(const std::string& filename, const mitk::Image::Pointer& img);
99  static void LoadStereoRig(const std::string& filename, mitk::DataNode::Pointer node);
100  static void LoadStereoRig(const std::string& filename, mitk::Image::Pointer img);
101  static bool NeedsToLoadIntrinsicCalib(const std::string& filename, const mitk::DataNode::Pointer& node);
102  static bool NeedsToLoadIntrinsicCalib(const std::string& filename, const mitk::Image::Pointer& image);
103  static bool NeedsToLoadStereoRigExtrinsics(const std::string& filename, const mitk::DataNode::Pointer& node);
104  static bool NeedsToLoadStereoRigExtrinsics(const std::string& filename, const mitk::Image::Pointer& image);
105 
109  static void CopyImagePropsIfNecessary(const mitk::DataNode::Pointer source, mitk::Image::Pointer target);
110 
111 
119  virtual void Run(const mitk::DataNode::Pointer& output);
120 
125  virtual void Run(const mitk::Image::Pointer& output);
126 
134  void PrepareOutput(mitk::Image::Pointer& output);
135 
136 protected:
142  void ValidateInput();
143 
150  virtual void Process(const IplImage* input, IplImage* output, bool recomputeCache);
151 
152 protected:
153 
154  static bool NeedsToLoadImageProperty(const std::string& fileName,
155  const std::string& propertyName,
156  const mitk::Image::Pointer& image);
157 
158  // the node that this class is to operate on
159  mitk::DataNode::Pointer m_Node;
160  // the image attached to our node
161  mitk::Image::Pointer m_Image;
162  // the intrinsic parameters belonging to the image
163  mitk::CameraIntrinsics::Pointer m_Intrinsics;
164 
165  // cached for repeated use in Process()
166  IplImage* m_MapX;
167  IplImage* m_MapY;
169 };
170 
172 {
173 public:
174 
175  struct WorkItem
176  {
178  mitk::Image::Pointer m_InputImage;
179  mitk::Image::Pointer m_OutputImage;
182  };
183 
184  std::vector<WorkItem> m_Queue;
185 
186  void Run();
187 
188 };
189 
190 
191 
192 
193 } // namespace
194 
195 
196 #endif // niftk_Undistortion_h
Definition: niftkUndistortion.h:175
bool m_RecomputeCache
Definition: niftkUndistortion.h:168
std::string m_OutputNodeName
Definition: niftkUndistortion.h:180
niftk::Undistortion * m_Proc
Definition: niftkUndistortion.h:177
GLenum GLenum GLenum input
Definition: glew.h:12016
Definition: niftkUndistortion.h:171
GLenum GLsizei GLenum GLenum const GLvoid * image
Definition: glew.h:4052
mitk::Image::Pointer m_Image
Definition: niftkUndistortion.h:161
IplImage * m_MapY
Definition: niftkUndistortion.h:167
mitk::Image::Pointer m_OutputImage
Definition: niftkUndistortion.h:179
std::vector< WorkItem > m_Queue
Definition: niftkUndistortion.h:184
static const char * s_StereoRigTransformationPropertyName
Definition: niftkUndistortion.h:75
static const char * s_CameraCalibrationPropertyName
Definition: niftkUndistortion.h:72
static const char * s_ImageIsUndistortedPropertyName
Definition: niftkUndistortion.h:69
Definition: niftkUndistortion.h:66
#define NIFTKOPENCV_EXPORT
Definition: niftkSequentialCpuQds.h:27
IplImage * m_MapX
Definition: niftkUndistortion.h:166
mitk::GenericProperty< itk::Matrix< float, 4, 4 > > MatrixProperty
Definition: niftkUndistortion.h:78
std::string m_InputNodeName
Definition: niftkUndistortion.h:181
static const char * s_ImageIsRectifiedPropertyName
Definition: niftkUndistortion.h:74
GLint GLvoid * img
Definition: glew.h:1369
mitk::CameraIntrinsics::Pointer m_Intrinsics
Definition: niftkUndistortion.h:163
mitk::DataNode::Pointer m_Node
Definition: niftkUndistortion.h:159
mitk::Image::Pointer m_InputImage
Definition: niftkUndistortion.h:178
Definition: niftkExceptionObject.h:21
GLsizei const GLcharARB ** string
Definition: glew.h:5194
GLsizei GLsizei GLchar * source
Definition: glew.h:1816
GLenum target
Definition: glew.h:5584