[Insight-users] Writing BSpline transform with itkTransformFileWriter
Luis Ibanez
luis.ibanez at kitware.com
Tue Mar 16 18:58:03 EDT 2010
Hi Albert
Thanks for your detailed report.
Clearly something is going wrong at the time of writing
the transform.
The Fixed parameters indicate that we should expect
11x11x11 = 1331
double numbers in the line with the title "Parameters:"
This is indeed what the Reader is expecting and the reason
for the mismatch.
So the question is :
Why the Writer didn't find this 1331 doubles
in the parameters array of the transform ?
Looking at the source code of the writer, the key code is in
lines 105-116 of Insight/Code/IO/itkTransformFileWriter.cxx
while(it != m_TransformList.end())
{
out << "# Transform " << count << std::endl;
out << "Transform: " << (*it)->GetTransformTypeAsString() << std::endl;
TempArray = (*it)->GetParameters();
out << "Parameters: " << TempArray << std::endl;
TempArray = (*it)->GetFixedParameters();
out << "FixedParameters: " << TempArray << std::endl;
it++;
count++;
}
Which seems to indicate that the writer simply calls GetParameters()
in the Transform and send that array to the output stream.
---
Albert,
Please do the following:
1) Go to your code where you are writing the transform
> itk::TransformFileWriter::Pointer writerTransform;
> writerTransform = itk::TransformFileWriter::New();
> writerTransform->AddTransform(transform);
> writerTransform->SetFileName(filename.c_str());
> try{
> writerTransform->Update();
> }
2) and just before writerTransform->Update() call
the GetParameters() method of the transform,
like
> try{
std::cout << "Parameters: " << transform->GetParameters() << std::endl;
> writerTransform->Update();
> }
and
3) Let us know what you get.
4) You could also go for even more detail and add:
> try{
std::cout << "Parameters: " << transform->GetParameters() << std::endl;
std::cout << "Full transform description ";
transform->Print( std::cout );
> writerTransform->Update();
> }
On our side,
to build up more confidence in the Writer,
we just added the TransformFileWriter to the two examples:
Insight/Examples/Registration/
BSplineWarping1.cxx
BSplineWarping2.cxx
(you will have to do a CVS update to get this modified code).
When you run the tests of these two files:
ctest -R BSplineWarping -N
we get the expected two transforms in the binary
directory:
InsightBin/Testing/Temporary/
BSplineWarping1TestTransform.txt
BSplineWarping2TestTransform.txt
with the corresponding content:
#Insight Transform File V1.0
# Transform 0
Transform: BSplineDeformableTransform_double_2_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0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 5 0 0 0 0 0 0 0 2
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0
10 5 0 0 0 0 0 2 5 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 5 0 0 0 0 0
0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
FixedParameters: 8 8 8 -45 -54 -44.75 45 54 44.75 1 0 0 0 1 0 0 0 1
All that to say:
We suspect that something is wrong with your transform....
Please let us know what you find when you add the
print out line before calling update on the writer.
Thanks
Luis
----------------------------------------------------------------------------------------
On Thu, Mar 11, 2010 at 6:14 AM, Albert Gubern <bertkrek at gmail.com> wrote:
> Hi,
> I am having troubles writing a BSpline transform produced by
> DeformableRegistration15.cxx example. I have implemented a
> bsplineRegistration method, based on that example, that returns the final
> transform. From my main program, I apply the transform to the image and
> observing the transformed image I can see that the transform has been
> applied successfully. At the same time, I write the transform using the
> itkTransformFileWriter but the parameters field of the produced file is
> empty. Here is an example:
> ****************************************
> #Insight Transform File V1.0
> # Transform 0
> Transform: BSplineDeformableTransform_double_3_3
> Parameters:
> FixedParameters: 11 11 11 -73 -17 -36.4286 73 17 36.4286 1 0 0 0 1 0 0 0 1
> ***************************************
> And the code to write the transform is as follows:
>
> ****************************************
> itk::TransformFileWriter::Pointer writerTransform;
> writerTransform = itk::TransformFileWriter::New();
> writerTransform->AddTransform(transform);
> writerTransform->SetFileName(filename.c_str());
> try{
> writerTransform->Update();
> }
> catch( itk::ExceptionObject & excp )
> {
> std::cerr << "Exception thrown INPUT_OUTPUT TransformWriter" <<
> std::endl;
> std::cerr << excp << std::endl;
> return EXIT_FAILURE;
> }
> **********************************
>
> I have noticed of this problem when I have tried to read the transform file
> and I got the following error:
> *******************************************************
> Loading Transform: .../Transforms/2_3.txt
> terminate called after throwing an instance of 'itk::ExceptionObject'
> what():
> /usr/local/include/InsightToolkit/Common/itkBSplineDeformableTransform.txx:510:
> itk::ERROR: BSplineDeformableTransform(0x100bb9bf0): Mismatched between
> parameters size 0 and region size 1331
> ******************************************************
> And the program produces the error when is executing the Update() of the
> next lines:
> **************************************************
> typedef itk::TransformFileReader TransformReaderType;
> TransformReaderType::Pointer transformReader = TransformReaderType::New();
> std::cout << "Loading Transform: " << filename << std::endl;
> transformReader->SetFileName( filename.c_str());
> transformReader->Update();
> **************************************************
>
> Finally comment that same code has been tested with Affine transform and I
> have not had problems reading, writing and using the Affine transform.
> Any idea about what I am doing wrong?
>
> Thanks in advance.
> --
> Albert
>
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.html
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users
>
>
More information about the Insight-users
mailing list