Hi everyone,
I would like to convert simpleITK images to OpenCV images and vice versa.
The conversion from OpenCV to ITK is working fine like the example below:
cv::Mat movingImage = cv::imread(moving_image_path);
cv::Mat fixedImage = cv::imread(fixed_image_path);
cvMovingImage.convertTo(cvMovingImage, CV_32FC1, 1.0/255.0);
cvFixedImage.convertTo(cvFixedImage, CV_32FC1, 1.0/255.0);
typedef itk::Image<float, 2> ImageType;
ImageType::Pointer itkMovingImage = ImageType::New();
ImageType::Pointer itkFixedImage = ImageType::New();
itkMovingImage = itk::OpenCVImageBridge::CVMatToITKImage<ImageType>(cvMovingImage);
itkFixedImage = itk::OpenCVImageBridge::CVMatToITKImage<ImageType>(cvFixedImage);
m_fixedImage = sitk::Image(itkFixedImage);
m_movingImage = sitk::Image(itkMovingImage);
Then, I would like to convert the output from the sitk::CheckerBoard function to OpenCV image and at this moment I am getting some errors.
auto image = sitk::CheckerBoard(m_fixedImage, m_movingImage, {10,10,4});
sitk::Show(image, "SimpleITK Fusion", false);
// Convert ITK image image to opencv image
cv::Mat resultImage = itk::OpenCVImageBridge::ITKImageToCVMat(&image);
cv::imshow("ITK conversion", resultImage);
cv::waitKey(0);
This is the error that I am getting:
ITK/Modules/Video/BridgeOpenCV/include/itkOpenCVImageBridge.hxx:278:9: error: no type named ‘PixelType’ in ‘using ImageType = class itk::simple::Image’ {aka ‘class itk::simple::Image’}
using InputPixelType = typename ImageType::PixelType;
^~~~~~~~~~~~~~
ITK/Modules/Video/BridgeOpenCV/include/itkOpenCVImageBridge.hxx:279:9: error: no type named ‘PixelType’ in ‘class itk::simple::Image’
using ValueType = typename itk::NumericTraits<InputPixelType>::ValueType;
^~~
What is wrong with this portion of the code?
Thanks