21 parser = argparse.ArgumentParser(
22 description=
"Deform a Volume With a Thin Plate Spline."
24 parser.add_argument(
"source_landmarks")
25 parser.add_argument(
"target_landmarks")
26 parser.add_argument(
"input_image")
27 parser.add_argument(
"deformed_image")
28 parser.add_argument(
"checker_board_image")
29 args = parser.parse_args()
34 source_landmarks_mesh = itk.meshread(args.source_landmarks)
36 points = itk.array_from_vector_container(source_landmarks_mesh.GetPoints())
37 points = points.astype(np.float64)
38 source_landmarks = thin_plate_spline.GetSourceLandmarks()
39 source_landmarks.SetPoints(itk.vector_container_from_array(points.flatten()))
41 target_landmarks_mesh = itk.meshread(args.target_landmarks)
43 points = itk.array_from_vector_container(target_landmarks_mesh.GetPoints())
44 points = points.astype(np.float64)
45 target_landmarks = thin_plate_spline.GetTargetLandmarks()
46 target_landmarks.SetPoints(itk.vector_container_from_array(points.flatten()))
48 thin_plate_spline.ComputeWMatrix()
50 input_image = itk.imread(args.input_image)
52 deformed_image = itk.resample_image_filter(
54 use_reference_image=
True,
55 reference_image=input_image,
56 transform=thin_plate_spline,
58 itk.imwrite(deformed_image, args.deformed_image)
60 checker_board = itk.checker_board_image_filter(input_image, deformed_image)
61 itk.imwrite(checker_board, args.checker_board_image)