[Insight-users] DeformableRegistration8.cxx Works in C++, but Java version does not

sumit shah sshah at mednet.ucla.edu
Tue Sep 13 23:40:21 EDT 2005


Dear Itk Users:

I was wondering if anyone has any thoughts or hints on this issue I  
have stumbled upon.  Thanks for your time in reading this!

Thanks,
Sumit

On Sep 13, 2005, at 12:03 AM, sumit shah wrote:

> Dear Itk Users:
>
> I'm a bit confused with the result I've observed.  I have  
> implemented example DeformableRegistration8 in java and tested the  
> Java version to the CXX version.  I did have to change a few things  
> to get the necessary classes wrapped (e.g. itkLBFGSBOptimizer,  
> itkArrayI, etc.)  I also changed the c++ version to use image type  
> of float instead of signed short in order to keep everything as  
> similar as possible.
>
> I ran the c++ version with a command similar to:
>
> DeformableRegistration8 c:/RatLungSlice1.mha c:/RatLungSlice2.mha  
> test.mha
>
> and the result is:
>
>
> Starting Registration
>           Probe Tag    Starts    Stops           Time
>         Registration           1            1             0.313
>
>
> I ran the Java version with similar data and got the following result:
>
> ava.lang.RuntimeException: c:\insighttoolkit-2.2.0\code\algorithms 
> \itkMattesMutualInformationImageToImageMetric.txx:985:
> itk::ERROR: MattesMutualInformationImageToImageMetric(068FB208):  
> Too many samples map outside moving image buffer: 11 / 1638
>
>     at  
> InsightToolkit.itkImageRegistrationMethodJNI.itkImageRegistrationMetho 
> dF3F3_Pointer_StartRegistration(Native Method)
>     at  
> InsightToolkit.itkImageRegistrationMethodF3F3_Pointer.StartRegistratio 
> n(itkImageRegistrationMethodF3F3_Pointer.java:175)
>     at edu.ucla.rip.process.RegistrationTestUtils.defregister 
> (RegistrationTestUtils.java:125)
>     at edu.ucla.rip.process.RegistrationTestUtils.main 
> (RegistrationTestUtils.java:131)
>     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>     at sun.reflect.NativeMethodAccessorImpl.invoke 
> (NativeMethodAccessorImpl.java:39)
>     at sun.reflect.DelegatingMethodAccessorImpl.invoke 
> (DelegatingMethodAccessorImpl.java:25)
>     at java.lang.reflect.Method.invoke(Method.java:585)
>     at com.intellij.rt.execution.application.AppMain.main 
> (AppMain.java:78)
>
>
> Here is my config:
> WindowsXP SP2,
> Visual Studio.NET 2003
> JDK1.5
> ITK 2.2
> CableSWIG CVS
>
> I realize the example I tried was a 2D data set, but the results I  
> observe with the 2D dataset are similar to the results I observe  
> with some of our internal data sets (i.e. the too many samples map  
> outside error).  I just wanted to show an example with the included  
> ITK datasets.
>
> My Java source code is at the end of this message.  I'm not sure  
> what I am doing wrong, I've checked the source code many times to  
> see if I overlooked something, but if I did it is not jumping out  
> at me.  Any help that anyone out there can provide will be very  
> much appreciated.  Thank you very much.
>
> Sumit
>
>
>
> package edu.ucla.rip.process;
>
> import InsightToolkit.itkArrayD;
> import InsightToolkit.itkArrayI;
> import InsightToolkit.itkBSplineDeformableTransform33;
> import InsightToolkit.itkBSplineDeformableTransform33_Pointer;
> import InsightToolkit.itkImageFileReaderF3;
> import InsightToolkit.itkImageFileReaderF3_Pointer;
> import InsightToolkit.itkImageRegion3;
> import InsightToolkit.itkImageRegistrationMethodF3F3;
> import InsightToolkit.itkImageRegistrationMethodF3F3_Pointer;
> import InsightToolkit.itkIterationEvent;
> import InsightToolkit.itkJavaCommand;
> import InsightToolkit.itkLBFGSBOptimizer;
> import InsightToolkit.itkLBFGSBOptimizer_Pointer;
> import InsightToolkit.itkLinearInterpolateImageFunctionF3D;
> import InsightToolkit.itkLinearInterpolateImageFunctionF3D_Pointer;
> import  
> InsightToolkit.itkMattesMutualInformationImageToImageMetricF3F3;
> import  
> InsightToolkit.itkMattesMutualInformationImageToImageMetricF3F3_Pointe 
> r;
> import InsightToolkit.itkPointD3;
> import InsightToolkit.itkSize3;
> import InsightToolkit.itkVectorD3;
>
> /**
> * User: sshah
> * Date: May 17, 2005
> * Time: 12:03:36 PM
> */
>
> public class RegistrationTestUtils {
>   public static void defregister(String fix, String mov) throws  
> Exception {
>     itkImageFileReaderF3_Pointer fixedReader =  
> itkImageFileReaderF3.itkImageFileReaderF3_New();
>     fixedReader.SetFileName(fix);
>     itkImageFileReaderF3_Pointer movingReader =  
> itkImageFileReaderF3.itkImageFileReaderF3_New();
>     movingReader.SetFileName(mov);
>
>     movingReader.Update();
>
>     final itkLinearInterpolateImageFunctionF3D_Pointer interpolator  
> =  
> itkLinearInterpolateImageFunctionF3D.itkLinearInterpolateImageFunction 
> F3D_New();
>     final itkMattesMutualInformationImageToImageMetricF3F3_Pointer  
> metric =  
> itkMattesMutualInformationImageToImageMetricF3F3.itkMattesMutualInform 
> ationImageToImageMetricF3F3_New();
>     final itkLBFGSBOptimizer_Pointer optimizer =  
> itkLBFGSBOptimizer.itkLBFGSBOptimizer_New();
>     final itkBSplineDeformableTransform33_Pointer transform =  
> itkBSplineDeformableTransform33.itkBSplineDeformableTransform33_New();
>     final itkImageRegistrationMethodF3F3_Pointer registration =  
> itkImageRegistrationMethodF3F3.itkImageRegistrationMethodF3F3_New();
>
>     registration.SetMetric(metric.GetPointer());
>     registration.SetOptimizer(optimizer.GetPointer());
>     registration.SetInterpolator(interpolator.GetPointer());
>     registration.SetTransform(transform.GetPointer());
>     registration.SetFixedImage(fixedReader.GetOutput());
>     registration.SetMovingImage(movingReader.GetOutput());
>     fixedReader.Update();
>     itkImageRegion3 fixedRegion = fixedReader.GetOutput 
> ().GetBufferedRegion();
>     registration.SetFixedImageRegion(fixedRegion);
>
>     itkImageRegion3 bsplineRegion = new itkImageRegion3();
>     itkSize3 gridSizeOnImage = new itkSize3();
>     itkSize3 gridBorderSize = new itkSize3();
>     itkSize3 totalGridSize = new itkSize3();
>
>     gridSizeOnImage.Fill(12);
>     gridBorderSize.Fill(3);
>     totalGridSize.Fill(15);
>
>     bsplineRegion.SetSize(totalGridSize);
>
>     itkVectorD3 spacing = fixedReader.GetOutput().GetSpacing();
>     itkPointD3 origin = fixedReader.GetOutput().GetOrigin();
>     itkSize3 fixedImageSize = fixedRegion.GetSize();
>
>     for (int r = 0; r < 3; r++) {
>       spacing.SetElement(r, spacing.GetElement(r) * Math.floor 
> (((double) (fixedImageSize.GetElement(r) - 1)) / ((double)  
> (gridSizeOnImage.GetElement(r) - 1))));
>       origin.SetElement(r, origin.GetElement(r) - spacing.GetElement 
> (r));
>     }
>
>     transform.SetGridSpacing(spacing);
>     transform.SetGridOrigin(origin);
>     transform.SetGridRegion(bsplineRegion);
>
>     for (int i = 0; i < 3; i++) System.out.print(spacing.GetElement 
> (i) + " ");
>     System.out.println();
>     for (int i = 0; i < 3; i++) System.out.print(origin.GetElement 
> (i) + " ");
>     System.out.println();
>     for (int i = 0; i < 3; i++) System.out.print 
> (bsplineRegion.GetSize(i) + " ");
>     System.out.println();
>     for (int i = 0; i < 3; i++) System.out.print 
> (bsplineRegion.GetIndex(i) + " ");
>     System.out.println();
>
>     long numberOfParameters = transform.GetNumberOfParameters();
>
>     itkArrayD parameters = new itkArrayD(numberOfParameters);
>     parameters.Fill(0);
>     transform.SetParameters(parameters);
>
>     registration.SetInitialTransformParameters 
> (transform.GetParameters());
>
>     itkArrayI boundSelect = new itkArrayI 
> (transform.GetNumberOfParameters());
>     itkArrayD upperBound = new itkArrayD 
> (transform.GetNumberOfParameters());
>     itkArrayD lowerBound = new itkArrayD 
> (transform.GetNumberOfParameters());
>     boundSelect.Fill(0);
>     upperBound.Fill(0.0);
>     lowerBound.Fill(0.0);
>
>     optimizer.SetBoundSelection(boundSelect);
>     optimizer.SetUpperBound(upperBound);
>     optimizer.SetLowerBound(lowerBound);
>     optimizer.SetCostFunctionConvergenceFactor(1e7);
>     optimizer.SetProjectedGradientTolerance(1e-4);
>     optimizer.SetMaximumNumberOfIterations(500);
>     optimizer.SetMaximumNumberOfEvaluations(500);
>     optimizer.SetMaximumNumberOfCorrections(12);
>     System.out.println(optimizer.GetBoundSelection 
> ().GetNumberOfElements() + " " + optimizer.GetBoundSelection 
> ().GetElement(0));
>
>     metric.SetNumberOfHistogramBins(50);
>     metric.SetNumberOfSpatialSamples((int)  
> (fixedRegion.GetNumberOfPixels() * 0.1));
>
>     class CommandIterationUpdate extends itkJavaCommand {
>       public void Execute() {
>         System.out.println("iteration " +  
> optimizer.GetCurrentIteration() + " " + optimizer.GetValue() + " "  
> + optimizer.GetInfinityNormOfProjectedGradient());
>       }
>     }
>
>     CommandIterationUpdate p = new CommandIterationUpdate();
>     registration.AddObserver(new itkIterationEvent(), p);
>
>     registration.StartRegistration();
>
>   }
>
>   public static void main(String args[]) {
>     try {
>       defregister(args[0], args[1]);
>     } catch (Exception e) {
>       e.printStackTrace();
>     }
>   }
> }
>
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
>



More information about the Insight-users mailing list