Linearly scales each image in `image` to have mean 0 and variance 1. For each 3-D image `x` in `image`, computes `(x - mean) / adjusted_stddev`, where - `mean` is the average of all values in `x` - `adjusted_stddev = max(stddev, 1.0/sqrt(N))` is capped away from 0 to protect against di
(image)
| 1479 | |
| 1480 | @tf_export('image.per_image_standardization') |
| 1481 | def per_image_standardization(image): |
| 1482 | """Linearly scales each image in `image` to have mean 0 and variance 1. |
| 1483 | |
| 1484 | For each 3-D image `x` in `image`, computes `(x - mean) / adjusted_stddev`, |
| 1485 | where |
| 1486 | |
| 1487 | - `mean` is the average of all values in `x` |
| 1488 | - `adjusted_stddev = max(stddev, 1.0/sqrt(N))` is capped away from 0 to |
| 1489 | protect against division by 0 when handling uniform images |
| 1490 | - `N` is the number of elements in `x` |
| 1491 | - `stddev` is the standard deviation of all values in `x` |
| 1492 | |
| 1493 | Args: |
| 1494 | image: An n-D Tensor with at least 3 dimensions, the last 3 of which are the |
| 1495 | dimensions of each image. |
| 1496 | |
| 1497 | Returns: |
| 1498 | A `Tensor` with same shape and dtype as `image`. |
| 1499 | |
| 1500 | Raises: |
| 1501 | ValueError: if the shape of 'image' is incompatible with this function. |
| 1502 | """ |
| 1503 | with ops.name_scope(None, 'per_image_standardization', [image]) as scope: |
| 1504 | image = ops.convert_to_tensor(image, name='image') |
| 1505 | image = _AssertAtLeast3DImage(image) |
| 1506 | |
| 1507 | # Remember original dtype to so we can convert back if needed |
| 1508 | orig_dtype = image.dtype |
| 1509 | if orig_dtype not in [dtypes.float16, dtypes.float32]: |
| 1510 | image = convert_image_dtype(image, dtypes.float32) |
| 1511 | |
| 1512 | num_pixels = math_ops.reduce_prod(array_ops.shape(image)[-3:]) |
| 1513 | image_mean = math_ops.reduce_mean(image, axis=[-1, -2, -3], keepdims=True) |
| 1514 | |
| 1515 | # Apply a minimum normalization that protects us against uniform images. |
| 1516 | stddev = math_ops.reduce_std(image, axis=[-1, -2, -3], keepdims=True) |
| 1517 | min_stddev = math_ops.rsqrt(math_ops.cast(num_pixels, image.dtype)) |
| 1518 | adjusted_stddev = math_ops.maximum(stddev, min_stddev) |
| 1519 | |
| 1520 | image -= image_mean |
| 1521 | image = math_ops.div(image, adjusted_stddev, name=scope) |
| 1522 | return convert_image_dtype(image, orig_dtype, saturate=True) |
| 1523 | |
| 1524 | |
| 1525 | @tf_export('image.random_brightness') |
nothing calls this directly
no test coverage detected