Image Denoising html
OpenCV提供了这种技术的四种变体。dom
Common arguments:ide
cv2.fastNlMeansDenoisingColored()
如上所述,它用于从彩色图像中去除噪声。 (噪音预计是高斯噪音)ui
import numpy as np import cv2 import matplotlib.pyplot as plt img = cv2.imread('img.jpg') dst = cv2.fastNlMeansDenoisingColored(img,None,10,10,7,21) plt.subplot(121),plt.imshow(img) plt.subplot(122),plt.imshow(dst) plt.show()
cv2.fastNlMeansDenoisingMulti()
this
如今咱们将相同的方法应用于视频。 第一个参数是嘈杂帧的列表。 第二个参数imgToDenoiseIndex指定咱们须要去噪的帧,由于咱们在输入列表中传递了frame的索引。 第三个是temporalWindowSize,它指定了用于去噪的附近帧的数量。 在这种状况下,使用总共temporalWindowSize帧,其中中心帧是要去噪的帧。 例如,传递了5个帧的列表做为输入。 设imgToDenoiseIndex = 2和temporalWindowSize = 3.而后使用frame-1,frame-2和frame-3对帧-2进行去噪spa
import numpy as np import cv2 import matplotlib.pyplot as plt cap = cv2.VideoCapture('test.mp4') # create a list of first 5 frames img = [cap.read()[1] for i in range(5)] # convert all to grayscale gray = [cv2.cvtColor(i, cv2.COLOR_BGR2GRAY) for i in img] # convert all to float64 gray = [np.float64(i) for i in gray] # create a noise of variance 25 noise = np.random.randn(*gray[1].shape)*10 # Add this noise to images noisy = [i+noise for i in gray] # Convert back to uint8 noisy = [np.uint8(np.clip(i,0,255)) for i in noisy] # Denoise 3rd frame considering all the 5 frames dst = cv2.fastNlMeansDenoisingMulti(noisy, 2, 5, None, 4, 7, 35) plt.subplot(131),plt.imshow(gray[2],'gray') plt.subplot(132),plt.imshow(noisy[2],'gray') plt.subplot(133),plt.imshow(dst,'gray') plt.show()