(num_dims=2, N=4)
| 240 | |
| 241 | |
| 242 | def hilbert_path_square(num_dims=2, N=4): |
| 243 | import numpy as np |
| 244 | from hilbert import decode |
| 245 | |
| 246 | img_size_power = int(math.sqrt(N)) |
| 247 | assert img_size_power**2 == N, f"{N} should be a square number" |
| 248 | print("img_size_power", img_size_power) |
| 249 | |
| 250 | def draw_curve(num_bits): |
| 251 | # The maximum Hilbert integer. |
| 252 | max_h = 2 ** (num_bits * num_dims) |
| 253 | |
| 254 | # Generate a sequence of Hilbert integers. |
| 255 | hilberts = np.arange(max_h) |
| 256 | print("image size:", N) |
| 257 | order_index = np.zeros((N, N), dtype=int) |
| 258 | |
| 259 | # Compute the 2-dimensional locations. |
| 260 | locs = decode(hilberts, num_dims, num_bits) |
| 261 | for i, loc in enumerate(locs): |
| 262 | order_index[loc[0], loc[1]] = i |
| 263 | # print(locs.shape, locs) |
| 264 | print(order_index) |
| 265 | return order_index |
| 266 | |
| 267 | res = draw_curve(img_size_power) |
| 268 | res_mirror = np.transpose(res) |
| 269 | ro90 = np.rot90(res, 1) |
| 270 | ro90_mirror = np.transpose(ro90) |
| 271 | ro180 = np.rot90(res, 2) |
| 272 | ro180_mirror = np.transpose(ro180) |
| 273 | ro270 = np.rot90(res, 3) |
| 274 | ro270_mirror = np.transpose(ro270) |
| 275 | res = [res, res_mirror, ro90, ro90_mirror, ro180, ro180_mirror, ro270, ro270_mirror] |
| 276 | print("***") |
| 277 | for _ in res: |
| 278 | print(_) |
| 279 | res = [_.flatten() for _ in res] |
| 280 | for _ in res: |
| 281 | print(_.shape) |
| 282 | return res |
| 283 | |
| 284 | |
| 285 | def hilbert_path(N=16): |
nothing calls this directly
no test coverage detected