概述
#include <iostream>
#include "elastixlib.h"
#include "itkParameterFileParser.h"
#include "itkImageFileWriter.h"
#include "itkImageFileReader.h"
int main() {
const unsigned int Dimension = 3;
typedef short PixelType;
typedef itk::Image<PixelType, Dimension> ImageType;
typedef itk::ImageFileReader<ImageType> ReaderType;
ReaderType::Pointer fixReader = ReaderType::New();
ReaderType::Pointer movReader = ReaderType::New();
fixReader->SetFileName("E:/registration/input/fix.mhd");
movReader->SetFileName("E:/registration/input/mov.mhd");
try
{
fixReader->Update();
movReader->Update();
}
catch (itk::ExceptionObject &ex)
{
std::cout << ex << std::endl;
return 0;
}
using namespace elastix;
typedef ELASTIX::ParameterMapType RegistrationParametersType;
typedef itk::ParameterFileParser ParserType;
// Create parser for transform parameters text file.
ParserType::Pointer file_parser = ParserType::New();
// Try parsing transform parameters text file.
file_parser->SetParameterFileName("E:/registration/input/parameters.txt");
try
{
file_parser->ReadParameterFile();
}
catch (itk::ExceptionObject & e)
{
std::cout << e.what() << std::endl;
// Do some error handling!
}
// Retrieve parameter settings as map.
RegistrationParametersType parameters = file_parser->GetParameterMap();
typedef std::vector<RegistrationParametersType> RegistrationParametersContainerType;
ELASTIX* elastix = new ELASTIX();
int error = 0;
try
{
error = elastix->RegisterImages(
static_cast<typename itk::DataObject::Pointer>(fixReader->GetOutput()),
static_cast<typename itk::DataObject::Pointer>(movReader->GetOutput()),
parameters, // Parameter map read in previous code
"E:/registration/output", // Directory where output is written, if enabled
true, // Enable/disable writing of elastix.log
true, // Enable/disable output to console
0, // Provide fixed image mask (optional, 0 = no mask)
0 // Provide moving image mask (optional, 0 = no mask)
);
}
catch (itk::ExceptionObject &err)
{
// Do some error handling.
}
if (error == 0)
{
if (elastix->GetResultImage().IsNotNull())
{
// Typedef the ITKImageType first...
ImageType * output_image = static_cast<ImageType *>(
elastix->GetResultImage().GetPointer());
}
else
{
// Registration failure. Do some error handling.
}
// Get transform parameters of all registration steps.
RegistrationParametersContainerType transform_parameters
= elastix->GetTransformParameterMapList();
// Clean up memory.
delete elastix;
return 0;
}
}
注:
1、如果图像像素类型与elastix配置文本中像素类型不一致时,会导致图像读取结果为空。
2、图像转换我也搞定了,但是重采样图像一次要五分钟- -?!
最后
以上就是无辜啤酒为你收集整理的ITK使用elastix库作配准的全部内容,希望文章能够帮你解决ITK使用elastix库作配准所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复