NifTK  16.4.1 - 0798f20
CMIC's Translational Medical Imaging Platform
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
niftk::Undistortion Class Reference

Public Types

typedef mitk::GenericProperty
< itk::Matrix< float, 4, 4 > > 
MatrixProperty
 

Public Member Functions

 Undistortion (const mitk::DataNode::Pointer &node)
 
 Undistortion (const mitk::Image::Pointer &image)
 
virtual ~Undistortion ()
 
virtual void Run (const mitk::DataNode::Pointer &output)
 
virtual void Run (const mitk::Image::Pointer &output)
 
void PrepareOutput (mitk::Image::Pointer &output)
 

Static Public Member Functions

static void LoadIntrinsicCalibration (const std::string &filename, mitk::DataNode::Pointer node)
 
static void LoadIntrinsicCalibration (const std::string &filename, const mitk::Image::Pointer &img)
 
static void LoadStereoRig (const std::string &filename, mitk::DataNode::Pointer node)
 
static void LoadStereoRig (const std::string &filename, mitk::Image::Pointer img)
 
static bool NeedsToLoadIntrinsicCalib (const std::string &filename, const mitk::DataNode::Pointer &node)
 
static bool NeedsToLoadIntrinsicCalib (const std::string &filename, const mitk::Image::Pointer &image)
 
static bool NeedsToLoadStereoRigExtrinsics (const std::string &filename, const mitk::DataNode::Pointer &node)
 
static bool NeedsToLoadStereoRigExtrinsics (const std::string &filename, const mitk::Image::Pointer &image)
 
static void CopyImagePropsIfNecessary (const mitk::DataNode::Pointer source, mitk::Image::Pointer target)
 Copies properties from node to image, if they don't already exist on the image. More...
 

Static Public Attributes

static const char * s_ImageIsUndistortedPropertyName = "niftk.ImageIsUndistorted"
 
static const char * s_CameraCalibrationPropertyName = "niftk.CameraCalibration"
 
static const char * s_ImageIsRectifiedPropertyName = "niftk.ImageIsRectified"
 
static const char * s_StereoRigTransformationPropertyName = "niftk.StereoRigTransformation"
 

Protected Member Functions

void ValidateInput ()
 
virtual void Process (const IplImage *input, IplImage *output, bool recomputeCache)
 

Static Protected Member Functions

static bool NeedsToLoadImageProperty (const std::string &fileName, const std::string &propertyName, const mitk::Image::Pointer &image)
 

Protected Attributes

mitk::DataNode::Pointer m_Node
 
mitk::Image::Pointer m_Image
 
mitk::CameraIntrinsics::Pointer m_Intrinsics
 
IplImage * m_MapX
 
IplImage * m_MapY
 
bool m_RecomputeCache
 

Detailed Description

Idea is to create one of these Undistortion objects for a given DataNode or Image, which then does all the magic for computing the undistortion and caches some data. Output, however, is not tied into an instance of the class. Instead it's passed into Run().

How to use. You can pass in any combination of input DataNode or Image and output DataNode or Image. 1) For exmaple: mitk::DataNode::Pointer input = ...; mitk::DataNode::Pointer output = mitk::DataNode::New(); niftk::Undistortion* undist = new niftk::Undistortion(input); undist->Run(output);

2) Another one: mitk::Image::Pointer input = ...; mitk::Image::Pointer output; niftk::Undistortion* undist = new niftk::Undistortion(input); undist->PrepareOutput(output); undist->Run(output);

Either way, the node or image need to have calibration properties. The output object will have these calibrations copied to it as well, including s_ImageIsUndistortedPropertyName. In case both node and its attached image have calibration props then image wins. Also, for consistency sake, both calibration props need to match in this case.

A note about smart pointers: various functions take as parameter something like const mitk::DataNode::Pointer&. This means that the smart-pointer itself is const but the pointed-to object is not! Const is not transitive for smart-pointers! Using const smart-pointers avoids unnecessary ref-count operations (which make stepping through the code rather annoying). If you wanted a const pointed-to object then the parameter would be mitk::DataNode::ConstPointer.

When I wrote this originally, I decided for a non-mitk-smartypants class here, i.e. bare-bones c++ class. Now I can't remember why. Feel free to change it to mitk.

Warning
Only 2D images are tested and supported! Anything else might or might not work, crash, trigger the apocolypse. For 3D what probably happens is that only the very first slice is processed.

Member Typedef Documentation

typedef mitk::GenericProperty<itk::Matrix<float, 4, 4> > niftk::Undistortion::MatrixProperty

Constructor & Destructor Documentation

niftk::Undistortion::Undistortion ( const mitk::DataNode::Pointer &  node)

node should have Image data attached, at least when Run() is called.

Exceptions
std::runtime_errorif node.IsNull()
niftk::Undistortion::Undistortion ( const mitk::Image::Pointer &  image)
Exceptions
std::runtime_errorif image.IsNull()
niftk::Undistortion::~Undistortion ( )
virtual

Member Function Documentation

void niftk::Undistortion::CopyImagePropsIfNecessary ( const mitk::DataNode::Pointer  source,
mitk::Image::Pointer  target 
)
static

Copies properties from node to image, if they don't already exist on the image.

void niftk::Undistortion::LoadIntrinsicCalibration ( const std::string filename,
mitk::DataNode::Pointer  node 
)
static
void niftk::Undistortion::LoadIntrinsicCalibration ( const std::string filename,
const mitk::Image::Pointer &  img 
)
static
void niftk::Undistortion::LoadStereoRig ( const std::string filename,
mitk::DataNode::Pointer  node 
)
static
void niftk::Undistortion::LoadStereoRig ( const std::string filename,
mitk::Image::Pointer  img 
)
static
bool niftk::Undistortion::NeedsToLoadImageProperty ( const std::string fileName,
const std::string propertyName,
const mitk::Image::Pointer &  image 
)
staticprotected
bool niftk::Undistortion::NeedsToLoadIntrinsicCalib ( const std::string filename,
const mitk::DataNode::Pointer &  node 
)
static
bool niftk::Undistortion::NeedsToLoadIntrinsicCalib ( const std::string filename,
const mitk::Image::Pointer &  image 
)
static
bool niftk::Undistortion::NeedsToLoadStereoRigExtrinsics ( const std::string filename,
const mitk::DataNode::Pointer &  node 
)
static
bool niftk::Undistortion::NeedsToLoadStereoRigExtrinsics ( const std::string filename,
const mitk::Image::Pointer &  image 
)
static
void niftk::Undistortion::PrepareOutput ( mitk::Image::Pointer &  output)

You should call this if you use Run(const mitk::Image::Pointer&). If output is null then a new image is allocated. If the dimensions of an existing image are wrong then a new one is allocated too.

Exceptions
std::runtime_errorrethrown from ValidateInput()
void niftk::Undistortion::Process ( const IplImage *  input,
IplImage *  output,
bool  recomputeCache 
)
protectedvirtual

FIXME: presumably this is virtual so that we could derive a gpu version. but then the ipl parameters are no use!

Parameters
recomputeCachetrue image dimensions or type have changed, m_RecomputeCache is passed in (and set to false afterwards, by Run()).
Exceptions
exceptionsif anything is wrong.
void niftk::Undistortion::Run ( const mitk::DataNode::Pointer &  output)
virtual
Warning
You need to call output->Modified() yourself if you want listeners to be notified!
Exceptions
stufffrom ValidateInput().
std::runtime_errorif output is null.
std::runtime_errorif the attached image is zero-size.
Postcondition
If successful, output node will have an image attached of the correct size.
void niftk::Undistortion::Run ( const mitk::Image::Pointer &  output)
virtual

output has to have the same size as input (which you passed in to the constructor). Call PrepareOutput() to make sure.

void niftk::Undistortion::ValidateInput ( )
protected

Check that we have an image to work on, it has the correct depth/channels, etc.

Exceptions
std::runtime_errorif image type is wrong or required properties are missing.
std::runtime_errorif image is zero-size.

Member Data Documentation

mitk::Image::Pointer niftk::Undistortion::m_Image
protected
mitk::CameraIntrinsics::Pointer niftk::Undistortion::m_Intrinsics
protected
IplImage* niftk::Undistortion::m_MapX
protected
IplImage* niftk::Undistortion::m_MapY
protected
mitk::DataNode::Pointer niftk::Undistortion::m_Node
protected
bool niftk::Undistortion::m_RecomputeCache
protected
const char * niftk::Undistortion::s_CameraCalibrationPropertyName = "niftk.CameraCalibration"
static
const char * niftk::Undistortion::s_ImageIsRectifiedPropertyName = "niftk.ImageIsRectified"
static
const char * niftk::Undistortion::s_ImageIsUndistortedPropertyName = "niftk.ImageIsUndistorted"
static
const char * niftk::Undistortion::s_StereoRigTransformationPropertyName = "niftk.StereoRigTransformation"
static

The documentation for this class was generated from the following files: