[ITK-users] Deformable Transformation for Coregistration Simple ITK JAVA code
ivan
ivan.granata.na at gmail.com
Thu Oct 20 07:51:55 EDT 2016
i try with this code
Affine and After BSpline
but after 190 iterations return error code
-------
itk::simple::Transform
AffineTransform (000000001966EA60)
RTTI typeinfo: class itk::AffineTransform<double,3>
Reference Count: 3
Modified Time: 3451
Debug: Off
Object Name:
Observers:
none
Matrix:
-0.0283494 0.437495 -0.558782
-0.215329 2.14011 2.01216
0.661568 -8.35499 1.81576
Offset: [0.0377555, -0.0313043, -0.251059]
Center: [0, 0, 0]
Translation: [0.0377555, -0.0313043, -0.251059]
Inverse:
-435.991 -81.6103 -43.7342
-36.2773 -6.70277 -3.73619
-8.07294 -1.10745 -0.706396
Singular: 0
Optimizer stop condition: RegularStepGradientDescentOptimizerv4: Maximum
number of iterations (200) exceeded.
Iteration: 200
Metric value: -0,176593
Exception in thread "main" java.lang.RuntimeException: Exception thrown in
SimpleITK new_BSplineTransform:
..\..\..\..\..\SimpleITK\Code\Common\src\sitkBSplineTransform.cxx:188:
sitk::ERROR: Transform is not of type BSplineTransform!
at org.itk.simple.SimpleITKJNI.new_BSplineTransform__SWIG_3(Native Method)
at org.itk.simple.BSplineTransform.<init>(BSplineTransform.java:75)
at ImageRegistrationMethodNaplab.main(IterationUpdate.java:68)
this is my code
import org.itk.simple.*;
class IterationUpdate extends Command {
private ImageRegistrationMethod m_Method;
public IterationUpdate(ImageRegistrationMethod m) {
super();
m_Method=m;
}
public void execute() {
org.itk.simple.VectorDouble pos = m_Method.getOptimizerPosition();
System.out.format("%3d = %10.5f : [%f, %f]\n",
m_Method.getOptimizerIteration(),
m_Method.getMetricValue(),
pos.get(0), pos.get(1));
}
}
class ImageRegistrationMethodNaplab {
public static void main(String argv[]) {
if ( argv.length < 3 )
{
System.out.format( "Usage: %s <fixedImageFilter> <movingImageFile>
<outputTransformFile>\n", "ImageRegistrationMethodNaplab");
System.exit(-1);
}
int ImageDimension = 3;
char PixelType;
org.itk.simple.ImageFileReader reader = new
org.itk.simple.ImageFileReader();
reader.setOutputPixelType( PixelIDValueEnum.sitkFloat32 );
reader.setFileName(argv[0]);
Image fixed = reader.execute();
reader.setFileName(argv[1]);
Image moving = reader.execute();
org.itk.simple.ImageRegistrationMethod R = new
org.itk.simple.ImageRegistrationMethod();
R.setMetricAsMattesMutualInformation();
double maxStep = 4.0;
double minStep = 0.01;
int numberOfIterations = 200;
double relaxationFactor = 0.5;
R.setOptimizerAsRegularStepGradientDescent( maxStep,
minStep,
numberOfIterations,
relaxationFactor );
R.setInitialTransform( new org.itk.simple.AffineTransform(
fixed.getDimension() ) );
R.setInterpolator( InterpolatorEnum.sitkBSpline );
IterationUpdate cmd = new IterationUpdate(R);
R.addCommand( EventEnum.sitkIterationEvent, cmd);
org.itk.simple.Transform outTx = R.execute( fixed, moving );
System.out.println("-------");
System.out.println(outTx.toString());
System.out.format("Optimizer stop condition: %s\n",
R.getOptimizerStopConditionDescription());
System.out.format(" Iteration: %d\n", R.getOptimizerIteration());
System.out.format(" Metric value: %f\n", R.getMetricValue());
outTx.writeTransform(argv[2]);
org.itk.simple.BSplineTransform R2 = new
org.itk.simple.BSplineTransform(outTx);
fixed.getSpacing();
fixed.getOrigin();
//fixed.getLargestPossibleRegion();
fixed.getDirection();
int SplineOrder = 3;
long SpaceDimension = ImageDimension;
double CoordinateRepType;
//org.itk.simple.Transform R = new
org.itk.simple.BSplineTransform(SpaceDimension,SplineOrder);
//org.itk.simple.BSplineTransformInitializerFilter R = new
org.itk.simple.BSplineTransformInitializerFilter();
//R.getTransformDomainMeshSize();
//R.getOrder();
//org.itk.simple.Transform outTx = R.execute(moving);
//org.itk.simple.BSplineTransform R2 = new
org.itk.simple.BSplineTransform(outTx);
//R2.getDomainOrigin();
// IterationUpdate cmd = new IterationUpdate(R);
// R.addCommand( EventEnum.sitkIterationEvent, cmd);
//getDimension Return the dimension of the Transform ( 2D or 3D )
// R.setInitialTransform( new
org.itk.simple.BSplineTransform(SplineOrder,SpaceDimension ) );
//R.getDomainDirection();
//fixed.getDimension()
System.out.println("-------");
System.out.println(outTx.toString());
//System.out.format(" Fixed Initial Transform: %d\n",
R.getFixedInitialTransform());
//System.out.format(" Moving Initial Transform: %d\n",
R.getMovingInitialTransform());
//System.out.format(" Initial Transform: %d\n", R.getInitialTransform());
//System.out.format(" Optimizer Position: %d\n",
R.getOptimizerPosition());
//System.out.format("Optimizer stop condition: %s\n",
R2.getOptimizerStopConditionDescription());
//System.out.format(" Iteration: %d\n",
R2.getOptimizerIteration());
//System.out.format(" Metric value: %f\n",
R2.getMetricValue());
//System.out.format(" Interpolator: %f\n", R.getInterpolator());
//System.out.format(" Translation X", R.getTranslationAlongX());
// System.out.format(" Translation Y", R.getTranslationAlongY());
R2.writeTransform(argv[2]);
System.out.println("Parametri Trasformazione Generati e Salvati");
//org.itk.simple.Transform.writeTransform(argv[4]);
//org.itk.simple.ResampleImageFilter image = new
org.itk.simple.ResampleImageFilter();
//image.setOutputPixelType( PixelIDValueEnum.sitkFloat32 );
// image.getOutputPixelType();
// image.getSize ();
//ImageFileWriter writer = new ImageFileWriter();
// writer.setFileName(argv[5]);
org.itk.simple.Transform transform = new org.itk.simple.Transform();
reader.setFileName(argv[2]);
// Write result image
ImageFileWriter writer2 = new org.itk.simple.ImageFileWriter();
writer2.setFileName(argv[3]);
org.itk.simple.ResampleImageFilter transf = new
org.itk.simple.ResampleImageFilter();
transf.setReferenceImage(fixed);
transf.setTransform(outTx);
transf.setOutputPixelType(PixelIDValueEnum.sitkUInt32);
//InterpolatorEnum interp =
transf.getInterpolator();
//transf.setInterpolator(interp);
// VectorDouble orig =
transf.getOutputOrigin();
//VectorDouble spac =
transf.getOutputSpacing();
// VectorDouble dir =
transf.getOutputDirection();
//Double pix =
transf.getDefaultPixelValue();
//transf.setInterpolator(dir);
//VectorUInt32 pts = new VectorUInt32();
transf.getSize();
transf.execute(moving);
Image blurredImg = transf.execute(moving);
//Image castImg = caster.execute(blurredImg);
ImageFileWriter writer3 = new ImageFileWriter();
writer3.setFileName(argv[3]);
writer3.execute(blurredImg);
//writer.execute(transform.getResultImage());
// transform.setParameters(reader.execute());
//Image transform = reader.execute();
//Transform.setParameters();
// Perform warp
// transform.logToConsoleOn();
// transform.execute();
}
}
--
View this message in context: http://itk-users.7.n7.nabble.com/ITK-users-Deformable-Transformation-for-Coregistration-Simple-ITK-JAVA-code-tp37683p37685.html
Sent from the ITK - Users mailing list archive at Nabble.com.
More information about the Insight-users
mailing list