r"""Normalizes RGB image values from :math:`[0, 255]` range to :math:`[0, 1]` range. Args: rgb (torch.Tensor or numpy.ndarray): RGB image in range :math:`[0, 255]` Returns: torch.Tensor or numpy.ndarray: Normalized RGB image in range :math:`[0, 1]` Shape: - rgb
(rgb: Union[torch.Tensor, np.ndarray])
| 11 | ] |
| 12 | |
| 13 | def normalize_image(rgb: Union[torch.Tensor, np.ndarray]): |
| 14 | r"""Normalizes RGB image values from :math:`[0, 255]` range to :math:`[0, 1]` range. |
| 15 | |
| 16 | Args: |
| 17 | rgb (torch.Tensor or numpy.ndarray): RGB image in range :math:`[0, 255]` |
| 18 | |
| 19 | Returns: |
| 20 | torch.Tensor or numpy.ndarray: Normalized RGB image in range :math:`[0, 1]` |
| 21 | |
| 22 | Shape: |
| 23 | - rgb: :math:`(*)` (any shape) |
| 24 | - Output: Same shape as input :math:`(*)` |
| 25 | """ |
| 26 | if torch.is_tensor(rgb): |
| 27 | return rgb.float() / 255 |
| 28 | elif isinstance(rgb, np.ndarray): |
| 29 | return rgb.astype(float) / 255 |
| 30 | else: |
| 31 | raise TypeError("Unsupported input rgb type: %r" % type(rgb)) |
| 32 | |
| 33 | |
| 34 | def channels_first(rgb: Union[torch.Tensor, np.ndarray]): |
nothing calls this directly
no outgoing calls
no test coverage detected