#include "itkOpenCVImageBridge.h"
ITK的官网例子:
#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkOpenCVImageBridge.h"
#include "cv.h"
#include "opencv2/opencv.hpp" // cv::imwrite
int main()
{
constexpr unsigned int Dimension = 2;
using PixelType = unsigned char;
using ImageType = itk::Image< PixelType, Dimension >;
using ReaderType = itk::ImageFileReader< ImageType >;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName(filename);
try
{
reader->Update();
}
catch( itk::ExceptionObject & error )
{
std::cerr << "Error: " << error << std::endl;
return EXIT_FAILURE;
}
cv::Mat img = itk::OpenCVImageBridge::ITKImageToCVMat< ImageType >( reader->GetOutput() );
imshow("img",img);
return EXIT_SUCCESS;
}
同理:其他的相关的转化方法也有: