# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# # Application of ICP to a generated sample dataset

# Load required packages
import numpy as np
import matplotlib.pyplot as plt
from icp import icp

# +
# Generate data
n_dst = 50
x_dst, y_dst = np.meshgrid(np.linspace(-1, 1, n_dst), np.linspace(-1, 1, n_dst), indexing='ij')
z_dst = x_dst ** 2 + y_dst ** 2
plt.figure(figsize=(12, 9))
plt.pcolormesh(x_dst, y_dst, z_dst)

offset = 0.2
scale = 0.9
n_src = 50
x_src, y_src = np.meshgrid(np.linspace(-1, 1, n_src), np.linspace(-1, 1, n_src), indexing='ij')
z_src = x_src ** 2 + y_src ** 2 -offset
x_src *= 1 / scale
y_src *= 1 / scale
plt.figure(figsize=(12, 9))
plt.pcolormesh(x_src, y_src, z_src)

src = np.column_stack((np.reshape(x_src, (n_src ** 2,)), np.reshape(y_src, (n_src ** 2,)),
                       np.reshape(z_src, (n_src ** 2,))))
src += np.random.normal(loc=0, scale=0.1, size=(n_src * n_src, 3))
dst = np.column_stack((np.reshape(x_dst, (n_dst ** 2,)), np.reshape(y_dst, (n_dst ** 2,)),
                       np.reshape(z_dst, (n_dst ** 2,))))
# -

# Apply ICP
scale, offset = icp(src, dst, dim_offset=[2], dim_scale=[0, 1], num_iter=50)

# Print results
print('Scale:', scale)
print('Offset:', offset)

StarcoderdataJupyterScriptsDedupFiltered