[Insight-users] Registration Example in java?
Michael Bell
michael.bell at acm.org
Wed Sep 6 22:33:14 EDT 2006
Here is some java code to do an affine registration on windows. It is
modelled after Examples/ImageRegistration9.cxx. The cvs version of
WrapITK was necessary for some of the classes. The parameters are
tuned for the specific images I am using, so you might have to set
them differently for your application. It's not a full application,
but it should get you started.
System.loadLibrary("ITKCommon");
itkMeanSquaresImageToImageMetricIF2IF2_Pointer metric =
itkMeanSquaresImageToImageMetricIF2IF2.itkMeanSquaresImageToImageMetricIF2IF2_New();
itkCenteredTransformInitializerA2DTDIF2IF2_Pointer
initializer =
itkCenteredTransformInitializerA2DTDIF2IF2.itkCenteredTransformInitializerA2DTDIF2IF2_New();
itkAffineTransformD2_Pointer transform =
itkAffineTransformD2.itkAffineTransformD2_New();
itkRegularStepGradientDescentOptimizer_Pointer optimizer =
itkRegularStepGradientDescentOptimizer.itkRegularStepGradientDescentOptimizer_New();
itkLinearInterpolateImageFunctionIF2D_Pointer interpolator
=
itkLinearInterpolateImageFunctionIF2D.itkLinearInterpolateImageFunctionIF2D_New();
itkImageRegistrationMethodIF2IF2_Pointer registration =
itkImageRegistrationMethodIF2IF2.itkImageRegistrationMethodIF2IF2_New();
itkImageFileReaderIF2_Pointer fixedReader =
itkImageFileReaderIF2.itkImageFileReaderIF2_New();
fixedReader.SetFileName( fixedName);
fixedReader.Update();
itkImageFileReaderIF2_Pointer moveReader =
itkImageFileReaderIF2.itkImageFileReaderIF2_New();
moveReader.SetFileName( movingName);
moveReader.Update();
registration.SetMetric(metric.GetPointer());
registration.SetOptimizer(optimizer.GetPointer());
registration.SetTransform(transform.GetPointer());
registration.SetInterpolator(interpolator.GetPointer());
registration.SetFixedImageRegion(fixedReader.GetOutput().GetBufferedRegion());
initializer.SetTransform(transform.GetPointer());
initializer.SetFixedImage(fixedReader.GetOutput());
initializer.SetMovingImage(moveReader.GetOutput());
initializer.MomentsOn();
initializer.InitializeTransform();
registration.SetFixedImage(fixedReader.GetOutput());
registration.SetMovingImage(moveReader.GetOutput());
registration.SetFixedImageRegion(fixedReader.GetOutput().GetBufferedRegion());
registration.SetInitialTransformParameters(transform.GetParameters());
itkArrayD scales = new itkArrayD(6);
scales.Fill(1.0);
scales.SetElement(4,0.001);
scales.SetElement(5,0.001);
optimizer.SetScales(scales);
optimizer.SetMaximumStepLength( 0.7 );
optimizer.SetMinimumStepLength( 0.1 );
optimizer.SetNumberOfIterations( 300 );
optimizer.MinimizeOn();
registration.StartRegistration();
itkArrayD finalParameters =
registration.GetLastTransformParameters();
System.out.println("Result = ");
System.out.println(" Center X = " +
transform.GetCenter().GetElement(0));
System.out.println(" Center Y = " +
transform.GetCenter().GetElement(1));
System.out.println(" Translation X = " +
finalParameters.GetElement(4));
System.out.println(" Translation Y = " +
finalParameters.GetElement(5));
System.out.println(" Iterations = " +
optimizer.GetCurrentIteration());
System.out.println(" Metric value = " + optimizer.GetValue());
System.out.println(finalParameters.GetElement(0) + " " +
finalParameters.GetElement(1));
itkResampleImageFilterIF2IF2_Pointer resampler =
itkResampleImageFilterIF2IF2.itkResampleImageFilterIF2IF2_New();
resampler.SetInput(moveReader.GetOutput());
resampler.SetTransform(registration.GetTransform());
resampler.SetSize(moveReader.GetOutput().GetLargestPossibleRegion().GetSize());
resampler.SetOutputOrigin(moveReader.GetOutput().GetOrigin());
resampler.SetOutputSpacing(moveReader.GetOutput().GetSpacing());
resampler.SetDefaultPixelValue(100);
resampler.Update();
On 9/6/06, Luis Ibanez <luis.ibanez at kitware.com> wrote:
> Hi 歐陽儒
>
> Unfortunately we don't have any Java examples for registration.
>
> However, you can easily convert the Python examples in to Java.
>
> Please look at the Java examples in the Examples/Filtering
> directory, and compare them with the equivalent Python examples
> in the same directory.
>
> That comparison will give you an idea on how to convert from
> Python to Java.
>
>
> Regards,
>
>
> Luis
>
>
> -------------
> 歐陽儒 wrote:
> > Hello
> >
> > Is there any Java example in "Registration" application of ITK?
> >
> > I am a Student in Taiwan Tzu Chi University and I'm working on content-based
> > retrival in medical images.
> >
> > Please reply this mail as soon as possible. :P
> >
> >
> >
> > P.S. I have a problem casting unsigned long 2 image to unsighed short
> > image in java before, and I solve it. :D
> >
> >
> > Best Regard.
>
>
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
>
--
michael.bell at acm.org
More information about the Insight-users
mailing list