import numpy as np import cv2 def mean_filter(img, kernel_size): width, height = img.shape[:2] output = np.zeros_like(img) pad = kernel_size // 2 img_pad = cv2.copyMakeBorder(img, pad, pad, pad, pad, cv2.BORDER_REFLECT) for i in range(pad, width + pad): for j in range(pad, height + pad): output[i - pad, j - pad] = np.mean(img_pad[i - pad:i + pad + 1, j - pad:j + pad + 1]) return output # 调用示例 image = cv2.imread('input.jpg', 0) output = mean_filter(image, 3) cv2.imwrite('output.jpg', output)
import numpy as np import cv2 def median_filter(img, kernel_size): width, height = img.shape[:2] output = np.zeros_like(img) pad = kernel_size // 2 img_pad = cv2.copyMakeBorder(img, pad, pad, pad, pad, cv2.BORDER_REFLECT) for i in range(pad, width + pad): for j in range(pad, height + pad): output[i - pad, j - pad] = np.median(img_pad[i - pad:i + pad + 1, j - pad:j + pad + 1]) return output # 调用示例 image = cv2.imread('input.jpg', 0) output = median_filter(image, 3) cv2.imwrite('output.jpg', output)
import numpy as np import cv2 def bilateral_filter(img, sigma_spatial, sigma_range): output = cv2.bilateralFilter(img, -1, sigma_spatial, sigma_range) return output # 调用示例 image = cv2.imread('input.jpg', 0) output = bilateral_filter(image, 5, 50) cv2.imwrite('output.jpg', output)
以上が画像強調技術におけるノイズ抑制の問題の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。