gpt-3.5-turbo-0301· OpenAI
WildChat-4.8M (AI2)
Finalize the docstring: def applytf(img: np.ndarray, tf: Sequence[float]): """ Apply a…
- User
Finalize the docstring:
def apply_tf(img: np.ndarray, tf: Sequence[float]): """ Apply a [α β γ h s v] transformation on a (H x W x C)[0, 255][RGB] NumPy image, where each transform (gain) is a float-like multiplier.
- alpha (α) [1.0 - 3.0]: contrast multiplier - beta (β) [0 - 100]: brightness bias - gamma (γ) [0]: non-linear brigthness correction - hue (h) []: """ # gains alpha, beta, gamma, h, s, v = tf # adjust contrast (alpha) and brightness (beta) # https://www.tutorialspoint.com/how-to-change-the-contrast-and-brightness-of-an-image-using-opencv-in-python img = cv2.convertScaleAbs(img, alpha=alpha, beta=beta) # adjust gamma img = adjust_gamma(img, gamma) # adjust hue, value and saturation using multipliers # https://stackoverflow.com/a/74720575/1658105 img_hsv = cv2.cvtColor(img, cv2.COLOR_RGB2HSV) img_hsv[:, :, 0] = (img_hsv[:, :, 0] * h).clip(0, 180) img_hsv[:, :, 1] = (img_hsv[:, :, 1] * s).clip(0, 255) img_hsv[:, :, 2] = (img_hsv[:, :, 2] * v).clip(0, 255) img = cv2.cvtColor(img_hsv, cv2.COLOR_HSV2RGB) return img - Assistant
""" Apply a [α β γ h s v] transformation on a (H x W x C)[0, 255][RGB] NumPy image.
Parameters:
- img: np.ndarray : A NumPy image array of shape (H x W x C) [0, 255][RGB].
- tf: Sequence[float] : A sequence of 6 float-like values in the order [α β γ h s v]. α (float): Contrast multiplier [1.0 - 3.0]. β (float): Brightness bias [0 - 100]. γ (float): Non-linear brightness correction [0]. h (float): Hue multiplier. s (float): Saturation multiplier. v (float): Value multiplier.
Returns:
- np.ndarray : A transformed NumPy image array of shape (H x W x C).
Note:
- This function uses OpenCV to apply the transformations.
- The transformation values should be chosen carefully as they may produce undesirable results.
- The hue value h should be in the range [0, 1] where 0 and 1 correspond to no change.
- The saturation value s and value value v should be in the range [0, inf). """