def create_positive_canonical_and_noisy_examples_from_mask(self, im_arr, full_seg_im, orig_seg_patch, pic_patch,
bbox_patch, pic_id, seg_id, stats):
created_examples = 0
offsets = [-translation_shift, 0, translation_shift]
scales = [pow(2.0, scale_deformation), 1, pow(2.0, -scale_deformation)]
[orig_patch_center_x, orig_patch_center_y] = orig_seg_patch.center()
[orig_patch_width, orig_patch_height] = orig_seg_patch.size()
for scale_i in range(len(scales)):
for x_offset_i in range(len(offsets)):
for y_offset_i in range(len(offsets)):
new_patch_width = orig_patch_width * scales[scale_i]
new_patch_height = orig_patch_height * scales[scale_i]
new_patch_min_x = orig_patch_center_x - new_patch_width / 2 + offsets[x_offset_i]
new_patch_min_y = orig_patch_center_y - new_patch_height / 2 + offsets[y_offset_i]
new_patch = Patch(new_patch_min_x, new_patch_width, new_patch_min_y, new_patch_height)
if self.patch_exceeds_pic(new_patch, pic_patch):
stats.pos_noisy_seg_too_close_to_edges += 1
continue
if self.patch_exceeds_seg(new_patch, bbox_patch):
# this will not happen with the default constants (input size, max object dimension)
stats.pos_noisy_seg_cuts_seg += 1
continue
img_path = self.create_path(self.positive_output_dir, 'pos', 'im', pic_id, seg_id, x_offset_i,
y_offset_i, scale_i)
patch_im = self.create_and_save_image_patch(im_arr, new_patch, img_path)
mask_path = self.create_path(self.positive_output_dir, 'pos', 'mask', pic_id, seg_id,
x_offset_i, y_offset_i, scale_i)
patch_seg_im = self.create_and_save_mask(full_seg_im, new_patch, mask_path)
self.create_and_save_mirror(self.positive_output_dir, 'pos', patch_seg_im, patch_im, pic_id,
seg_id, x_offset_i, y_offset_i, scale_i)
created_examples += 2 # example and mirror
return created_examples
评论列表
文章目录