MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / create_table_neighbour_code_to_contour_length

Function create_table_neighbour_code_to_contour_length

monai/metrics/utils.py:839–878  ·  view source on GitHub ↗

Returns an array mapping neighbourhood code to the contour length. Adapted from https://github.com/deepmind/surface-distance 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 obje

(spacing_mm, device=None)

Source from the content-addressed store, hash-verified

837
838
839def create_table_neighbour_code_to_contour_length(spacing_mm, device=None):
840 """
841 Returns an array mapping neighbourhood code to the contour length.
842 Adapted from https://github.com/deepmind/surface-distance
843
844 In 2D, each point has 4 neighbors. Thus, are 16 configurations. A
845 configuration is encoded with '1' meaning "inside the object" and '0' "outside
846 the object". For example,
847 "0101" and "1010" both encode an edge along the first spatial axis with length spacing[0] mm;
848 "0011" and "1100" both encode an edge along the second spatial axis with length spacing[1] mm.
849
850 Args:
851 spacing_mm: 2-element list-like structure. Pixel spacing along the 1st and 2nd spatial axes.
852 device: device to put the table on.
853
854 Returns:
855 A 16-element array mapping neighbourhood code to the contour length.
856 ENCODING_KERNEL[2] which is the kernel used to compute the neighbourhood code.
857 """
858 spacing_mm = ensure_tuple_rep(spacing_mm, 2)
859 first, second = spacing_mm # spacing along the first and second spatial dimension respectively
860 diag = 0.5 * np.linalg.norm(spacing_mm)
861
862 neighbour_code_to_contour_length = np.zeros([16], dtype=diag.dtype)
863 neighbour_code_to_contour_length[int("0001", 2)] = diag
864 neighbour_code_to_contour_length[int("0010", 2)] = diag
865 neighbour_code_to_contour_length[int("0011", 2)] = second
866 neighbour_code_to_contour_length[int("0100", 2)] = diag
867 neighbour_code_to_contour_length[int("0101", 2)] = first
868 neighbour_code_to_contour_length[int("0110", 2)] = 2 * diag
869 neighbour_code_to_contour_length[int("0111", 2)] = diag
870 neighbour_code_to_contour_length[int("1000", 2)] = diag
871 neighbour_code_to_contour_length[int("1001", 2)] = 2 * diag
872 neighbour_code_to_contour_length[int("1010", 2)] = first
873 neighbour_code_to_contour_length[int("1011", 2)] = diag
874 neighbour_code_to_contour_length[int("1100", 2)] = second
875 neighbour_code_to_contour_length[int("1101", 2)] = diag
876 neighbour_code_to_contour_length[int("1110", 2)] = diag
877 neighbour_code_to_contour_length = convert_to_tensor(neighbour_code_to_contour_length, device=device)
878 return neighbour_code_to_contour_length, torch.as_tensor([[ENCODING_KERNEL[2]]], device=device)
879
880
881def get_code_to_measure_table(spacing, device=None):

Callers 1

Calls 3

ensure_tuple_repFunction · 0.90
convert_to_tensorFunction · 0.90
as_tensorMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…