import org.itk.simple.*;
public class LandmarkRegistration {
public static void main(String[] args) throws Exception {
Image fixedImage = new Image(100, 100, PixelIDValueEnum.sitkUInt8);
for (long x = 11; x < 20; ++x) {
for (long y = 11; y < 20; ++y) {
VectorUInt32 idx = new VectorUInt32();
idx.add(x);
idx.add(y);
fixedImage.setPixelAsUInt8(idx, (short)200);
}
}
Image movingImage = new Image(100, 100, PixelIDValueEnum.sitkUInt8);
for (long x = 51; x < 60; ++x) {
for (long y = 51; y < 60; ++y) {
VectorUInt32 idx = new VectorUInt32();
idx.add(x);
idx.add(y);
movingImage.setPixelAsUInt8(idx, (short)69);
}
}
VectorDouble fixedLandmarks = new VectorDouble();
fixedLandmarks.add(10.0); fixedLandmarks.add(10.0);
fixedLandmarks.add(20.0); fixedLandmarks.add(10.0);
fixedLandmarks.add(20.0); fixedLandmarks.add(20.0);
VectorDouble movingLandmarks = new VectorDouble();
movingLandmarks.add(50.0); movingLandmarks.add(50.0);
movingLandmarks.add(60.0); movingLandmarks.add(50.0);
movingLandmarks.add(60.0); movingLandmarks.add(60.0);
LandmarkBasedTransformInitializerFilter landmarkInitializer = new LandmarkBasedTransformInitializerFilter();
landmarkInitializer.setFixedLandmarks(fixedLandmarks);
landmarkInitializer.setMovingLandmarks(movingLandmarks);
Transform transform = new Euler2DTransform();
Transform outputTransform = landmarkInitializer.execute(transform);
System.out.println(outputTransform.toString());
Image outputImage = SimpleITK.resample(movingImage, fixedImage, outputTransform, InterpolatorEnum.sitkLinear, 150);
SimpleITK.writeImage(outputImage, "landmark_example.png");
String outName;
if (args.length > 0) {
outName = args[0];
} else {
outName = "landmark_transform.tfm";
}
SimpleITK.writeTransform(outputTransform, outName);
}
}