[ITK] [ITK-users] Coregistration Transform Phyton to Java please help me
ivan
ivan.granata.na at gmail.com
Mon Oct 24 08:53:53 EDT 2016
i've this
https://itk.org/SimpleITKDoxygen/html/Python_2ImageRegistrationMethodDisplacement1_8py-example.html
and in java i try to translate in this:
but i've some errors
can anyone help me please?
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 < 4 )
{
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.Transform initialTx = new org.itk.simple.Transform();
//initialTx.CenteredTransformInitializerFilter( new
org.itk.simple.AffineTransform( fixed.getDimension() ) );
initialTx.execute( fixed, moving, AffineTransform( fixed.getDimension() ));
//org.itk.simple.Transform transf1 = new org.itk.simple.Transform();
//org.itk.simple.AffineTransform afftransf = new
org.itk.simple.AffineTransform();
//CenteredTransformInitializerFilter initialTx =
transf1.execute(fixed,moving, Transform.Affine(fixed.getDimension()));
//org.itk.simple.AffineTransform Aff = new
org.itk.simple.AffineTransform();
// org.itk.simple.ImageRegistrationMethod initialTx = new
org.itk.simple.ImageRegistrationMethod();
// CenteredTransformInitializerFilter transform1 = new
CenteredTransformInitializerFilter();
// initialTx.execute(fixed, moving, transform1( fixed.getDimension()));
//initialTx.CenteredTransformInitializerFilter( new
org.itk.simple.AffineTransform( fixed.getDimension() ) );
// Transform initialTx = new Transform();
//ord.add(initialTx);
//org.itk.simple.Transform transform = new Transform();
// initialTx.setInitialTransform( new org.itk.simple.TranslationTransform(
fixed.getDimension() ) );
// initialTx.setInitialTransform( new org.itk.simple.TranslationTransform(
fixed.getDimension() ) );
// initialTx.setTransform( new org.itk.simple.AffineTransform(
fixed.getDimension() ) );
//
//org.itk.simple.Transform initialTx =
CenteredTransformInitializerFilter.execute(fixed, moving, Aff);
//fixed, moving, Transform(fixed.getDimension(),TransformEnum.sitkAffine)
org.itk.simple.ImageRegistrationMethod R = new
org.itk.simple.ImageRegistrationMethod();
//VectorUInt32 b = [(3,2,1)];
//VectorUInt32 b = new VectorUInt32 {(3,2,1)};
long a1= 321;
VectorUInt32 x1 = new VectorUInt32(a1);
R.setShrinkFactorsPerLevel(x1);
//Vector<Double> (3,2,1);
long b1 = 211;
VectorDouble y1 = new VectorDouble(b1);
R.setSmoothingSigmasPerLevel(y1);
//SET Metric
R.setMetricAsMattesMutualInformation(20);
//R.setMetricAsJointHistogramMutualInformation(20);
R.setMetricUseFixedImageGradientFilter(false);
double learningRate = 1.0 ;
double minStep = 0.01;
int numberOfIterations = 100;
R.setOptimizerAsRegularStepGradientDescent( learningRate,
minStep,
numberOfIterations);
//R.setOptimizerAsGradientDescent(learningRate=1.0, //
numberOfIterations=100, // estimateLearningRate = R.EachIteration)
//SET Optimizer
R.setOptimizerScalesFromPhysicalShift();
R.setInitialTransform(initialTx,true);
//SET Interpolator
R.setInterpolator(InterpolatorEnum.sitkLinear);
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());
org.itk.simple.Image displacementField = new
org.itk.simple.Image(fixed.getSize(), PixelIDValueEnum.sitkVectorFloat64);
//displacementField.Image();
org.itk.simple.DisplacementFieldTransform displacementTx = new
org.itk.simple.DisplacementFieldTransform(displacementField);
double varianceForUpdateField = 0.0 ;
double varianceForTotalField = 1.5;
displacementTx.setSmoothingGaussianOnUpdate(varianceForUpdateField,
varianceForTotalField);
R.setMovingInitialTransform(outTx);
R.setInitialTransform(displacementTx,true);
R.setMetricAsANTSNeighborhoodCorrelation(4);
R.setMetricUseFixedImageGradientFilter(false);
R.setMetricUseFixedImageGradientFilter(false);
//VectorUInt32 b = [(3,2,1)];
//VectorUInt32 b = new VectorUInt32 {(3,2,1)};
long a2= 321;
VectorUInt32 x2 = new VectorUInt32(a2);
R.setShrinkFactorsPerLevel(x2);
//Vector<Double> (3,2,1);
long b2 = 211;
VectorDouble y2 = new VectorDouble(b2);
R.setSmoothingSigmasPerLevel(y2);
R.setOptimizerScalesFromPhysicalShift();
double learningRate2 = 1.0 ;
double minStep2 = 0.01;
int numberOfIterations2 = 300;
R.setOptimizerAsRegularStepGradientDescent( learningRate2,
minStep2,
numberOfIterations2);
//outTx.AddTransform( R.Execute(fixed, moving) )
outTx.addTransform ( 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]);
System.out.println("Parametri Trasformazione Generati e Salvati");
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();
}
private static Transform AffineTransform(long dimension) {
// TODO Auto-generated method stub
return null;
}
}
--
View this message in context: http://itk-users.7.n7.nabble.com/ITK-users-Coregistration-Transform-Phyton-to-Java-please-help-me-tp37692.html
Sent from the ITK - Users mailing list archive at Nabble.com.
_____________________________________
Powered by www.kitware.com
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
Kitware offers ITK Training Courses, for more information visit:
http://www.kitware.com/products/protraining.php
Please keep messages on-topic and check the ITK FAQ at:
http://www.itk.org/Wiki/ITK_FAQ
Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/insight-users
More information about the Community
mailing list