MCPcopy Create free account
hub / github.com/ImprintLab/Medical-SAM2 / random_click

Function random_click

func_3d/utils.py:90–105  ·  view source on GitHub ↗
(mask, point_labels = 1, seed=None)

Source from the content-addressed store, hash-verified

88 torch.save(states, os.path.join(output_dir, 'checkpoint_best.pth'))
89
90def random_click(mask, point_labels = 1, seed=None):
91 # check if all masks are black
92 max_label = max(set(mask.flatten()))
93 if max_label == 0:
94 point_labels = max_label
95 # max agreement position
96 indices = np.argwhere(mask == max_label)
97 # return point_labels, indices[np.random.randint(len(indices))]
98 if seed is not None:
99 rand_instance = random.Random(seed)
100 rand_num = rand_instance.randint(0, len(indices) - 1)
101 else:
102 rand_num = random.randint(0, len(indices) - 1)
103 output_index_1 = indices[rand_num][0]
104 output_index_0 = indices[rand_num][1]
105 return point_labels, np.array([output_index_0, output_index_1])
106
107def generate_bbox(mask, variation=0, seed=None):
108 if seed is not None:

Callers 2

__getitem__Method · 0.90
__getitem__Method · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected