MCPcopy Create free account
hub / github.com/UX-Decoder/Semantic-SAM / apply_coords

Method apply_coords

utils/sam_utils/transforms.py:33–45  ·  view source on GitHub ↗

Expects a numpy array of length 2 in the final dimension. Requires the original image size in (H, W) format.

(self, coords: np.ndarray, original_size: Tuple[int, ...])

Source from the content-addressed store, hash-verified

31 return np.array(resize(to_pil_image(image), target_size))
32
33 def apply_coords(self, coords: np.ndarray, original_size: Tuple[int, ...]) -> np.ndarray:
34 """
35 Expects a numpy array of length 2 in the final dimension. Requires the
36 original image size in (H, W) format.
37 """
38 old_h, old_w = original_size
39 new_h, new_w = self.get_preprocess_shape(
40 original_size[0], original_size[1], self.target_length
41 )
42 coords = deepcopy(coords).astype(float)
43 coords[..., 0] = coords[..., 0] * (new_w / old_w)
44 coords[..., 1] = coords[..., 1] * (new_h / old_h)
45 return coords
46
47 def apply_boxes(self, boxes: np.ndarray, original_size: Tuple[int, ...]) -> np.ndarray:
48 """

Callers 1

apply_boxesMethod · 0.95

Calls 1

get_preprocess_shapeMethod · 0.95

Tested by

no test coverage detected