[SOLVED] Writing a transform to file

Hi,

I want to write a transform to a file. The file name is “FinalTransform.tfm”.

The relevant code snippet is:

#include <itkTransformFileWriter.h>
using TransformFileWriterType = itk::TransformFileWriter;
[...]
auto TransformWriter = TransformFileWriterType::New();
TransformWriter->SetFileName("FinalTransform.tfm");
TransformWriter->SetInput(NReg->GetTransform());
try
{
  TransformWriter->Update();
}
catch (itk::ExceptionObject &EO)
{
  std::cout << "Write transform error" << std::endl;
  EO.Print(std::cout);
  return EXIT_FAILURE;
}

When I run the programm I got following error:

itk::ExceptionObject (00000000001BDB90)
Location: "unknown"
File: C:\TK\src\ITK-413\Modules\IO\TransformBase\include\itkTransformFileWriter.hxx
Line 167
Description: itk::ERROR: TransformFileWriterTemplate (00000000045D19C0): Could not create IO object for writing FinalTransform.tfm
  Tried to create one of the following:
    MatlabTransformIOTemplate
    MatlabTransformIOTemplate
  You probably failed to set a file suffix, or set the suffix to an unsupported type.

The CMakeLists.txt looks like:

cmake_minimum_required(VERSION 3.10)
project(Reg2D3D)

find_package(ITK REQUIRED COMPONENTS ORA RTK ITKIOTransformBase ITKIOTransformMatlab ITKIONRRD)
include(${ITK_USE_FILE})

set(SRCS
	Reg2D3D.cxx
)

add_executable(Reg2D3D ${SRCS})
target_link_libraries(Reg2D3D ${ITK_LIBRARIES})

Note: If I do not include the ITKIOTransformMatlab component it wont compile (error: LNK2019).
The components ORA and RTK are two external modules that work fine with ITK.

I failed to understand why I suddenly need a Matlab transform object. None of the projects are connected to Matlab in any way.
Why are not the usual transform file extensions supported anymore?

Hello Gordian,

The “tfm” transform extensions is support by the class ITK text format, which is in the “ITKIOTransformInsightLegacy” module. From the error message you can see that this factory is not registered.

In your find_package CMake call you are selecting the ITK components which you want to use, which does NOT include the above TransformIO. If you include the “ITKTransformIO” meta component then all configure TransformIO will be registered so that you can use them in your program.

1 Like

Thanks. Solved my problem.

I guess same goes for the IO for images.