[Insight-users] B-Splines Registration

A.R.Lopessimoes at ewi.utwente.nl A.R.Lopessimoes at ewi.utwente.nl
Fri Aug 20 04:34:38 EDT 2010


Dear all,

 

I am trying to "translate" the example DeformableRegistration4.cxx
(deformable registration of two 2D images) into Python. However, I keep
getting this error:

 

itk::ERROR: Region ImageRegion (0027F104)

  Dimension: 2

  Index: [-1, -1]

  Size: [3, 3]

 is outside of buffered region ImageRegion (036C44AC)

  Dimension: 2

  Index: [0, 0]

  Size: [8, 8]

 

What exactly are these two different regions? The second one seems to be
the whole grid and the first one perhaps the border. But where do the
negative indexes come from?

 

Can someone please take a look at my code? I suspect there may be
something wrong in the definition of the grid, but I can't figure out
what.

 

#

# Read the fixed and moving images using filenames

#

 

FixedImageType = itk.Image[itk.F,2]

MovingImageType = itk.Image[itk.F,2]

 

fixedImageReader = itk.ImageFileReader[FixedImageType].New()

movingImageReader = itk.ImageFileReader[MovingImageType].New()

 

fixedImageReader.SetFileName(
r'C:\Development\Insight\Examples\Data\RatLungSlice1.mha' )

movingImageReader.SetFileName(
r'C:\Development\Insight\Examples\Data\RatLungSlice2.mha'  )

 

fixedImageReader.Update()

movingImageReader.Update()

 

fixedImage = fixedImageReader.GetOutput() 

movingImage = movingImageReader.GetOutput()

 

 

#

#  Registration framework

#

registration    =
itk.ImageRegistrationMethod[FixedImageType,MovingImageType].New()

metric     =
itk.MeanSquaresImageToImageMetric[FixedImageType,MovingImageType].New()

 

transformType = itk.BSplineDeformableTransform[itk.D,2,2]

transform       = transformType.New()

optimizer       = itk.LBFGSOptimizer.New()

interpolator    =
itk.LinearInterpolateImageFunction[FixedImageType,itk.D].New()

 

registration.SetOptimizer(      optimizer.GetPointer() )

registration.SetTransform(      transform.GetPointer() )

registration.SetInterpolator(   interpolator.GetPointer() )

registration.SetMetric(         metric.GetPointer() )

registration.SetFixedImage(  fixedImage )

registration.SetMovingImage( movingImage )

registration.SetFixedImageRegion(  fixedImage.GetBufferedRegion() )

 

 

#

# Transform parameters 

#

 

# Define the grid

bSplineRegion = itk.ImageRegion[2]()

gridSizeOnImage = itk.Size[2]()

gridBorderSize = itk.Size[2]()

totalGridSize = itk.Size[2]()

 

gridSizeOnImage.Fill( 5 )

gridBorderSize.Fill( 3 )

 

for r in range(0,2):

    totalGridSize.SetElement(r,gridSizeOnImage.GetElement(r) +
gridBorderSize.GetElement(r))

 

bSplineRegion.SetSize(totalGridSize)

 

spacing = fixedImage.GetSpacing()

origin = fixedImage.GetOrigin()

fixedImageSize = fixedImage.GetLargestPossibleRegion().GetSize()

 

for r in range(0,2):

    s = mat.floor((fixedImageSize.GetElement(r) - 1 )/(
gridSizeOnImage.GetElement(r) - 1 ))

    spacing.SetElement(r,spacing.GetElement(r)*s)

    origin.SetElement(r,origin.GetElement(r)-s)

 

gridDirection = fixedImage.GetDirection()

 

transform.SetGridSpacing(spacing)

transform.SetGridOrigin(origin)

transform.SetGridRegion(bSplineRegion)

transform.SetGridDirection(gridDirection)

 

numbOfParameters = transform.GetNumberOfParameters()

parameters = itk.Array[itk.D]()

parameters.SetSize(numbOfParameters)

parameters.Fill( 0.0 )

 

transform.SetParameters(parameters)

registration.SetInitialTransformParameters( transform.GetParameters() )

 

 

#

# Define optimizer parameters

#

 

optimizer.SetGradientConvergenceTolerance( 0.05 );

optimizer.SetLineSearchAccuracy( 0.9 );

optimizer.SetDefaultStepLength( 1.5 );

optimizer.TraceOn();

optimizer.SetMaximumNumberOfFunctionEvaluations( 1000 );

 

 

#

# Start the registration process

#

print "Starting registration"

registration.StartRegistration()

 

 

Thank you in advance!

 

Rita

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20100820/32163677/attachment-0001.htm>


More information about the Insight-users mailing list