<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1">
<title></title>
</head>
<body text="#000000" bgcolor="#ffffff">
Hi @all,<br>
<br>
when I try to run the deformableRegistration1 example, it <br>
crashes with the following message:<br>
<br>
Microsoft Windows XP [Version 5.1.2600]<br>
(C) Copyright 1985-2001 Microsoft Corp.<br>
<br>
<font color="#ff0000">C:\DFG-Projekt\RIP\build\RelWithDebInfo>registrationImagingPlattform
params.txt<br>
Reading config file...params.txt<br>
Example configured. E 0 rho 0<br>
reading moving<br>
reading fixed<br>
beginning level 0<br>
scaling 1<br>
scaling 1<br>
scaling 1<br>
ElementsPerDim 512 512 52<br>
File not found!<br>
applying loads<br>
<br>
no landmark file specified.<br>
num of LM loads 0<br>
landmarks done<br>
allocating deformation field<br>
load sizes [512, 512, 52] image [512, 512, 52]<br>
load sizes [512, 512, 52] image [512, 512, 52]<br>
energy 0<br>
<br>
This application has requested the Runtime to terminate it in an
unusual way.<br>
Please contact the application's support team for more information.</font><br>
<br>
<br>
I use the following configurations file:<br>
<br>
<font color="#3333ff">% Note: the paths in the parameters assume you
have the traditional<br>
% ITK file hierarchy as shown below:<br>
%<br>
% ITK/Insight/Examples/Registration/DeformableRegistration1.cxx<br>
% ITK/Insight/Examples/Data/RatLungSlice*<br>
% ITK/Insight-Bin/bin/DeformableRegistration1<br>
%<br>
% ---------------------------------------------------------<br>
% Parameters for the single- or multi-resolution techniques<br>
% ---------------------------------------------------------<br>
1 % Number of levels in the multi-res pyramid (1 = single-res)<br>
1 % Highest level to use in the pyramid<br>
1 1 % Scaling at lowest level of pyramid<br>
8 % Number of pixels per element<br>
1.e4 % Elasticity (E)<br>
1.e4 % Density x capacity (RhoC)<br>
1 % Image energy scaling (gamma) - sets gradient step size<br>
2 % NumberOfIntegrationPoints<br>
1 % WidthOfMetricRegion<br>
20 % MaximumIterations<br>
% -------------------------------<br>
% Parameters for the registration<br>
% -------------------------------<br>
0 0.99 % Similarity metric (0=mean sq, 1 = ncc, 2=pattern int, 3=MI,
5=demons)<br>
1.0 % Alpha<br>
0 % DescentDirection (1 = max, 0 = min)<br>
0 % DoLineSearch (0=never, 1=always, 2=if needed)<br>
1.e1 % TimeStep<br>
0.5 % Landmark variance<br>
0 % Employ regridding / enforce diffeomorphism ( >= 1 -> true)<br>
% ----------------------------------<br>
% Information about the image inputs<br>
% ----------------------------------<br>
512 % Nx (image x dimension)<br>
512 % Ny (image y dimension)<br>
52 % Nz (image z dimension - not used if 2D)<br>
rigid_reg_CT1.hdr % ReferenceFileName<br>
CT.hdr % TargetFileName<br>
<br>
% -------------------------------------------------------------------<br>
% The actions below depend on the values of the flags preceding them.<br>
% For example, to write out the displacement fields, you have to set<br>
% the value of WriteDisplacementField to 1.<br>
% -------------------------------------------------------------------<br>
0 % UseLandmarks? - read the file name below if this is true<br>
- % LandmarkFileName<br>
./RatLung_result % ResultsFileName (prefix only)<br>
0 % WriteDisplacementField?<br>
./RatLung_disp % DisplacementsFileName (prefix only)<br>
0 % ReadMeshFile?<br>
- % MeshFileName<br>
END<br>
<br>
<font color="#000000">I also changed the code of the example a little
bit to work in 3D (see the following part of<br>
the message).<br>
I hope that I didn't do a mistake here.<br>
Help would be very appreciated to find the cause of this error.<br>
I use ITK Version 2.4.0 and compile in release with deb.inf. mode.<br>
<br>
Best regards,<br>
Markus<br>
<br>
<br>
<br>
<br>
<br>
/*=========================================================================<br>
<br>
Program: Insight Segmentation & Registration Toolkit<br>
Module: $RCSfile: DeformableRegistration1.cxx,v $<br>
Language: C++<br>
Date: $Date: 2005/11/19 16:31:50 $<br>
Version: $Revision: 1.32 $<br>
<br>
Copyright (c) Insight Software Consortium. All rights reserved.<br>
See ITKCopyright.txt or <a class="moz-txt-link-freetext" href="http://www.itk.org/HTML/Copyright.htm">http://www.itk.org/HTML/Copyright.htm</a> for
details.<br>
<br>
This software is distributed WITHOUT ANY WARRANTY; without even <br>
the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR <br>
PURPOSE. See the above copyright notices for more information.<br>
<br>
=========================================================================*/<br>
#if defined(_MSC_VER)<br>
#pragma warning ( disable : 4786 )<br>
#endif<br>
<br>
<br>
#include "itkImageFileReader.h" <br>
#include "itkImageFileWriter.h" <br>
<br>
#include "itkRescaleIntensityImageFilter.h"<br>
#include "itkHistogramMatchingImageFilter.h"<br>
<br>
// Software Guide : BeginLatex<br>
//<br>
// The finite element (FEM) library within the Insight Toolkit can be<br>
// used to solve deformable image registration problems. The first
step in<br>
// implementing a FEM-based registration is to include the appropriate<br>
// header files.<br>
//<br>
// \index{Registration!Finite Element-Based}<br>
//<br>
// Software Guide : EndLatex <br>
<br>
<br>
// Software Guide : BeginCodeSnippet<br>
#include "itkFEM.h"<br>
#include "itkFEMRegistrationFilter.h"<br>
<br>
// Software Guide : EndCodeSnippet<br>
<br>
//#include "itkFEMFiniteDifferenceFunctionLoad.h"<br>
<br>
<br>
// Software Guide : BeginLatex<br>
//<br>
// Next, we use \code{typedef}s to instantiate all necessary classes.
We<br>
// define the image and element types we plan to use to solve a<br>
// two-dimensional registration problem. We define multiple element<br>
// types so that they can be used without recompiling the code.<br>
//<br>
// Software Guide : EndLatex <br>
<br>
<br>
// Software Guide : BeginCodeSnippet<br>
typedef itk::Image<unsigned char, 2>
fileImageType;<br>
typedef itk::Image<float, 2>
ImageType;<br>
typedef itk::fem::Element2DC0LinearQuadrilateralMembrane ElementType;<br>
typedef itk::fem::Element2DC0LinearTriangularMembrane ElementType2;<br>
// Software Guide : EndCodeSnippet<br>
<br>
<br>
// Software Guide : BeginLatex<br>
//<br>
// Note that in order to solve a three-dimensional registration<br>
// problem, we would simply define 3D image and element types in lieu<br>
// of those above. The following declarations could be used for a 3D<br>
// problem:<br>
//<br>
// SoftwareGuide : EndLatex<br>
<br>
<br>
// SoftwareGuide : BeginCodeSnippet<br>
typedef itk::Image<short, 3>
fileImage3DType;<br>
typedef itk::Image<short, 3>
Image3DType;<br>
typedef itk::fem::Element3DC0LinearHexahedronMembrane Element3DType;<br>
typedef itk::fem::Element3DC0LinearTetrahedronMembrane Element3DType2;<br>
// Software Guide : EndCodeSnippet<br>
<br>
<br>
// Software Guide : BeginLatex<br>
// <br>
// Here, we instantiate the load types and explicitly template the<br>
// load implementation type. We also define visitors that allow the<br>
// elements and loads to communicate with one another. <br>
//<br>
// Software Guide : EndLatex<br>
<br>
<br>
//typedef itk::fem::ImageMetricLoad<ImageType,ImageType>
ImageLoadType;<br>
<br>
// Software Guide : BeginCodeSnippet<br>
<br>
typedef
itk::fem::FiniteDifferenceFunctionLoad<Image3DType,Image3DType>
ImageLoadType;<br>
template class
itk::fem::ImageMetricLoadImplementation<ImageLoadType>;<br>
<br>
typedef Element3DType::LoadImplementationFunctionPointer LoadImpFP;<br>
typedef Element3DType::LoadType
ElementLoadType;<br>
<br>
typedef Element3DType2::LoadImplementationFunctionPointer LoadImpFP2;<br>
typedef Element3DType2::LoadType
ElementLoadType2;<br>
<br>
typedef itk::fem::VisitorDispatcher<Element3DType,ElementLoadType,
LoadImpFP> <br>
DispatcherType;<br>
<br>
typedef itk::fem::VisitorDispatcher<Element3DType2,ElementLoadType2,
LoadImpFP2> <br>
DispatcherType2;<br>
// Software Guide : EndCodeSnippet<br>
<br>
<br>
// Software Guide : BeginLatex<br>
//<br>
// Once all the necessary components have been instantiated, we can<br>
// instantiate the \doxygen{FEMRegistrationFilter}, which depends on
the<br>
// image input and output types.<br>
//<br>
// Software Guide : EndLatex<br>
<br>
<br>
// Software Guide : BeginCodeSnippet<br>
typedef itk::fem::FEMRegistrationFilter<Image3DType,Image3DType>
RegistrationType;<br>
// Software Guide : EndCodeSnippet<br>
<br>
<br>
int main(int argc, char *argv[])<br>
{<br>
char *paramname;<br>
if ( argc < 2 )<br>
{<br>
std::cout << "Parameter file name missing" << std::endl;<br>
std::cout << "Usage: " << argv[0] << "
param.file" << std::endl;<br>
return -1;<br>
} <br>
else <br>
{ <br>
paramname=argv[1]; <br>
}<br>
<br>
<br>
// Software Guide : BeginLatex<br>
// <br>
// The \doxygen{fem::ImageMetricLoad} must be registered before it<br>
// can be used correctly with a particular element type. An example<br>
// of this is shown below for ElementType. Similar<br>
// definitions are required for all other defined element types.<br>
//<br>
// Software Guide : EndLatex<br>
<br>
// Register the correct load implementation with the element-typed
visitor dispatcher. <br>
{<br>
// Software Guide : BeginCodeSnippet<br>
Element3DType::LoadImplementationFunctionPointer fp = <br>
&itk::fem::ImageMetricLoadImplementation<ImageLoadType>::ImplementImageMetricLoad;<br>
DispatcherType::RegisterVisitor((ImageLoadType*)0,fp);<br>
// Software Guide : EndCodeSnippet <br>
}<br>
{<br>
Element3DType2::LoadImplementationFunctionPointer fp =<br>
&itk::fem::ImageMetricLoadImplementation<ImageLoadType>::ImplementImageMetricLoad;<br>
DispatcherType2::RegisterVisitor((ImageLoadType*)0,fp);<br>
}<br>
<br>
<br>
// Software Guide : BeginLatex<br>
// <br>
// In order to begin the registration, we declare an instance of the<br>
// FEMRegistrationFilter. For simplicity, we will call<br>
// it \code{registrationFilter}.<br>
// <br>
// Software Guide : EndLatex<br>
<br>
// Software Guide : BeginCodeSnippet<br>
RegistrationType::Pointer registrationFilter =
RegistrationType::New(); <br>
// Software Guide : EndCodeSnippet<br>
<br>
<br>
// Software Guide : BeginLatex<br>
// <br>
// Next, we call \code{registrationFilter->SetConfigFileName()} to
read the parameter<br>
// file containing information we need to set up the registration<br>
// filter (image files, image sizes, etc.). A sample parameter file
is shown at the end of this<br>
// section, and the individual components are labeled. <br>
//<br>
// Software Guide : EndLatex<br>
<br>
<br>
// Attempt to read the parameter file, and exit if an error occurs<br>
registrationFilter->SetConfigFileName(paramname);<br>
if ( !registrationFilter->ReadConfigFile( <br>
(registrationFilter->GetConfigFileName()).c_str() ) ) <br>
{ <br>
return -1; <br>
}<br>
<br>
// Read the image files<br>
typedef itk::ImageFileReader< fileImage3DType >
FileSourceType;<br>
typedef fileImageType::PixelType PixType;<br>
<br>
FileSourceType::Pointer movingfilter = FileSourceType::New();<br>
movingfilter->SetFileName(
"rigid_reg_ct1.hdr"/*(registrationFilter->GetMovingFile()).c_str()*/
);<br>
FileSourceType::Pointer fixedfilter = FileSourceType::New();<br>
fixedfilter->SetFileName(
"ct.hdr"/*(registrationFilter->GetFixedFile()).c_str()*/ );<br>
std::cout << " reading moving " <<
registrationFilter->GetMovingFile() << std::endl;<br>
std::cout << " reading fixed " <<
registrationFilter->GetFixedFile() << std::endl;<br>
<br>
<br>
try<br>
{<br>
movingfilter->Update();<br>
}<br>
catch( itk::ExceptionObject & e )<br>
{<br>
std::cerr << "Exception caught during reference file reading
" << std::endl;<br>
std::cerr << e << std::endl;<br>
return -1;<br>
}<br>
try<br>
{<br>
fixedfilter->Update();<br>
}<br>
catch( itk::ExceptionObject & e )<br>
{<br>
std::cerr << "Exception caught during target file reading "
<< std::endl;<br>
std::cerr << e << std::endl;<br>
return -1;<br>
}<br>
<br>
<br>
// Rescale the image intensities so that they fall between 0 and 255<br>
typedef
itk::RescaleIntensityImageFilter<fileImage3DType,Image3DType>
FilterType;<br>
FilterType::Pointer movingrescalefilter = FilterType::New();<br>
FilterType::Pointer fixedrescalefilter = FilterType::New();<br>
<br>
movingrescalefilter->SetInput(movingfilter->GetOutput());<br>
fixedrescalefilter->SetInput(fixedfilter->GetOutput());<br>
<br>
const double desiredMinimum = 0.0;<br>
const double desiredMaximum = 255.0;<br>
<br>
movingrescalefilter->SetOutputMinimum( desiredMinimum );<br>
movingrescalefilter->SetOutputMaximum( desiredMaximum );<br>
movingrescalefilter->UpdateLargestPossibleRegion();<br>
fixedrescalefilter->SetOutputMinimum( desiredMinimum );<br>
fixedrescalefilter->SetOutputMaximum( desiredMaximum );<br>
fixedrescalefilter->UpdateLargestPossibleRegion();<br>
<br>
<br>
// Histogram match the images<br>
typedef
itk::HistogramMatchingImageFilter<Image3DType,Image3DType>
HEFilterType;<br>
HEFilterType::Pointer IntensityEqualizeFilter = HEFilterType::New();<br>
<br>
IntensityEqualizeFilter->SetReferenceImage(
fixedrescalefilter->GetOutput() );<br>
IntensityEqualizeFilter->SetInput(
movingrescalefilter->GetOutput() );<br>
IntensityEqualizeFilter->SetNumberOfHistogramLevels( 100);<br>
IntensityEqualizeFilter->SetNumberOfMatchPoints( 15);<br>
IntensityEqualizeFilter->ThresholdAtMeanIntensityOn();<br>
IntensityEqualizeFilter->Update();<br>
<br>
registrationFilter->SetFixedImage(fixedrescalefilter->GetOutput());<br>
registrationFilter->SetMovingImage(IntensityEqualizeFilter->GetOutput());<br>
<br>
<br>
itk::ImageFileWriter<Image3DType>::Pointer writer;<br>
writer = itk::ImageFileWriter<Image3DType>::New();<br>
std::string ofn="fixed.hdr";<br>
writer->SetFileName(ofn.c_str());<br>
writer->SetInput(registrationFilter->GetFixedImage() ); <br>
writer->Write();<br>
<br>
ofn="moving.hdr";<br>
itk::ImageFileWriter<Image3DType>::Pointer writer2;<br>
writer2 = itk::ImageFileWriter<Image3DType>::New();<br>
writer2->SetFileName(ofn.c_str());<br>
writer2->SetInput(registrationFilter->GetMovingImage() ); <br>
writer2->Write();<br>
<br>
<br>
<br>
<br>
// Software Guide : BeginLatex<br>
// <br>
// In order to initialize the mesh of elements, we must first create<br>
// ``dummy'' material and element objects and assign them to the<br>
// registration filter. These objects are subsequently used to<br>
// either read a predefined mesh from a file or generate a mesh using<br>
// the software. The values assigned to the fields within the<br>
// material object are arbitrary since they will be replaced with<br>
// those specified in the parameter file. Similarly, the element<br>
// object will be replaced with those from the desired mesh.<br>
// <br>
// Software Guide : EndLatex<br>
<br>
// Software Guide : BeginCodeSnippet<br>
// Create the material properties<br>
itk::fem::MaterialLinearElasticity::Pointer m;<br>
m = itk::fem::MaterialLinearElasticity::New();<br>
m->GN = 0; // Global number of the material<br>
m->E = registrationFilter->GetElasticity(); // Young's modulus
-- used in the membrane<br>
m->A = 1.0; // Cross-sectional area<br>
m->h = 1.0; // Thickness<br>
m->I = 1.0; // Moment of inertia<br>
m->nu = 0.; // Poisson's ratio -- DONT CHOOSE 1.0!!<br>
m->RhoC = 1.0; // Density<br>
<br>
// Create the element type <br>
Element3DType::Pointer e1=Element3DType::New();<br>
e1->m_mat=dynamic_cast<itk::fem::MaterialLinearElasticity*>(
m );<br>
registrationFilter->SetElement(e1);<br>
registrationFilter->SetMaterial(m);<br>
// Software Guide : EndCodeSnippet<br>
<br>
<br>
// Software Guide : BeginLatex<br>
//<br>
// Now we are ready to run the registration:<br>
//<br>
// Software Guide : EndLatex<br>
<br>
// Software Guide : BeginCodeSnippet<br>
registrationFilter->RunRegistration();<br>
// Software Guide : EndCodeSnippet<br>
<br>
<br>
// Software Guide : BeginLatex<br>
//<br>
// To output the image resulting from the registration, we can call<br>
// \code{WriteWarpedImage()}. The image is written in floating point<br>
// format.<br>
//<br>
// Software Guide : EndLatex<br>
<br>
// Software Guide : BeginCodeSnippet<br>
registrationFilter->WriteWarpedImage(<br>
(registrationFilter->GetResultsFileName()).c_str());<br>
// Software Guide : EndCodeSnippet<br>
<br>
// Software Guide : BeginLatex<br>
//<br>
// We can also output the displacement fields resulting from the<br>
// registration, we can call \code{WriteDisplacementField()} with the<br>
// desired vector component as an argument. For a $2D$ registration,<br>
// you would want to write out both the $x$ and $y$ displacements, and<br>
// this requires two calls to the aforementioned function.<br>
//<br>
// Software Guide : EndLatex<br>
<br>
// Software Guide : BeginCodeSnippet<br>
if (registrationFilter->GetWriteDisplacements()) <br>
{<br>
//registrationFilter->WriteDisplacementField(0);<br>
//registrationFilter->WriteDisplacementField(1);<br>
// If this were a 3D example, you might also want to call this line:<br>
// registrationFilter->WriteDisplacementField(2);<br>
<br>
// We can also write it as a multicomponent vector field<br>
registrationFilter->WriteDisplacementFieldMultiComponent();<br>
}<br>
// Software Guide : EndCodeSnippet<br>
<br>
// This is a documented sample parameter file that can be used with<br>
// this deformable registration example.<br>
//<br>
// ../Data/FiniteElementRegistrationParameters1.txt<br>
//<br>
<br>
return 0;<br>
}<br>
<br>
<br>
<br>
</font></font>
</body>
</html>