MCPcopy Create free account
hub / github.com/OpenGVLab/HumanBench / VFlipTransform

Class VFlipTransform

PATH/core/data/transforms/seg_aug_dev.py:81–132  ·  view source on GitHub ↗

Perform vertical flip.

Source from the content-addressed store, hash-verified

79
80
81class VFlipTransform(Transform):
82 """
83 Perform vertical flip.
84 """
85
86 def __init__(self, height: int):
87 super().__init__()
88 self._set_attributes(locals())
89
90 def apply_image(self, img: np.ndarray) -> np.ndarray:
91 """
92 Flip the image(s).
93
94 Args:
95 img (ndarray): of shape HxW, HxWxC, or NxHxWxC. The array can be
96 of type uint8 in range [0, 255], or floating point in range
97 [0, 1] or [0, 255].
98 Returns:
99 ndarray: the flipped image(s).
100 """
101 tensor = torch.from_numpy(np.ascontiguousarray(img))
102 if len(tensor.shape) == 2:
103 # For dimension of HxW.
104 tensor = tensor.flip((-2))
105 elif len(tensor.shape) > 2:
106 # For dimension of HxWxC, NxHxWxC.
107 tensor = tensor.flip((-3))
108 return tensor.numpy()
109
110 def apply_coords(self, coords: np.ndarray) -> np.ndarray:
111 """
112 Flip the coordinates.
113
114 Args:
115 coords (ndarray): floating point array of shape Nx2. Each row is
116 (x, y).
117 Returns:
118 ndarray: the flipped coordinates.
119
120 Note:
121 The inputs are floating point coordinates, not pixel indices.
122 Therefore they are flipped by `(W - x, H - y)`, not
123 `(W - 1 - x, H - 1 - y)`.
124 """
125 coords[:, 1] = self.height - coords[:, 1]
126 return coords
127
128 def inverse(self) -> Transform:
129 """
130 The inverse is to flip again
131 """
132 return self
133
134
135class NoOpTransform(Transform):

Callers 2

get_transformMethod · 0.90
get_transformMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected