高斯滤波的简单理解
程序员文章站
2022-07-12 10:07:56
...
高斯滤波:
高斯滤波对图像邻域内像素进行平滑时,邻域内不同位置的像素被赋予不同的权值,对图像进行平滑的同时,同时能够更多的保留图像的总体灰度分布特征。
高斯滤波手动实现代码:
# -*- coding: utf-8 -*-
"""
Created on Sat Jul 11 14:53:28 2020
@author: 陨星落云
"""
import imageio
import numpy as np
def GaussianFilter(img):
h,w,c = img.shape
# 高斯滤波
K_size = 3
sigma = 1
# 零填充
pad = K_size//2
out = np.zeros((h + 2*pad,w + 2*pad,c),dtype=np.float)
out[pad:pad+h,pad:pad+w] = img.copy().astype(np.float)
# 定义滤波核
K = np.zeros((K_size,K_size),dtype=np.float)
for x in range(-pad,-pad+K_size):
for y in range(-pad,-pad+K_size):
K[y+pad,x+pad] = np.exp(-(x**2+y**2)/(2*(sigma**2)))
K /= (sigma*np.sqrt(2*np.pi))
K /= K.sum()
# 卷积的过程
tmp = out.copy()
for y in range(h):
for x in range(w):
for ci in range(c):
out[pad+y,pad+x,ci] = np.sum(K*tmp[y:y+K_size,x:x+K_size,ci])
out = out[pad:pad+h,pad:pad+w].astype(np.uint8)
return out
if __name__ == "__main__":
# 读取图像
img = imageio.imread("lena.jpg")
# 高斯滤波
imageio.imsave("GaussianFilter.jpg",GaussianFilter(img))
3.窗口大小以及标准差的影响
https://blog.shinelee.me/2018/09-19-%E5%A6%82%E4%BD%95%E7%A1%AE%E5%AE%9A%E9%AB%98%E6%96%AF%E6%BB%A4%E6%B3%A2%E7%9A%84%E6%A0%87%E5%87%86%E5%B7%AE%E5%92%8C%E7%AA%97%E5%8F%A3%E5%A4%A7%E5%B0%8F.html
参考链接:
https://blog.csdn.net/lz0499/article/details/54015150
https://www.jianshu.com/p/0f766bf8b74f
https://blog.shinelee.me/2018/09-19-%E5%A6%82%E4%BD%95%E7%A1%AE%E5%AE%9A%E9%AB%98%E6%96%AF%E6%BB%A4%E6%B3%A2%E7%9A%84%E6%A0%87%E5%87%86%E5%B7%AE%E5%92%8C%E7%AA%97%E5%8F%A3%E5%A4%A7%E5%B0%8F.html
上一篇: matlab 坐标系转换
下一篇: gdal 坐标系转换