inferece image, _, _ = preprocess_image(image_path, mask_path=None, intr=None, pad_ratio=0, bg_color=1.0, max_tgt_size=896, aspect_standard=aspect_standard, enlarge_ratio=[1.0, 1.0], render_tgt_size=source_size, mult
(
rgb_path,
mask,
intr,
pad_ratio,
bg_color,
max_tgt_size,
aspect_standard,
enlarge_ratio,
render_tgt_size,
multiply,
need_mask=True,
)
| 101 | |
| 102 | |
| 103 | def infer_preprocess_image( |
| 104 | rgb_path, |
| 105 | mask, |
| 106 | intr, |
| 107 | pad_ratio, |
| 108 | bg_color, |
| 109 | max_tgt_size, |
| 110 | aspect_standard, |
| 111 | enlarge_ratio, |
| 112 | render_tgt_size, |
| 113 | multiply, |
| 114 | need_mask=True, |
| 115 | ): |
| 116 | """inferece |
| 117 | image, _, _ = preprocess_image(image_path, mask_path=None, intr=None, pad_ratio=0, bg_color=1.0, |
| 118 | max_tgt_size=896, aspect_standard=aspect_standard, enlarge_ratio=[1.0, 1.0], |
| 119 | render_tgt_size=source_size, multiply=14, need_mask=True) |
| 120 | |
| 121 | """ |
| 122 | |
| 123 | rgb = np.array(Image.open(rgb_path)) |
| 124 | rgb_raw = rgb.copy() |
| 125 | |
| 126 | bbox = get_bbox(mask) |
| 127 | bbox_list = bbox.get_box() |
| 128 | |
| 129 | rgb = rgb[bbox_list[1] : bbox_list[3], bbox_list[0] : bbox_list[2]] |
| 130 | mask = mask[bbox_list[1] : bbox_list[3], bbox_list[0] : bbox_list[2]] |
| 131 | |
| 132 | |
| 133 | h, w, _ = rgb.shape |
| 134 | assert w < h |
| 135 | cur_ratio = h / w |
| 136 | scale_ratio = cur_ratio / aspect_standard |
| 137 | |
| 138 | |
| 139 | target_w = int(min(w * scale_ratio, h)) |
| 140 | if target_w - w >0: |
| 141 | offset_w = (target_w - w) // 2 |
| 142 | |
| 143 | rgb = np.pad( |
| 144 | rgb, |
| 145 | ((0, 0), (offset_w, offset_w), (0, 0)), |
| 146 | mode="constant", |
| 147 | constant_values=255, |
| 148 | ) |
| 149 | |
| 150 | mask = np.pad( |
| 151 | mask, |
| 152 | ((0, 0), (offset_w, offset_w)), |
| 153 | mode="constant", |
| 154 | constant_values=0, |
| 155 | ) |
| 156 | else: |
| 157 | target_h = w * aspect_standard |
| 158 | offset_h = int(target_h - h) |
| 159 | |
| 160 | rgb = np.pad( |
no test coverage detected