Image enhancement is an important technology in digital image processing, which aims to improve the quality and details of images. However, in practical applications, images may be contaminated by various types of noise, such as Gaussian noise, salt-and-pepper noise, and speckle noise. These noises can reduce the visual effect and readability of images, so noise suppression is a key task in image enhancement.
The noise suppression problem in image enhancement technology can be solved through some effective methods. This article will introduce some common noise suppression techniques and provide corresponding code examples.
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)
Through the above example code, it can be seen that mean filtering, median filtering and bilateral filtering are all commonly used for noise suppression in image enhancement techniques. method. According to the actual situation and needs of the image, choosing the appropriate technology and parameters can effectively improve the quality and details of the image.
However, it should be noted that the selection and parameter settings of noise suppression methods are not static. Different types of noise and different images may require different processing methods. Therefore, in practical applications, it is very important to select appropriate noise suppression methods and parameters according to the characteristics and needs of the image.
The above is the detailed content of Noise suppression issues in image enhancement technology. For more information, please follow other related articles on the PHP Chinese website!