好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

Python opencv(六) 高斯模糊

前提条件

使用工具python3.x 使用库 :numpy、opencv,

api简介

1.cv.GaussianBlur 对图片进行高斯模糊,就是对图像进行平滑的同时,还能够更多的保留图像的信息,如总体灰度分布特征

代码示例

import cv2 as cvimport numpy as npdef Clamp(pv):
	if (pv>255):
		return 255
	if (pv<0):
		return 0
	else:
		return pvdef gaussianNoise(image):#增加高斯噪声
	h, w, c = image.shape	for row in range(h):
		for col in range(w):
			s = np.random.normal(0,20,3)
			b = image[row, col, 0] #蓝色通道
			g = image[row, col, 1] #绿色通道
			r = image[row, col, 2] #红色通道

			image[row, col, 0] = Clamp(b+s[0])
			image[row, col, 1] = Clamp(g+s[1])
			image[row, col, 2] = Clamp(r+s[2])
	cv.imshow('噪声 image', image)src=cv.imread("D:/openCV_image/image/1.png")# src=cv.imread("D:/openCV_image/image/2_2.png")# print(src)cv.namedWindow("input image",cv.WINDOW_AUTOSIZE)cv.imshow("input image",src)# gaussianNoise(src)#直接进行高斯模糊操作dst = cv.GaussianBlur(src, (0,0), 15) #(0,0)高斯核:必须为正数和奇数,或者它们可以是零的。 最后一个参数,表示模糊程度,值越大越模糊cv.imshow('GaussianBlur', dst)cv.waitKey(0)cv.destroyAllWindows()

效果:

查看更多关于Python opencv(六) 高斯模糊的详细内容...

  阅读:31次