(num_dims=2, img_size_power=3)
| 205 | |
| 206 | |
| 207 | def test_hibert_fig(num_dims=2, img_size_power=3): |
| 208 | import numpy as np |
| 209 | import matplotlib.pyplot as plt |
| 210 | from hilbert import decode |
| 211 | |
| 212 | def draw_curve(ax, num_bits): |
| 213 | |
| 214 | # The maximum Hilbert integer. |
| 215 | max_h = 2 ** (num_bits * num_dims) |
| 216 | |
| 217 | # Generate a sequence of Hilbert integers. |
| 218 | hilberts = np.arange(max_h) |
| 219 | print("image size:", 2**img_size_power) |
| 220 | order_index = np.zeros((2**img_size_power, 2**img_size_power), dtype=int) |
| 221 | |
| 222 | # Compute the 2-dimensional locations. |
| 223 | locs = decode(hilberts, num_dims, num_bits) |
| 224 | for i, loc in enumerate(locs): |
| 225 | order_index[loc[0], loc[1]] = i |
| 226 | print(locs.shape, locs) |
| 227 | print(order_index) |
| 228 | # Draw |
| 229 | ax.plot(locs[:, 0], locs[:, 1], ".-") |
| 230 | ax.set_aspect("equal") |
| 231 | # ax.set_title("%d bits per dimension" % (num_bits)) |
| 232 | # ax.set_xlabel("dim 1") |
| 233 | # ax.set_ylabel("dim 2") |
| 234 | |
| 235 | fig = plt.figure(figsize=(16, 4)) |
| 236 | for ii, num_bits in enumerate([img_size_power]): |
| 237 | ax = fig.add_subplot(1, 4, ii + 1) |
| 238 | draw_curve(ax, num_bits) |
| 239 | plt.savefig("example_2d.png", bbox_inches="tight") |
| 240 | |
| 241 | |
| 242 | def hilbert_path_square(num_dims=2, N=4): |
nothing calls this directly
no test coverage detected