MCPcopy Create free account
hub / github.com/aigc3d/LHM / ratio_mapping

Method ratio_mapping

engine/SegmentAPI/SAM.py:364–391  ·  view source on GitHub ↗
(self, img)

Source from the content-addressed store, hash-verified

362 return scale_box, pha[..., 0].astype(np.float32) / 255.0
363
364 def ratio_mapping(self, img):
365
366 my_ratio_map = self.RATIO_MAP
367
368 ratio_landmarks = [v[0] for v in my_ratio_map]
369
370 ratio_v = [v[1] for v in my_ratio_map]
371 h, w, _ = img.shape
372
373 max_length = min(h, w)
374
375 low_bound = bisect_left(
376 ratio_landmarks, max_length, lo=0, hi=len(ratio_landmarks)
377 )
378
379 if 0 == low_bound:
380 return 1.0
381 elif low_bound == len(ratio_landmarks):
382 return ratio_v[-1]
383 else:
384 _l = ratio_v[low_bound - 1]
385 _r = ratio_v[low_bound]
386
387 _l_land = ratio_landmarks[low_bound - 1]
388 _r_land = ratio_landmarks[low_bound]
389 cur_ratio = _l + (_r - _l) * (max_length - _l_land) / (_r_land - _l_land)
390
391 return cur_ratio
392
393 def get_img(self, img_path, sup_res=True):
394

Callers 1

predict_bboxMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected