# test transform read / write transforms = itk.transformread(transform_filename) fixed_parameters = np.asarray(transforms[0].GetFixedParameters()) parameters = np.asarray(transforms[0].GetParameters()) assert np.allclose(fixed_parameters, baseline_fixed_parameters) assert np.allclose(parameters, baseline_parameters) additional_transform = itk.TranslationTransform[itk.D, 3].New() baseline_additional_transform_params = [3.0, 2.0, 8.0] parameters = additional_transform.GetParameters() parameters[0] = baseline_additional_transform_params[0] parameters[1] = baseline_additional_transform_params[1] parameters[2] = baseline_additional_transform_params[2] additional_transform.SetParameters(parameters) transforms.insert(0, additional_transform) itk.transformwrite(transforms, sys.argv[7], compression=True) transforms = itk.transformread(sys.argv[7]) fixed_parameters = np.asarray(transforms[1].GetFixedParameters()) parameters = np.asarray(transforms[1].GetParameters()) assert np.allclose(fixed_parameters, baseline_fixed_parameters) assert np.allclose(parameters, baseline_parameters) parameters = np.asarray(transforms[0].GetParameters()) assert np.allclose(parameters, np.array(baseline_additional_transform_params)) # pipeline, auto_pipeline and templated class are tested in other files # BridgeNumPy # Images image = itk.imread(filename)
# only float is wrapped as coordinate representation type in TileMontage montage = itk.TileMontage[type(grayscale_images[0]), itk.F].New() montage.SetMontageSize(stage_tiles.GetAxisSizes()) for t in range(stage_tiles.LinearSize()): montage.SetInputTile(t, grayscale_images[t]) print("Computing tile registration transforms") montage.Update() print("Writing tile transforms") actual_tiles = stage_tiles # we will update it later for t in range(stage_tiles.LinearSize()): index = stage_tiles.LinearIndexToNDIndex(t) regTr = montage.GetOutputTransform(index) tile = stage_tiles.GetTile(t) itk.transformwrite([regTr], str(output_path / (tile.GetFileName() + ".tfm"))) # calculate updated positions - transform physical into index shift pos = tile.GetPosition() for d in range(dimension): pos[d] -= regTr.GetOffset()[d] / spacing[d] tile.SetPosition(pos) actual_tiles.SetTile(t, tile) actual_tiles.Write(str(output_path / "TileConfiguration.registered.txt")) print("Producing the mosaic") resampleF = itk.TileMergeImageFilter[type(color_images[0])].New() resampleF.SetMontageSize(stage_tiles.GetAxisSizes()) for t in range(stage_tiles.LinearSize()): resampleF.SetInputTile(t, color_images[t]) index = stage_tiles.LinearIndexToNDIndex(t)