MCPcopy Create free account
hub / github.com/IRMVLab/SemGauss-SLAM / normalize_image

Function normalize_image

datasets/gradslam_datasets/datautils.py:13–31  ·  view source on GitHub ↗

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])

Source from the content-addressed store, hash-verified

11]
12
13def 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
34def channels_first(rgb: Union[torch.Tensor, np.ndarray]):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected