[Insight-users] RE: need an example of BSpline parameter file

mrcheung at mdanderson.org mrcheung at mdanderson.org
Thu Jul 21 13:12:19 EDT 2005


Hi,

Below is a segment of code from itk BSplineWarp1.cxx. Can anyone provide me
with an example of the format of a parameter file that could be fed into
bsplineTransform->SetParameters( parameters );

Thanks a lot, Rex

// Software Guide : BeginCodeSnippet
  typedef TransformType::RegionType RegionType;
  RegionType bsplineRegion;
  RegionType::SizeType   size;

  const unsigned int numberOfGridNodesOutsideTheImageSupport = 3;

  const unsigned int numberOfGridNodesInsideTheImageSupport = 5;

  const unsigned int numberOfGridNodes =
                        numberOfGridNodesInsideTheImageSupport +
                        numberOfGridNodesOutsideTheImageSupport;

  const unsigned int numberOfGridCells =
                        numberOfGridNodesInsideTheImageSupport - 1;

  size.Fill( numberOfGridNodes );
  bsplineRegion.SetSize( size );

  typedef TransformType::SpacingType SpacingType;
  SpacingType spacing;
  spacing[0] = floor( fixedSpacing[0] * (fixedSize[0] - 1) /
numberOfGridCells );
  spacing[1] = floor( fixedSpacing[1] * (fixedSize[1] - 1) /
numberOfGridCells );

  typedef TransformType::OriginType OriginType;
  OriginType origin;
  origin[0] = fixedOrigin[0] - spacing[0];
  origin[1] = fixedOrigin[1] - spacing[1];

  bsplineTransform->SetGridSpacing( spacing );
  bsplineTransform->SetGridOrigin( origin );
  bsplineTransform->SetGridRegion( bsplineRegion );


  typedef TransformType::ParametersType     ParametersType;

  const unsigned int numberOfParameters =
               bsplineTransform->GetNumberOfParameters();


  const unsigned int numberOfNodes = numberOfParameters / SpaceDimension;

  ParametersType parameters( numberOfParameters );
//  Software Guide : EndCodeSnippet




//  Software Guide : BeginLatex
//
//  The BSpline grid should now be fed with coeficients at each node. Since
//  this is a two dimensional grid, each node should receive two
coefficients.
//  Each coefficient pair is representing a displacement vector at this
node.
//  The coefficients can be passed to the BSpline in the form of an array
where
//  the first set of elements are the first component of the displacements
for
//  all the nodes, and the second set of elemets is formed by the second
//  component of the displacements for all the nodes.
//
//  In this example we read such displacements from a file, but for
convinience
//  we have written this file using the pairs of $(x,y)$ displacement for
every
//  node. The elements read from the file should therefore be reorganized
when
//  assigned to the elements of the array. We do this by storing all the
odd
//  elements from the file in the first block of the array, and all the
even
//  elements from the file in the second block of the array. Finally the
array
//  is passed to the BSpline transform using the \code{SetParameters()}.
//
//  Software Guide : EndLatex


// Software Guide : BeginCodeSnippet
  std::ifstream infile;

  infile.open( argv[1] );

  for( unsigned int n=0; n < numberOfNodes; n++ )
    {
    infile >>  parameters[n];
    infile >>  parameters[n+numberOfNodes];
    }

  infile.close();
//  Software Guide : EndCodeSnippet



//  Software Guide : BeginLatex
//
//   Finally the array is passed to the BSpline transform using the
//   \code{SetParameters()}.
//
//  Software Guide : EndLatex

// Software Guide : BeginCodeSnippet

  bsplineTransform->SetParameters( parameters );




More information about the Insight-users mailing list