| 249 | |
| 250 | |
| 251 | class PadImage(object): |
| 252 | def __init__(self, size): |
| 253 | self.size = size |
| 254 | self.ignore_index = cfg.DATASET.IGNORE_LABEL |
| 255 | |
| 256 | |
| 257 | def __call__(self, img, mask): |
| 258 | assert img.size == mask.size |
| 259 | th, tw = self.size, self.size |
| 260 | |
| 261 | |
| 262 | w, h = img.size |
| 263 | |
| 264 | if w > tw or h > th : |
| 265 | wpercent = (tw/float(w)) |
| 266 | target_h = int((float(img.size[1])*float(wpercent))) |
| 267 | img, mask = img.resize((tw, target_h), Image.BICUBIC), mask.resize((tw, target_h), Image.NEAREST) |
| 268 | |
| 269 | w, h = img.size |
| 270 | ##Pad |
| 271 | img = ImageOps.expand(img, border=(0,0,tw-w, th-h), fill=0) |
| 272 | mask = ImageOps.expand(mask, border=(0,0,tw-w, th-h), fill=self.ignore_index) |
| 273 | |
| 274 | return img, mask |
| 275 | |
| 276 | class RandomHorizontallyFlip(object): |
| 277 | def __call__(self, img, mask): |
nothing calls this directly
no outgoing calls
no test coverage detected