segment
data.dataclass.segment
contours_area_methods
module-attribute
contours_area_methods = {'exact': compute_contours_area_exact, 'fast': compute_contours_area_fast, 'fast_plus': compute_contours_area_fast_plus, 'fast_plusplus': compute_contours_area_fast_plusplus}
SegmentBox
dataclass
from_xywh
classmethod
from_xywh(left, top, width, height) -> SegmentBox
from_xyxy
classmethod
from_xyxy(left, top, right, bottom) -> SegmentBox
Segment
Segment(bounding_box: Optional[SegmentBox] = None, bitmap: Optional[ndarray] = None, contours: Optional[Contours] = None, class_index: Optional[int] = None)
Segment 타입을 정의합니다. (= SegmentedObject) Segmentation 라벨링 혹은 모델의 예측 결과로 나오는 연결된 픽셀 덩어리이며, 1개의 outer polygon과 여러개의 inner polygon (도넛 형태인 경우) 으로 구성된 오브젝트입니다.
해당 오브젝트를 표현하는 방식은 2가지가 존재하며, segment를 이용해 어떤 연산을 수행하는가에 따라 다른 표현 방식이 필요합니다. 1. bounding_box & bitmap: SegmentBox & np.ndarray 2. contours: Sequence[np.ndarray]
Segment 오브젝트를 생성하기 위해서는 1가지 표현의 데이터만 필요하고, 다른 표현이 필요한 연산의 경우 lazy 한 방식으로 해당 표현을 계산합니다.
Segment 오브젝트 생성 시 bounding_box, bitmap 과 contours가 모두 주어진 경우, 서로 일치하는지 확인하지 않습니다.
Segment 오브젝트 생성 시 bounding_box, bitmap 표현이 주어진 경우 모든 픽셀이 연결되어 있는지 확인하지 않습니다.
Parameters:
-
bounding_box(Optional[SegmentBox], default:None) –description. Defaults to None.
-
bitmap(Optional[Bitmap], default:None) –description. Defaults to None.
-
contours(Optional[Contours], default:None) –description. Defaults to None.
-
class_index(Optional[int], default:None) –description. Defaults to None.
Source code in SaigeToolkit/data/dataclass/segment.py
from_xyhw_and_bitmap
classmethod
from_xyhw_and_bitmap(bounding_box: List[int], bitmap: Bitmap, class_index: Optional[int] = None, contours: Optional[Contours] = None, **ignore) -> Segment
Source code in SaigeToolkit/data/dataclass/segment.py
from_any
classmethod
Source code in SaigeToolkit/data/dataclass/segment.py
get_bounding_box_from_contours
get_bounding_box_from_contours(contours: Contours) -> SegmentBox
contours의 bounding box를 구합니다.
convert_contours_to_box_and_bitmap
convert_contours_to_box_and_bitmap(contours: Contours, bounding_box: Optional[SegmentBox] = None) -> Tuple[SegmentBox, Bitmap]
contours를 bounding_box 와 bitmap representation으로 변환합니다
Source code in SaigeToolkit/data/dataclass/segment.py
convert_box_and_bitmap_to_contours
convert_box_and_bitmap_to_contours(bitmap: Bitmap, bounding_box: Optional[SegmentBox] = None) -> Contours
bounding_box 와 bitmap을 contours representation으로 변환합니다
Source code in SaigeToolkit/data/dataclass/segment.py
compute_box_intersection
compute_box_intersection(box1: SegmentBox, box2: SegmentBox) -> Optional[SegmentBox]
intersecting box를 계산합니다. 겹치지 않는 경우 None
Source code in SaigeToolkit/data/dataclass/segment.py
to_segments
List[Union[Segment, Dict]]를을 List[Segment]들로 변환합니다
merge_segments
여러 Segment들을 하나의 Segment로 합칩니다. (union)
Source code in SaigeToolkit/data/dataclass/segment.py
compute_contours_area_exact
compute_contours_area_exact(contours: Contours) -> int
bounding box 크기의 이미지에 contour를 그린 뒤 픽셀 개수 카운트
compute_contours_area_fast
compute_contours_area_fast(contours: Contours) -> int
cv2.contourArea() 로 contour 면적 계산: contour 테두리를 0.5 픽셀 제외하고 계산되는 듯. average error: 17.08%
Source code in SaigeToolkit/data/dataclass/segment.py
compute_contours_area_fast_plus
compute_contours_area_fast_plus(contours: Contours) -> int
cv2.contourArea() 로 contour 면적 계산, outer의 경우 cv2.arcLength() 더해줌 average error: 1.50%
Source code in SaigeToolkit/data/dataclass/segment.py
compute_contours_area_fast_plusplus
compute_contours_area_fast_plusplus(contours: Contours) -> int
cv2.contourArea() + cv2.arcLength() 로 contour 면적 계산 average error: 1.58%
Source code in SaigeToolkit/data/dataclass/segment.py
compute_contours_area
compute_contours_area(contours: Contours, method: str) -> int
contours의 면적을 계산합니다. 참고: https://www.notion.so/65e5a56b2b8744bea087b1a0d2f9bfbf
Source code in SaigeToolkit/data/dataclass/segment.py
compute_segment_intersection_area
두 Segment 사이의 겹치는 영역 넓이를 계산합니다. bounding_box를 이용해 겹치는 박스를 먼저 계산한 뒤 해당 박스만 잘라서 겹치는 픽셀 수를 셉니다.
Source code in SaigeToolkit/data/dataclass/segment.py
compute_segment_score
compute_segment_score(segment: Segment, scoremap: ndarray, method: str = 'mean', return_float: bool = False) -> Union[float, int]
scoremap 중 segment 영역의 score를 대표하는 값을 계산합니다.
Source code in SaigeToolkit/data/dataclass/segment.py
compute_segment_properties_and_apply_threshold
compute_segment_properties_and_apply_threshold(segment: Segment, calc_area_and_apply_threshold: bool = False, area_method: str = 'fast_plus', area_threshold: int = 0, calc_score_and_apply_threshold: bool = False, scoremap: Optional[ndarray] = None, score_method: str = 'mean', score_threshold: Union[float, int] = 0, score_as_float: bool = False) -> Optional[Dict]
API 계산 결과로 필요한 Segment의 property 들을 계산하고 threshold를 적용합니다. threshold에 걸리지 않는 경우 각 property들의 Dict를, threshold 에 걸리는 경우 None을 리턴합니다. 계산 로직은 다음과 순서로 적용됩니다.
calc_object_area_and_apply_threshold=True인 경우- area 계산
- area_threshold 적용
calc_object_score_and_apply_threshold=True인 경우- score 계산
- score_threshold 적용
- 아래 항목들 계산
- bounding_box
- bounding_rotated_box
- fitted_ellipse
Parameters:
-
segment(Segment) –segment
Returns:
-
Optional[Dict]–Optional[Dict]: segment property dictionary. threshold에 걸려서 필터링 된 경우 None
Source code in SaigeToolkit/data/dataclass/segment.py
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 | |
scale_segments_properties
scale_segment_properties
Source code in SaigeToolkit/data/dataclass/segment.py
translate_segments_properties
translate_segments_properties(segments_properties: List[Dict], left: int, top: int, **kwargs) -> List[Dict]