MCPcopy Create free account
hub / github.com/tensorflow/datasets / frost

Function frost

tensorflow_datasets/image_classification/corruptions.py:521–546  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

519
520
521def 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
549def snow(x, severity=1):

Callers

nothing calls this directly

Calls 2

around_and_astypeFunction · 0.85
copyMethod · 0.45

Tested by

no test coverage detected