网络编程
位置:首页>> 网络编程>> Python编程>> python OpenCV 实现高斯滤波详解

python OpenCV 实现高斯滤波详解

作者:点云侠  发布时间:2022-11-22 16:40:34 

标签:Python,OpenCV,高斯滤波

一、高斯滤波

   高斯滤波是一种线性平滑滤波,适用于消除高斯噪声,广泛应用于图像处理的减噪过程。 [1] 通俗的讲,高斯滤波就是对整幅图像进行加权平均的过程,每一个像素点的值,都由其本身和邻域内的其他像素值经过加权平均后得到。高斯滤波的具体操作是:用一个模板(或称卷积、掩模)扫描图像中的每一个像素,用模板确定的邻域内像素的加权平均灰度值去替代模板中心像素点的值。

二、C++代码


#include <opencv2\opencv.hpp>
#include <iostream>

using namespace cv;
using namespace std;

int main()
{
Mat img = imread("gauss_noise.png");

if (img.empty())
{
cout << "请确认图像文件名称是否正确" << endl;
return -1;
}
Mat result_5, result_9;  //存放含噪声滤波的结果,后面数字代表滤波器尺寸

//调用均值滤波函数blur()进行滤波
GaussianBlur(img, result_5, Size(5, 5), 0, 0);
GaussianBlur(img, result_9, Size(9, 9), 0, 0);
//显示含有高斯噪声图像
imshow("img_gauss", img);
//显示去噪结果
imshow("result_5gauss", result_5);
imshow("result_9gauss", result_9);

waitKey(0);
return 0;
}

三、python代码


import cv2

# ----------------------读取图片-----------------------------
img = cv2.imread('gauss_noise.png')
# ----------------------高斯滤波-----------------------------
result_5 = cv2.GaussianBlur(img, (5, 5), 0)  # 5x5
result_9 = cv2.GaussianBlur(img, (9, 9), 0)  # 9x9
# ----------------------显示结果-----------------------------
cv2.imshow('origion_pic', img)
cv2.imshow('5x5_filtered_pic', result_5)
cv2.imshow('9x9_filtered_pic', result_9)
cv2.waitKey(0)

四、结果展示

1、原始图像

python OpenCV 实现高斯滤波详解

2、5x5卷积

python OpenCV 实现高斯滤波详解

3、9x9卷积

python OpenCV 实现高斯滤波详解

来源:https://blog.csdn.net/qq_36686437/article/details/120620950

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com