close
圖像平滑/降噪: 中值濾波
基礎理論: 中值濾波是一種非線性的圖像平滑技術。它運作的方式是將每個像素值替換為其鄰域內像素值的中值。這種方法對於去除鹽和胡椒噪聲非常有效,因為這種噪聲通常表現為單一的亮或暗的離群值,而中值濾波可以有效地移除這些離群值。
舉例: 考慮一個3x3的鄰域,這種方法將取3x3窗口內的所有像素值的中值,並將此中值指定給窗口中心的像素。此過程將對圖像中的每個像素重複。
接下來,我將使用Python和OpenCV來示範如何使用中值濾波進行圖像平滑。
# Apply median blur for smoothing
median_blur_image = cv2.medianBlur(image, 3)
# Display the original and processed images side by side
fig, axes = plt.subplots(1, 2, figsize=(12, 6))
axes[0].imshow(image)
axes[0].axis('off')
axes[0].set_title('Original Image')
axes[1].imshow(median_blur_image)
axes[1].axis('off')
axes[1].set_title('Smoothed Image using Median Filtering')
plt.tight_layout()
plt.show()
文章標籤
全站熱搜