fix(v5): preserve grayscale gradient masks

This commit is contained in:
2026-07-09 20:09:22 +08:00
parent 38faff0ed0
commit 47d6af6abc
2 changed files with 37 additions and 1 deletions

View File

@@ -327,6 +327,7 @@ def gradient_abs_sum(image, params):
Use it to emphasize prominent edges before combining them with a sharpened image.
"""
grayscale_input = image.ndim == 2
operator = params.get("operator", "sobel")
gray = to_gray(image).astype(np.float32)
if operator == "roberts":
@@ -337,7 +338,8 @@ def gradient_abs_sum(image, params):
gy = np.array([[-1, 0, 1], [-2, 0, 2], [-1, 0, 1]], dtype=np.float32)
fx = cv2.filter2D(gray, cv2.CV_32F, gx, borderType=cv2.BORDER_REFLECT)
fy = cv2.filter2D(gray, cv2.CV_32F, gy, borderType=cv2.BORDER_REFLECT)
return gray_to_rgb(normalize_to_uint8(np.abs(fx) + np.abs(fy)))
gradient = normalize_to_uint8(np.abs(fx) + np.abs(fy))
return gradient if grayscale_input else gray_to_rgb(gradient)
def rgb_channel(image, params):