def crop(self, big_rad: int, small_rad: int, center_coord: Coordinate, angle: int, index_list: list = None): ring_crop_helper = RingCropHelper(img_object=self.img_object, big_rad=big_rad, small_rad=small_rad) ring_crop_helper.crop_ring(center_coord=center_coord) crop_rotate_ring_piece_list = ring_crop_helper.get_crop_rotate_ring_piece_list( angle=angle) if index_list is None: index_list = [i for i in range(len(crop_rotate_ring_piece_list))] # Checking defect for defect in self.defect_list: # Crop D 에서 defect 가 있을 때 if defect.is_defect_in_cropped_img(img_center_coord=center_coord, margin_min=small_rad, margin_max=big_rad): for crop_rotate_ring_piece in crop_rotate_ring_piece_list: ring_crop_helper.relocate_defect( img_object=crop_rotate_ring_piece, defect=defect) # 해당하는 index 의 이미지만 반환 return [crop_rotate_ring_piece_list[i] for i in index_list]
def crop(self, inner_circle_rad: int, inner_circle_center_coord: Coordinate, outer_circle_rad: int, outer_circle_center_coord: Coordinate, ring_small_rad: int, angle: int): inner_circle_crop_helper = CircleCropHelper( img_object=self.img_object, center_coord=inner_circle_center_coord, rad=inner_circle_rad) inner_circle_crop_mask = inner_circle_crop_helper.get_circle_mask( inverse=True) outer_circle_crop_helper = CircleCropHelper( img_object=self.img_object, center_coord=outer_circle_center_coord, rad=outer_circle_rad) outer_circle_crop_mask = outer_circle_crop_helper.get_circle_mask( inverse=False) crop_ring_mask = inner_circle_crop_mask * outer_circle_crop_mask ring_crop_helper = RingCropHelper(img_object=self.img_object, big_rad=outer_circle_rad, small_rad=ring_small_rad) # Switching image img_original = self.img_object.img self.img_object.img = self.img_object.img * crop_ring_mask ring_crop_helper.crop_ring(center_coord=outer_circle_center_coord) crop_rotate_ring_piece_list = ring_crop_helper.get_crop_rotate_ring_piece_list( angle=angle) self.img_object.img = img_original # Checking defect for defect in self.defect_list: # Crop C 바깥에 위치한 경우 is_first_circle_outside = defect.is_defect_in_cropped_img( img_center_coord=inner_circle_center_coord, margin_min=inner_circle_rad, margin_max=2000 # Temp ) # Crop D 외곽 반지름 안에 위치한 경우 is_second_circle_inside = defect.is_defect_in_cropped_img( img_center_coord=outer_circle_center_coord, margin_min=1, # Temp margin_max=outer_circle_rad) if is_first_circle_outside and is_second_circle_inside: for crop_rotate_ring_piece in crop_rotate_ring_piece_list: ring_crop_helper.relocate_defect( img_object=crop_rotate_ring_piece, defect=defect) return crop_rotate_ring_piece_list
def crop(self, big_rad: int, small_rad: int, center_coord: Coordinate, angle: int): ring_crop_helper = RingCropHelper(img_object=self.img_object, big_rad=big_rad, small_rad=small_rad) ring_crop_helper.crop_ring(center_coord=center_coord) crop_rotate_ring_piece_list = ring_crop_helper.get_crop_rotate_ring_piece_list( angle=angle) # Checking defect for defect in self.defect_list: if defect.is_defect_in_cropped_img(img_center_coord=center_coord, margin_min=small_rad, margin_max=big_rad): for crop_rotate_ring_piece in crop_rotate_ring_piece_list: ring_crop_helper.relocate_defect( img_object=crop_rotate_ring_piece, defect=defect) return crop_rotate_ring_piece_list
def crop(self, big_rad: int, small_rad: int, center_coord: Coordinate): ring_crop_helper = RingCropHelper(img_object=self.img_object, big_rad=big_rad, small_rad=small_rad) ring_crop_helper.crop_ring(center_coord=center_coord) cropped_img_object = ring_crop_helper.cropped_img_object # Checking defect for defect in self.defect_list: # Crop A 에서 defect 가 있을 때 if defect.is_defect_in_cropped_img(img_center_coord=center_coord, margin_min=small_rad, margin_max=big_rad): ring_crop_helper.relocate_defect(img_object=cropped_img_object, defect=defect) return [cropped_img_object]