warp
(img, use_tia=True, prob=0.4, angz=2)
| 315 | |
| 316 | |
| 317 | def warp(img, use_tia=True, prob=0.4, angz=2): |
| 318 | """ |
| 319 | warp |
| 320 | """ |
| 321 | h, w, _ = img.shape |
| 322 | config = Config(use_tia=use_tia) |
| 323 | config.make(w, h, angz) |
| 324 | new_img = img |
| 325 | |
| 326 | if config.distort: |
| 327 | img_height, img_width = img.shape[0:2] |
| 328 | if random.random() <= (prob - 0.1) and img_height >= 32 and img_width >= 32: |
| 329 | new_img = tia_distort(new_img, 10) |
| 330 | |
| 331 | if config.stretch: |
| 332 | img_height, img_width = img.shape[0:2] |
| 333 | if random.random() <= prob and img_height >= 32 and img_width >= 32: |
| 334 | new_img = tia_stretch(new_img, 10) |
| 335 | |
| 336 | if config.perspective: |
| 337 | if random.random() <= prob: |
| 338 | new_img = tia_perspective(new_img) |
| 339 | |
| 340 | if config.crop: |
| 341 | img_height, img_width = img.shape[0:2] |
| 342 | if random.random() <= prob and img_height >= 32 and img_width >= 32: |
| 343 | new_img = get_crop(new_img) |
| 344 | |
| 345 | if config.blur: |
| 346 | bprob = prob / 3. |
| 347 | if random.random() <= bprob: |
| 348 | new_img = blur(new_img) |
| 349 | elif random.random() > bprob and random.random() <= 2 * bprob: |
| 350 | new_img = resizeAug(new_img) |
| 351 | elif random.random() > 2 * bprob and random.random() <= 3 * bprob: |
| 352 | new_img = motion_blur(new_img) |
| 353 | |
| 354 | if config.random_dilute: |
| 355 | if random.random() <= prob: |
| 356 | new_img = random_dilute(new_img) |
| 357 | |
| 358 | if config.color: |
| 359 | if random.random() <= prob: |
| 360 | new_img = cvtColor(new_img) |
| 361 | if config.jitter: |
| 362 | new_img = jitter(new_img) |
| 363 | if config.noise: |
| 364 | if random.random() <= prob: |
| 365 | new_img = add_gasuss_noise(new_img) |
| 366 | if config.reverse: |
| 367 | if random.random() <= prob: |
| 368 | new_img = 255 - new_img |
| 369 | |
| 370 | return new_img |
| 371 |
no test coverage detected