[ITK-users] Simple ITK Overlap Two Image for example PET and MRI or CT ?? is it possible? and Image Fusion?
ivan
ivan.granata.na at gmail.com
Fri Nov 11 02:43:43 EST 2016
ok i'm thank u
but really i see overlap not fusion
this is my code and my result
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 ImageFusionFinal {
public static void main(String argv[]) {
//if ( argv.length < 3 )
// {
// System.out.format( "Usage: %s <fixedImageFilter> <movingImageFile>
<outputTransformFile>\n", "ImageRegistrationMethod1");
// System.exit(-1);
// }
//-----------Read
Image----------------------------------------------------------------------------------------------------
org.itk.simple.ImageFileReader reader = new
org.itk.simple.ImageFileReader();
reader.setOutputPixelType( PixelIDValueEnum.sitkFloat32);
reader.setFileName("D:/workspace/ImageFusionFinal/img/CT.nii");
Image ctimage = reader.execute();
reader.setOutputPixelType( PixelIDValueEnum.sitkFloat32);
reader.setFileName("D:/workspace/ImageFusionFinal/img/PET.nii");
Image petimage = reader.execute();
System.out.format("Images Read\n");
// println("Images Read");
//------Initial
Transform---------------------------------------------------------------------------------------------------------
org.itk.simple.CenteredTransformInitializerFilter initialTx = new
org.itk.simple.CenteredTransformInitializerFilter();
org.itk.simple.Transform tx = initialTx.execute( ctimage, petimage, new
org.itk.simple.AffineTransform(ctimage.getDimension()) );
//------Registration
Method---------------------------------------------------------------------------------------------------------
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.Euler3DTransform() );
double learningRate = 1 ;
long numberOfIterations = 100;
long numberOfHistogramBins = 50;
R.setMetricAsMattesMutualInformation(numberOfHistogramBins);
R.setOptimizerAsGradientDescentLineSearch(learningRate,numberOfIterations);
R.setOptimizerScalesFromIndexShift();
VectorUInt32 pts1 = new VectorUInt32(3);
// org.itk.simple.VectorUInt32 pts1;
pts1.clear();
pts1.push_back(4);
pts1.push_back(2);
pts1.push_back(1);
R.setShrinkFactorsPerLevel(pts1);
VectorDouble pts2 = new VectorDouble(3);
/* seed points */
pts2.clear();
pts2.push_back(8);
pts2.push_back(4);
pts2.push_back(2);
System.out.println(pts2);
R.setSmoothingSigmasPerLevel(pts2);
R.smoothingSigmasAreSpecifiedInPhysicalUnitsOn();
R.setMetricSamplingStrategy(org.itk.simple.ImageRegistrationMethod.MetricSamplingStrategyType.RANDOM);
R.setMetricSamplingPercentage(0.1);
R.setInitialTransform(tx);
R.setInterpolator( InterpolatorEnum.sitkLinear );
IterationUpdate cmd = new IterationUpdate(R);
R.addCommand( EventEnum.sitkIterationEvent, cmd);
org.itk.simple.Transform outTx = R.execute( ctimage, petimage );
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());
//tx.AddTransform(sitk.Transform(3,sitk.sitkAffine));
R.setInitialTransform(outTx,true);
tx.addTransform ( R.execute( ctimage, petimage ));
double learningRate2 = 1 ;
long numberOfIterations2 = 100;
//long numberOfHistogramBins2 = 50;
R.setOptimizerAsGradientDescentLineSearch(learningRate2,numberOfIterations2);
R.setOptimizerScalesFromIndexShift();
VectorUInt32 pts3 = new VectorUInt32(2);
// org.itk.simple.VectorUInt32 pts1;
pts3.clear();
pts3.push_back(2);
pts3.push_back(1);
R.setShrinkFactorsPerLevel(pts3);
VectorDouble pts4 = new VectorDouble(2);
/* seed points */
pts4.clear();
pts4.push_back(4);
pts4.push_back(1);
System.out.println(pts4);
R.setSmoothingSigmasPerLevel(pts4);
R.setInitialTransform(tx);
R.smoothingSigmasAreSpecifiedInPhysicalUnitsOn();
R.setMetricSamplingStrategy(org.itk.simple.ImageRegistrationMethod.MetricSamplingStrategyType.RANDOM);
R.setMetricSamplingPercentage(0.1);
R.setInitialTransform(tx);
R.setInterpolator( InterpolatorEnum.sitkLinear );
//------Resample
Method---------------------------------------------------------------------------------------------------------
org.itk.simple.ResampleImageFilter resample = new
org.itk.simple.ResampleImageFilter();
resample.setReferenceImage(ctimage);
resample.setOutputPixelType(PixelIDValueEnum.sitkUInt32);
//InterpolatorEnum interp =
resample.setInterpolator(InterpolatorEnum.sitkBSpline);
resample.setTransform(outTx);
//transf.setInterpolator(interp);
// VectorDouble orig =
resample.getOutputOrigin();
//VectorDouble spac =
resample.getOutputSpacing();
// VectorDouble dir =
resample.getOutputDirection();
//Double pix =
resample.getDefaultPixelValue();
//transf.setInterpolator(dir);
//VectorUInt32 pts = new VectorUInt32();
resample.getSize();
resample.execute(petimage);
Image out = resample.execute(petimage);
//------Resample
Method---------------------------------------------------------------------------------------------------------
ComposeImageFilter out_fin = new ComposeImageFilter();
Image out_fin2 = out_fin.execute(ctimage, petimage);
// org.itk.simple.CheckerBoardImageFilter out_fin = new
org.itk.simple.CheckerBoardImageFilter();
// out_fin.execute(ctimage, petimage);
VectorUInt32 checkerPattern = new VectorUInt32(2);
// org.itk.simple.VectorUInt32 pts1;
checkerPattern.clear();
checkerPattern.push_back(8);
checkerPattern.push_back(8);
checkerPattern.push_back(1);
CheckerBoardImageFilter out_fin3 = new CheckerBoardImageFilter();
Image out_fin4 = out_fin3.execute(ctimage, petimage,checkerPattern);
// LabelOverlayImageFilter out_fin5 = new LabelOverlayImageFilter();
// org.itk.simple.Image petimage2 = new
org.itk.simple.Image(ctimage.getSize(), PixelIDValueEnum.sitkVectorFloat64);
// petimage2.copyInformation(ctimage);
// Image out_fin6 = out_fin5.execute(ctimage, petimage2);
//-----Write Fused
Image---------------------------------------------------------------------------------------------------------
//Image blurredImg = filter.execute(img);
// CastImageFilter caster = new CastImageFilter();
// caster.setOutputPixelType( img.getPixelIDValue() );
// Image castImg = caster.execute( blurredImg );
// ImageFileWriter writer = new ImageFileWriter();
// writer.setFileName(argv[1]);
// writer.execute( castImg );
//Image blurredImg = resample.execute(out_fin2);
//Image castImg = caster.execute(blurredImg);
ImageFileWriter writer3 = new ImageFileWriter();
writer3.setFileName("D:/workspace/ImageFusionFinal/img/CT_PET_Fusion2.nii");
writer3.useCompressionOn();
writer3.execute(out_fin4);
//writer.execute(transform.getResultImage());
// transform.setParameters(reader.execute());
//Image transform = reader.execute();
//Transform.setParameters();
// Perform warp
// transform.logToConsoleOn();
// transform.execute();
}
}
<http://itk-users.7.n7.nabble.com/file/n37760/CT.jpg>
<http://itk-users.7.n7.nabble.com/file/n37760/PET.jpg>
result
<http://itk-users.7.n7.nabble.com/file/n37760/CT_PET_Fusion.jpg>
--
View this message in context: http://itk-users.7.n7.nabble.com/ITK-users-Simple-ITK-Overlap-Two-Image-for-example-PET-and-MRI-or-CT-is-it-possible-and-Image-Fusion-tp37753p37760.html
Sent from the ITK - Users mailing list archive at Nabble.com.
More information about the Insight-users
mailing list