|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from __future__ import absolute_import |
|
from __future__ import division |
|
from __future__ import print_function |
|
|
|
import math |
|
import numpy as np |
|
ENCODE_NEIGHBOURHOOD_3D_KERNEL = np.array([[[128, 64], [32, 16]], [[8, 4], |
|
[2, 1]]]) |
|
|
|
""" |
|
|
|
lookup_tables.py |
|
|
|
all of the lookup-tables functions are borrowed from DeepMind surface_distance repository |
|
|
|
""" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_NEIGHBOUR_CODE_TO_NORMALS = [ |
|
[[0, 0, 0]], |
|
[[0.125, 0.125, 0.125]], |
|
[[-0.125, -0.125, 0.125]], |
|
[[-0.25, -0.25, 0.0], [0.25, 0.25, -0.0]], |
|
[[0.125, -0.125, 0.125]], |
|
[[-0.25, -0.0, -0.25], [0.25, 0.0, 0.25]], |
|
[[0.125, -0.125, 0.125], [-0.125, -0.125, 0.125]], |
|
[[0.5, 0.0, -0.0], [0.25, 0.25, 0.25], [0.125, 0.125, 0.125]], |
|
[[-0.125, 0.125, 0.125]], |
|
[[0.125, 0.125, 0.125], [-0.125, 0.125, 0.125]], |
|
[[-0.25, 0.0, 0.25], [-0.25, 0.0, 0.25]], |
|
[[0.5, 0.0, 0.0], [-0.25, -0.25, 0.25], [-0.125, -0.125, 0.125]], |
|
[[0.25, -0.25, 0.0], [0.25, -0.25, 0.0]], |
|
[[0.5, 0.0, 0.0], [0.25, -0.25, 0.25], [-0.125, 0.125, -0.125]], |
|
[[-0.5, 0.0, 0.0], [-0.25, 0.25, 0.25], [-0.125, 0.125, 0.125]], |
|
[[0.5, 0.0, 0.0], [0.5, 0.0, 0.0]], |
|
[[0.125, -0.125, -0.125]], |
|
[[0.0, -0.25, -0.25], [0.0, 0.25, 0.25]], |
|
[[-0.125, -0.125, 0.125], [0.125, -0.125, -0.125]], |
|
[[0.0, -0.5, 0.0], [0.25, 0.25, 0.25], [0.125, 0.125, 0.125]], |
|
[[0.125, -0.125, 0.125], [0.125, -0.125, -0.125]], |
|
[[0.0, 0.0, -0.5], [0.25, 0.25, 0.25], [-0.125, -0.125, -0.125]], |
|
[[-0.125, -0.125, 0.125], [0.125, -0.125, 0.125], [0.125, -0.125, -0.125]], |
|
[[-0.125, -0.125, -0.125], [-0.25, -0.25, -0.25], |
|
[0.25, 0.25, 0.25], [0.125, 0.125, 0.125]], |
|
[[-0.125, 0.125, 0.125], [0.125, -0.125, -0.125]], |
|
[[0.0, -0.25, -0.25], [0.0, 0.25, 0.25], [-0.125, 0.125, 0.125]], |
|
[[-0.25, 0.0, 0.25], [-0.25, 0.0, 0.25], [0.125, -0.125, -0.125]], |
|
[[0.125, 0.125, 0.125], [0.375, 0.375, 0.375], |
|
[0.0, -0.25, 0.25], [-0.25, 0.0, 0.25]], |
|
[[0.125, -0.125, -0.125], [0.25, -0.25, 0.0], [0.25, -0.25, 0.0]], |
|
[[0.375, 0.375, 0.375], [0.0, 0.25, -0.25], |
|
[-0.125, -0.125, -0.125], [-0.25, 0.25, 0.0]], |
|
[[-0.5, 0.0, 0.0], [-0.125, -0.125, -0.125], |
|
[-0.25, -0.25, -0.25], [0.125, 0.125, 0.125]], |
|
[[-0.5, 0.0, 0.0], [-0.125, -0.125, -0.125], [-0.25, -0.25, -0.25]], |
|
[[0.125, -0.125, 0.125]], |
|
[[0.125, 0.125, 0.125], [0.125, -0.125, 0.125]], |
|
[[0.0, -0.25, 0.25], [0.0, 0.25, -0.25]], |
|
[[0.0, -0.5, 0.0], [0.125, 0.125, -0.125], [0.25, 0.25, -0.25]], |
|
[[0.125, -0.125, 0.125], [0.125, -0.125, 0.125]], |
|
[[0.125, -0.125, 0.125], [-0.25, -0.0, -0.25], [0.25, 0.0, 0.25]], |
|
[[0.0, -0.25, 0.25], [0.0, 0.25, -0.25], [0.125, -0.125, 0.125]], |
|
[[-0.375, -0.375, 0.375], [-0.0, 0.25, 0.25], |
|
[0.125, 0.125, -0.125], [-0.25, -0.0, -0.25]], |
|
[[-0.125, 0.125, 0.125], [0.125, -0.125, 0.125]], |
|
[[0.125, 0.125, 0.125], [0.125, -0.125, 0.125], [-0.125, 0.125, 0.125]], |
|
[[-0.0, 0.0, 0.5], [-0.25, -0.25, 0.25], [-0.125, -0.125, 0.125]], |
|
[[0.25, 0.25, -0.25], [0.25, 0.25, -0.25], |
|
[0.125, 0.125, -0.125], [-0.125, -0.125, 0.125]], |
|
[[0.125, -0.125, 0.125], [0.25, -0.25, 0.0], [0.25, -0.25, 0.0]], |
|
[[0.5, 0.0, 0.0], [0.25, -0.25, 0.25], |
|
[-0.125, 0.125, -0.125], [0.125, -0.125, 0.125]], |
|
[[0.0, 0.25, -0.25], [0.375, -0.375, -0.375], |
|
[-0.125, 0.125, 0.125], [0.25, 0.25, 0.0]], |
|
[[-0.5, 0.0, 0.0], [-0.25, -0.25, 0.25], [-0.125, -0.125, 0.125]], |
|
[[0.25, -0.25, 0.0], [-0.25, 0.25, 0.0]], |
|
[[0.0, 0.5, 0.0], [-0.25, 0.25, 0.25], [0.125, -0.125, -0.125]], |
|
[[0.0, 0.5, 0.0], [0.125, -0.125, 0.125], [-0.25, 0.25, -0.25]], |
|
[[0.0, 0.5, 0.0], [0.0, -0.5, 0.0]], |
|
[[0.25, -0.25, 0.0], [-0.25, 0.25, 0.0], [0.125, -0.125, 0.125]], |
|
[[-0.375, -0.375, -0.375], [-0.25, 0.0, 0.25], |
|
[-0.125, -0.125, -0.125], [-0.25, 0.25, 0.0]], |
|
[[0.125, 0.125, 0.125], [0.0, -0.5, 0.0], |
|
[-0.25, -0.25, -0.25], [-0.125, -0.125, -0.125]], |
|
[[0.0, -0.5, 0.0], [-0.25, -0.25, -0.25], [-0.125, -0.125, -0.125]], |
|
[[-0.125, 0.125, 0.125], [0.25, -0.25, 0.0], [-0.25, 0.25, 0.0]], |
|
[[0.0, 0.5, 0.0], [0.25, 0.25, -0.25], |
|
[-0.125, -0.125, 0.125], [-0.125, -0.125, 0.125]], |
|
[[-0.375, 0.375, -0.375], [-0.25, -0.25, 0.0], |
|
[-0.125, 0.125, -0.125], [-0.25, 0.0, 0.25]], |
|
[[0.0, 0.5, 0.0], [0.25, 0.25, -0.25], [-0.125, -0.125, 0.125]], |
|
[[0.25, -0.25, 0.0], [-0.25, 0.25, 0.0], |
|
[0.25, -0.25, 0.0], [0.25, -0.25, 0.0]], |
|
[[-0.25, -0.25, 0.0], [-0.25, -0.25, 0.0], [-0.125, -0.125, 0.125]], |
|
[[0.125, 0.125, 0.125], [-0.25, -0.25, 0.0], [-0.25, -0.25, 0.0]], |
|
[[-0.25, -0.25, 0.0], [-0.25, -0.25, 0.0]], |
|
[[-0.125, -0.125, 0.125]], |
|
[[0.125, 0.125, 0.125], [-0.125, -0.125, 0.125]], |
|
[[-0.125, -0.125, 0.125], [-0.125, -0.125, 0.125]], |
|
[[-0.125, -0.125, 0.125], [-0.25, -0.25, 0.0], [0.25, 0.25, -0.0]], |
|
[[0.0, -0.25, 0.25], [0.0, -0.25, 0.25]], |
|
[[0.0, 0.0, 0.5], [0.25, -0.25, 0.25], [0.125, -0.125, 0.125]], |
|
[[0.0, -0.25, 0.25], [0.0, -0.25, 0.25], [-0.125, -0.125, 0.125]], |
|
[[0.375, -0.375, 0.375], [0.0, -0.25, -0.25], |
|
[-0.125, 0.125, -0.125], [0.25, 0.25, 0.0]], |
|
[[-0.125, -0.125, 0.125], [-0.125, 0.125, 0.125]], |
|
[[0.125, 0.125, 0.125], [-0.125, -0.125, 0.125], [-0.125, 0.125, 0.125]], |
|
[[-0.125, -0.125, 0.125], [-0.25, 0.0, 0.25], [-0.25, 0.0, 0.25]], |
|
[[0.5, 0.0, 0.0], [-0.25, -0.25, 0.25], |
|
[-0.125, -0.125, 0.125], [-0.125, -0.125, 0.125]], |
|
[[-0.0, 0.5, 0.0], [-0.25, 0.25, -0.25], [0.125, -0.125, 0.125]], |
|
[[-0.25, 0.25, -0.25], [-0.25, 0.25, -0.25], |
|
[-0.125, 0.125, -0.125], [-0.125, 0.125, -0.125]], |
|
[[-0.25, 0.0, -0.25], [0.375, -0.375, -0.375], |
|
[0.0, 0.25, -0.25], [-0.125, 0.125, 0.125]], |
|
[[0.5, 0.0, 0.0], [-0.25, 0.25, -0.25], [0.125, -0.125, 0.125]], |
|
[[-0.25, 0.0, 0.25], [0.25, 0.0, -0.25]], |
|
[[-0.0, 0.0, 0.5], [-0.25, 0.25, 0.25], [-0.125, 0.125, 0.125]], |
|
[[-0.125, -0.125, 0.125], [-0.25, 0.0, 0.25], [0.25, 0.0, -0.25]], |
|
[[-0.25, -0.0, -0.25], [-0.375, 0.375, 0.375], |
|
[-0.25, -0.25, 0.0], [-0.125, 0.125, 0.125]], |
|
[[0.0, 0.0, -0.5], [0.25, 0.25, -0.25], [-0.125, -0.125, 0.125]], |
|
[[-0.0, 0.0, 0.5], [0.0, 0.0, 0.5]], |
|
[[0.125, 0.125, 0.125], [0.125, 0.125, 0.125], |
|
[0.25, 0.25, 0.25], [0.0, 0.0, 0.5]], |
|
[[0.125, 0.125, 0.125], [0.25, 0.25, 0.25], [0.0, 0.0, 0.5]], |
|
[[-0.25, 0.0, 0.25], [0.25, 0.0, -0.25], [-0.125, 0.125, 0.125]], |
|
[[-0.0, 0.0, 0.5], [0.25, -0.25, 0.25], |
|
[0.125, -0.125, 0.125], [0.125, -0.125, 0.125]], |
|
[[-0.25, 0.0, 0.25], [-0.25, 0.0, 0.25], |
|
[-0.25, 0.0, 0.25], [0.25, 0.0, -0.25]], |
|
[[0.125, -0.125, 0.125], [0.25, 0.0, 0.25], [0.25, 0.0, 0.25]], |
|
[[0.25, 0.0, 0.25], [-0.375, -0.375, 0.375], |
|
[-0.25, 0.25, 0.0], [-0.125, -0.125, 0.125]], |
|
[[-0.0, 0.0, 0.5], [0.25, -0.25, 0.25], [0.125, -0.125, 0.125]], |
|
[[0.125, 0.125, 0.125], [0.25, 0.0, 0.25], [0.25, 0.0, 0.25]], |
|
[[0.25, 0.0, 0.25], [0.25, 0.0, 0.25]], |
|
[[-0.125, -0.125, 0.125], [0.125, -0.125, 0.125]], |
|
[[0.125, 0.125, 0.125], [-0.125, -0.125, 0.125], [0.125, -0.125, 0.125]], |
|
[[-0.125, -0.125, 0.125], [0.0, -0.25, 0.25], [0.0, 0.25, -0.25]], |
|
[[0.0, -0.5, 0.0], [0.125, 0.125, -0.125], |
|
[0.25, 0.25, -0.25], [-0.125, -0.125, 0.125]], |
|
[[0.0, -0.25, 0.25], [0.0, -0.25, 0.25], [0.125, -0.125, 0.125]], |
|
[[0.0, 0.0, 0.5], [0.25, -0.25, 0.25], |
|
[0.125, -0.125, 0.125], [0.125, -0.125, 0.125]], |
|
[[0.0, -0.25, 0.25], [0.0, -0.25, 0.25], |
|
[0.0, -0.25, 0.25], [0.0, 0.25, -0.25]], |
|
[[0.0, 0.25, 0.25], [0.0, 0.25, 0.25], [0.125, -0.125, -0.125]], |
|
[[-0.125, 0.125, 0.125], [0.125, -0.125, 0.125], [-0.125, -0.125, 0.125]], |
|
[[-0.125, 0.125, 0.125], [0.125, -0.125, 0.125], |
|
[-0.125, -0.125, 0.125], [0.125, 0.125, 0.125]], |
|
[[-0.0, 0.0, 0.5], [-0.25, -0.25, 0.25], |
|
[-0.125, -0.125, 0.125], [-0.125, -0.125, 0.125]], |
|
[[0.125, 0.125, 0.125], [0.125, -0.125, 0.125], [0.125, -0.125, -0.125]], |
|
[[-0.0, 0.5, 0.0], [-0.25, 0.25, -0.25], |
|
[0.125, -0.125, 0.125], [0.125, -0.125, 0.125]], |
|
[[0.125, 0.125, 0.125], [-0.125, -0.125, 0.125], [0.125, -0.125, -0.125]], |
|
[[0.0, -0.25, -0.25], [0.0, 0.25, 0.25], [0.125, 0.125, 0.125]], |
|
[[0.125, 0.125, 0.125], [0.125, -0.125, -0.125]], |
|
[[0.5, 0.0, -0.0], [0.25, -0.25, -0.25], [0.125, -0.125, -0.125]], |
|
[[-0.25, 0.25, 0.25], [-0.125, 0.125, 0.125], |
|
[-0.25, 0.25, 0.25], [0.125, -0.125, -0.125]], |
|
[[0.375, -0.375, 0.375], [0.0, 0.25, 0.25], |
|
[-0.125, 0.125, -0.125], [-0.25, 0.0, 0.25]], |
|
[[0.0, -0.5, 0.0], [-0.25, 0.25, 0.25], [-0.125, 0.125, 0.125]], |
|
[[-0.375, -0.375, 0.375], [0.25, -0.25, 0.0], |
|
[0.0, 0.25, 0.25], [-0.125, -0.125, 0.125]], |
|
[[-0.125, 0.125, 0.125], [-0.25, 0.25, 0.25], [0.0, 0.0, 0.5]], |
|
[[0.125, 0.125, 0.125], [0.0, 0.25, 0.25], [0.0, 0.25, 0.25]], |
|
[[0.0, 0.25, 0.25], [0.0, 0.25, 0.25]], |
|
[[0.5, 0.0, -0.0], [0.25, 0.25, 0.25], |
|
[0.125, 0.125, 0.125], [0.125, 0.125, 0.125]], |
|
[[0.125, -0.125, 0.125], [-0.125, -0.125, 0.125], [0.125, 0.125, 0.125]], |
|
[[-0.25, -0.0, -0.25], [0.25, 0.0, 0.25], [0.125, 0.125, 0.125]], |
|
[[0.125, 0.125, 0.125], [0.125, -0.125, 0.125]], |
|
[[-0.25, -0.25, 0.0], [0.25, 0.25, -0.0], [0.125, 0.125, 0.125]], |
|
[[0.125, 0.125, 0.125], [-0.125, -0.125, 0.125]], |
|
[[0.125, 0.125, 0.125], [0.125, 0.125, 0.125]], |
|
[[0.125, 0.125, 0.125]], |
|
[[0.125, 0.125, 0.125]], |
|
[[0.125, 0.125, 0.125], [0.125, 0.125, 0.125]], |
|
[[0.125, 0.125, 0.125], [-0.125, -0.125, 0.125]], |
|
[[-0.25, -0.25, 0.0], [0.25, 0.25, -0.0], [0.125, 0.125, 0.125]], |
|
[[0.125, 0.125, 0.125], [0.125, -0.125, 0.125]], |
|
[[-0.25, -0.0, -0.25], [0.25, 0.0, 0.25], [0.125, 0.125, 0.125]], |
|
[[0.125, -0.125, 0.125], [-0.125, -0.125, 0.125], [0.125, 0.125, 0.125]], |
|
[[0.5, 0.0, -0.0], [0.25, 0.25, 0.25], |
|
[0.125, 0.125, 0.125], [0.125, 0.125, 0.125]], |
|
[[0.0, 0.25, 0.25], [0.0, 0.25, 0.25]], |
|
[[0.125, 0.125, 0.125], [0.0, 0.25, 0.25], [0.0, 0.25, 0.25]], |
|
[[-0.125, 0.125, 0.125], [-0.25, 0.25, 0.25], [0.0, 0.0, 0.5]], |
|
[[-0.375, -0.375, 0.375], [0.25, -0.25, 0.0], |
|
[0.0, 0.25, 0.25], [-0.125, -0.125, 0.125]], |
|
[[0.0, -0.5, 0.0], [-0.25, 0.25, 0.25], [-0.125, 0.125, 0.125]], |
|
[[0.375, -0.375, 0.375], [0.0, 0.25, 0.25], |
|
[-0.125, 0.125, -0.125], [-0.25, 0.0, 0.25]], |
|
[[-0.25, 0.25, 0.25], [-0.125, 0.125, 0.125], |
|
[-0.25, 0.25, 0.25], [0.125, -0.125, -0.125]], |
|
[[0.5, 0.0, -0.0], [0.25, -0.25, -0.25], [0.125, -0.125, -0.125]], |
|
[[0.125, 0.125, 0.125], [0.125, -0.125, -0.125]], |
|
[[0.0, -0.25, -0.25], [0.0, 0.25, 0.25], [0.125, 0.125, 0.125]], |
|
[[0.125, 0.125, 0.125], [-0.125, -0.125, 0.125], [0.125, -0.125, -0.125]], |
|
[[-0.0, 0.5, 0.0], [-0.25, 0.25, -0.25], |
|
[0.125, -0.125, 0.125], [0.125, -0.125, 0.125]], |
|
[[0.125, 0.125, 0.125], [0.125, -0.125, 0.125], [0.125, -0.125, -0.125]], |
|
[[-0.0, 0.0, 0.5], [-0.25, -0.25, 0.25], |
|
[-0.125, -0.125, 0.125], [-0.125, -0.125, 0.125]], |
|
[[-0.125, 0.125, 0.125], [0.125, -0.125, 0.125], |
|
[-0.125, -0.125, 0.125], [0.125, 0.125, 0.125]], |
|
[[-0.125, 0.125, 0.125], [0.125, -0.125, 0.125], [-0.125, -0.125, 0.125]], |
|
[[0.0, 0.25, 0.25], [0.0, 0.25, 0.25], [0.125, -0.125, -0.125]], |
|
[[0.0, -0.25, -0.25], [0.0, 0.25, 0.25], [0.0, 0.25, 0.25], [0.0, 0.25, 0.25]], |
|
[[0.0, 0.0, 0.5], [0.25, -0.25, 0.25], |
|
[0.125, -0.125, 0.125], [0.125, -0.125, 0.125]], |
|
[[0.0, -0.25, 0.25], [0.0, -0.25, 0.25], [0.125, -0.125, 0.125]], |
|
[[0.0, -0.5, 0.0], [0.125, 0.125, -0.125], |
|
[0.25, 0.25, -0.25], [-0.125, -0.125, 0.125]], |
|
[[-0.125, -0.125, 0.125], [0.0, -0.25, 0.25], [0.0, 0.25, -0.25]], |
|
[[0.125, 0.125, 0.125], [-0.125, -0.125, 0.125], [0.125, -0.125, 0.125]], |
|
[[-0.125, -0.125, 0.125], [0.125, -0.125, 0.125]], |
|
[[0.25, 0.0, 0.25], [0.25, 0.0, 0.25]], |
|
[[0.125, 0.125, 0.125], [0.25, 0.0, 0.25], [0.25, 0.0, 0.25]], |
|
[[-0.0, 0.0, 0.5], [0.25, -0.25, 0.25], [0.125, -0.125, 0.125]], |
|
[[0.25, 0.0, 0.25], [-0.375, -0.375, 0.375], |
|
[-0.25, 0.25, 0.0], [-0.125, -0.125, 0.125]], |
|
[[0.125, -0.125, 0.125], [0.25, 0.0, 0.25], [0.25, 0.0, 0.25]], |
|
[[-0.25, -0.0, -0.25], [0.25, 0.0, 0.25], |
|
[0.25, 0.0, 0.25], [0.25, 0.0, 0.25]], |
|
[[-0.0, 0.0, 0.5], [0.25, -0.25, 0.25], |
|
[0.125, -0.125, 0.125], [0.125, -0.125, 0.125]], |
|
[[-0.25, 0.0, 0.25], [0.25, 0.0, -0.25], [-0.125, 0.125, 0.125]], |
|
[[0.125, 0.125, 0.125], [0.25, 0.25, 0.25], [0.0, 0.0, 0.5]], |
|
[[0.125, 0.125, 0.125], [0.125, 0.125, 0.125], |
|
[0.25, 0.25, 0.25], [0.0, 0.0, 0.5]], |
|
[[-0.0, 0.0, 0.5], [0.0, 0.0, 0.5]], |
|
[[0.0, 0.0, -0.5], [0.25, 0.25, -0.25], [-0.125, -0.125, 0.125]], |
|
[[-0.25, -0.0, -0.25], [-0.375, 0.375, 0.375], |
|
[-0.25, -0.25, 0.0], [-0.125, 0.125, 0.125]], |
|
[[-0.125, -0.125, 0.125], [-0.25, 0.0, 0.25], [0.25, 0.0, -0.25]], |
|
[[-0.0, 0.0, 0.5], [-0.25, 0.25, 0.25], [-0.125, 0.125, 0.125]], |
|
[[-0.25, 0.0, 0.25], [0.25, 0.0, -0.25]], |
|
[[0.5, 0.0, 0.0], [-0.25, 0.25, -0.25], [0.125, -0.125, 0.125]], |
|
[[-0.25, 0.0, -0.25], [0.375, -0.375, -0.375], |
|
[0.0, 0.25, -0.25], [-0.125, 0.125, 0.125]], |
|
[[-0.25, 0.25, -0.25], [-0.25, 0.25, -0.25], |
|
[-0.125, 0.125, -0.125], [-0.125, 0.125, -0.125]], |
|
[[-0.0, 0.5, 0.0], [-0.25, 0.25, -0.25], [0.125, -0.125, 0.125]], |
|
[[0.5, 0.0, 0.0], [-0.25, -0.25, 0.25], |
|
[-0.125, -0.125, 0.125], [-0.125, -0.125, 0.125]], |
|
[[-0.125, -0.125, 0.125], [-0.25, 0.0, 0.25], [-0.25, 0.0, 0.25]], |
|
[[0.125, 0.125, 0.125], [-0.125, -0.125, 0.125], [-0.125, 0.125, 0.125]], |
|
[[-0.125, -0.125, 0.125], [-0.125, 0.125, 0.125]], |
|
[[0.375, -0.375, 0.375], [0.0, -0.25, -0.25], |
|
[-0.125, 0.125, -0.125], [0.25, 0.25, 0.0]], |
|
[[0.0, -0.25, 0.25], [0.0, -0.25, 0.25], [-0.125, -0.125, 0.125]], |
|
[[0.0, 0.0, 0.5], [0.25, -0.25, 0.25], [0.125, -0.125, 0.125]], |
|
[[0.0, -0.25, 0.25], [0.0, -0.25, 0.25]], |
|
[[-0.125, -0.125, 0.125], [-0.25, -0.25, 0.0], [0.25, 0.25, -0.0]], |
|
[[-0.125, -0.125, 0.125], [-0.125, -0.125, 0.125]], |
|
[[0.125, 0.125, 0.125], [-0.125, -0.125, 0.125]], |
|
[[-0.125, -0.125, 0.125]], |
|
[[-0.25, -0.25, 0.0], [-0.25, -0.25, 0.0]], |
|
[[0.125, 0.125, 0.125], [-0.25, -0.25, 0.0], [-0.25, -0.25, 0.0]], |
|
[[-0.25, -0.25, 0.0], [-0.25, -0.25, 0.0], [-0.125, -0.125, 0.125]], |
|
[[-0.25, -0.25, 0.0], [-0.25, -0.25, 0.0], |
|
[-0.25, -0.25, 0.0], [0.25, 0.25, -0.0]], |
|
[[0.0, 0.5, 0.0], [0.25, 0.25, -0.25], [-0.125, -0.125, 0.125]], |
|
[[-0.375, 0.375, -0.375], [-0.25, -0.25, 0.0], |
|
[-0.125, 0.125, -0.125], [-0.25, 0.0, 0.25]], |
|
[[0.0, 0.5, 0.0], [0.25, 0.25, -0.25], |
|
[-0.125, -0.125, 0.125], [-0.125, -0.125, 0.125]], |
|
[[-0.125, 0.125, 0.125], [0.25, -0.25, 0.0], [-0.25, 0.25, 0.0]], |
|
[[0.0, -0.5, 0.0], [-0.25, -0.25, -0.25], [-0.125, -0.125, -0.125]], |
|
[[0.125, 0.125, 0.125], [0.0, -0.5, 0.0], |
|
[-0.25, -0.25, -0.25], [-0.125, -0.125, -0.125]], |
|
[[-0.375, -0.375, -0.375], [-0.25, 0.0, 0.25], |
|
[-0.125, -0.125, -0.125], [-0.25, 0.25, 0.0]], |
|
[[0.25, -0.25, 0.0], [-0.25, 0.25, 0.0], [0.125, -0.125, 0.125]], |
|
[[0.0, 0.5, 0.0], [0.0, -0.5, 0.0]], |
|
[[0.0, 0.5, 0.0], [0.125, -0.125, 0.125], [-0.25, 0.25, -0.25]], |
|
[[0.0, 0.5, 0.0], [-0.25, 0.25, 0.25], [0.125, -0.125, -0.125]], |
|
[[0.25, -0.25, 0.0], [-0.25, 0.25, 0.0]], |
|
[[-0.5, 0.0, 0.0], [-0.25, -0.25, 0.25], [-0.125, -0.125, 0.125]], |
|
[[0.0, 0.25, -0.25], [0.375, -0.375, -0.375], |
|
[-0.125, 0.125, 0.125], [0.25, 0.25, 0.0]], |
|
[[0.5, 0.0, 0.0], [0.25, -0.25, 0.25], |
|
[-0.125, 0.125, -0.125], [0.125, -0.125, 0.125]], |
|
[[0.125, -0.125, 0.125], [0.25, -0.25, 0.0], [0.25, -0.25, 0.0]], |
|
[[0.25, 0.25, -0.25], [0.25, 0.25, -0.25], |
|
[0.125, 0.125, -0.125], [-0.125, -0.125, 0.125]], |
|
[[-0.0, 0.0, 0.5], [-0.25, -0.25, 0.25], [-0.125, -0.125, 0.125]], |
|
[[0.125, 0.125, 0.125], [0.125, -0.125, 0.125], [-0.125, 0.125, 0.125]], |
|
[[-0.125, 0.125, 0.125], [0.125, -0.125, 0.125]], |
|
[[-0.375, -0.375, 0.375], [-0.0, 0.25, 0.25], |
|
[0.125, 0.125, -0.125], [-0.25, -0.0, -0.25]], |
|
[[0.0, -0.25, 0.25], [0.0, 0.25, -0.25], [0.125, -0.125, 0.125]], |
|
[[0.125, -0.125, 0.125], [-0.25, -0.0, -0.25], [0.25, 0.0, 0.25]], |
|
[[0.125, -0.125, 0.125], [0.125, -0.125, 0.125]], |
|
[[0.0, -0.5, 0.0], [0.125, 0.125, -0.125], [0.25, 0.25, -0.25]], |
|
[[0.0, -0.25, 0.25], [0.0, 0.25, -0.25]], |
|
[[0.125, 0.125, 0.125], [0.125, -0.125, 0.125]], |
|
[[0.125, -0.125, 0.125]], |
|
[[-0.5, 0.0, 0.0], [-0.125, -0.125, -0.125], [-0.25, -0.25, -0.25]], |
|
[[-0.5, 0.0, 0.0], [-0.125, -0.125, -0.125], |
|
[-0.25, -0.25, -0.25], [0.125, 0.125, 0.125]], |
|
[[0.375, 0.375, 0.375], [0.0, 0.25, -0.25], |
|
[-0.125, -0.125, -0.125], [-0.25, 0.25, 0.0]], |
|
[[0.125, -0.125, -0.125], [0.25, -0.25, 0.0], [0.25, -0.25, 0.0]], |
|
[[0.125, 0.125, 0.125], [0.375, 0.375, 0.375], |
|
[0.0, -0.25, 0.25], [-0.25, 0.0, 0.25]], |
|
[[-0.25, 0.0, 0.25], [-0.25, 0.0, 0.25], [0.125, -0.125, -0.125]], |
|
[[0.0, -0.25, -0.25], [0.0, 0.25, 0.25], [-0.125, 0.125, 0.125]], |
|
[[-0.125, 0.125, 0.125], [0.125, -0.125, -0.125]], |
|
[[-0.125, -0.125, -0.125], [-0.25, -0.25, -0.25], |
|
[0.25, 0.25, 0.25], [0.125, 0.125, 0.125]], |
|
[[-0.125, -0.125, 0.125], [0.125, -0.125, 0.125], [0.125, -0.125, -0.125]], |
|
[[0.0, 0.0, -0.5], [0.25, 0.25, 0.25], [-0.125, -0.125, -0.125]], |
|
[[0.125, -0.125, 0.125], [0.125, -0.125, -0.125]], |
|
[[0.0, -0.5, 0.0], [0.25, 0.25, 0.25], [0.125, 0.125, 0.125]], |
|
[[-0.125, -0.125, 0.125], [0.125, -0.125, -0.125]], |
|
[[0.0, -0.25, -0.25], [0.0, 0.25, 0.25]], |
|
[[0.125, -0.125, -0.125]], |
|
[[0.5, 0.0, 0.0], [0.5, 0.0, 0.0]], |
|
[[-0.5, 0.0, 0.0], [-0.25, 0.25, 0.25], [-0.125, 0.125, 0.125]], |
|
[[0.5, 0.0, 0.0], [0.25, -0.25, 0.25], [-0.125, 0.125, -0.125]], |
|
[[0.25, -0.25, 0.0], [0.25, -0.25, 0.0]], |
|
[[0.5, 0.0, 0.0], [-0.25, -0.25, 0.25], [-0.125, -0.125, 0.125]], |
|
[[-0.25, 0.0, 0.25], [-0.25, 0.0, 0.25]], |
|
[[0.125, 0.125, 0.125], [-0.125, 0.125, 0.125]], |
|
[[-0.125, 0.125, 0.125]], |
|
[[0.5, 0.0, -0.0], [0.25, 0.25, 0.25], [0.125, 0.125, 0.125]], |
|
[[0.125, -0.125, 0.125], [-0.125, -0.125, 0.125]], |
|
[[-0.25, -0.0, -0.25], [0.25, 0.0, 0.25]], |
|
[[0.125, -0.125, 0.125]], |
|
[[-0.25, -0.25, 0.0], [0.25, 0.25, -0.0]], |
|
[[-0.125, -0.125, 0.125]], |
|
[[0.125, 0.125, 0.125]], |
|
[[0, 0, 0]]] |
|
|
|
|
|
|
|
def create_table_neighbour_code_to_surface_area(spacing_mm): |
|
"""Returns an array mapping neighbourhood code to the surface elements area. |
|
Note that the normals encode the initial surface area. This function computes |
|
the area corresponding to the given `spacing_mm`. |
|
Args: |
|
spacing_mm: 3-element list-like structure. Voxel spacing in x0, x1 and x2 |
|
direction. |
|
""" |
|
|
|
|
|
neighbour_code_to_surface_area = np.zeros([256]) |
|
for code in range(256): |
|
normals = np.array(_NEIGHBOUR_CODE_TO_NORMALS[code]) |
|
sum_area = 0 |
|
for normal_idx in range(normals.shape[0]): |
|
|
|
n = np.zeros([3]) |
|
n[0] = normals[normal_idx, 0] * spacing_mm[1] * spacing_mm[2] |
|
n[1] = normals[normal_idx, 1] * spacing_mm[0] * spacing_mm[2] |
|
n[2] = normals[normal_idx, 2] * spacing_mm[0] * spacing_mm[1] |
|
area = np.linalg.norm(n) |
|
sum_area += area |
|
neighbour_code_to_surface_area[code] = sum_area |
|
|
|
return neighbour_code_to_surface_area |
|
|
|
|
|
|
|
|
|
ENCODE_NEIGHBOURHOOD_2D_KERNEL = np.array([[8, 4], [2, 1]]) |
|
|
|
|
|
def create_table_neighbour_code_to_contour_length(spacing_mm): |
|
"""Returns an array mapping neighbourhood code to the contour length. |
|
For the list of possible cases and their figures, see page 38 from: |
|
https://nccastaff.bournemouth.ac.uk/jmacey/MastersProjects/MSc14/06/thesis.pdf |
|
In 2D, each point has 4 neighbors. Thus, are 16 configurations. A |
|
configuration is encoded with '1' meaning "inside the object" and '0' "outside |
|
the object". The points are ordered: top left, top right, bottom left, bottom |
|
right. |
|
The x0 axis is assumed vertical downward, and the x1 axis is horizontal to the |
|
right: |
|
(0, 0) --> (0, 1) |
|
| |
|
(1, 0) |
|
Args: |
|
spacing_mm: 2-element list-like structure. Voxel spacing in x0 and x1 |
|
directions. |
|
""" |
|
neighbour_code_to_contour_length = np.zeros([16]) |
|
|
|
vertical = spacing_mm[0] |
|
horizontal = spacing_mm[1] |
|
diag = 0.5 * math.sqrt(spacing_mm[0]**2 + spacing_mm[1]**2) |
|
|
|
neighbour_code_to_contour_length[int("00" |
|
"01", 2)] = diag |
|
|
|
neighbour_code_to_contour_length[int("00" |
|
"10", 2)] = diag |
|
|
|
neighbour_code_to_contour_length[int("00" |
|
"11", 2)] = horizontal |
|
|
|
neighbour_code_to_contour_length[int("01" |
|
"00", 2)] = diag |
|
|
|
neighbour_code_to_contour_length[int("01" |
|
"01", 2)] = vertical |
|
|
|
neighbour_code_to_contour_length[int("01" |
|
"10", 2)] = 2*diag |
|
|
|
neighbour_code_to_contour_length[int("01" |
|
"11", 2)] = diag |
|
|
|
neighbour_code_to_contour_length[int("10" |
|
"00", 2)] = diag |
|
|
|
neighbour_code_to_contour_length[int("10" |
|
"01", 2)] = 2*diag |
|
|
|
neighbour_code_to_contour_length[int("10" |
|
"10", 2)] = vertical |
|
|
|
neighbour_code_to_contour_length[int("10" |
|
"11", 2)] = diag |
|
|
|
neighbour_code_to_contour_length[int("11" |
|
"00", 2)] = horizontal |
|
|
|
neighbour_code_to_contour_length[int("11" |
|
"01", 2)] = diag |
|
|
|
neighbour_code_to_contour_length[int("11" |
|
"10", 2)] = diag |
|
|
|
|
|
return neighbour_code_to_contour_length |