Apply frost to images. Args: x: numpy array, uncorrupted image, assumed to have uint8 pixel in [0,255]. severity: integer, severity of corruption. Returns: numpy array, image with uint8 pixels in [0,255]. Applied frost.
(x, severity=1)
| 519 | |
| 520 | |
| 521 | def frost(x, severity=1): |
| 522 | """Apply frost to images. |
| 523 | |
| 524 | Args: |
| 525 | x: numpy array, uncorrupted image, assumed to have uint8 pixel in [0,255]. |
| 526 | severity: integer, severity of corruption. |
| 527 | |
| 528 | Returns: |
| 529 | numpy array, image with uint8 pixels in [0,255]. Applied frost. |
| 530 | """ |
| 531 | c = [(1, 0.4), (0.8, 0.6), (0.7, 0.7), (0.65, 0.7), (0.6, 0.75)][severity - 1] |
| 532 | filename = FROST_FILENAMES[np.random.randint(5)] |
| 533 | with tempfile.NamedTemporaryFile() as im_frost: |
| 534 | tf.io.gfile.copy(filename, im_frost.name, overwrite=True) |
| 535 | frost_img = tfds.core.lazy_imports.cv2.imread(im_frost.name) |
| 536 | # randomly crop and convert to rgb |
| 537 | x_start, y_start = np.random.randint( |
| 538 | 0, frost_img.shape[0] - 224 |
| 539 | ), np.random.randint(0, frost_img.shape[1] - 224) |
| 540 | frost_img = frost_img[x_start : x_start + 224, y_start : y_start + 224][ |
| 541 | ..., [2, 1, 0] |
| 542 | ] |
| 543 | |
| 544 | x = np.clip(c[0] * np.array(x) + c[1] * frost_img, 0, 255) |
| 545 | |
| 546 | return around_and_astype(x) |
| 547 | |
| 548 | |
| 549 | def snow(x, severity=1): |
nothing calls this directly
no test coverage detected