def WienerFilterDemo(self, img):
img = np.int16(img)
noise = self.noiseGenerator.GuassNoise(img, 0, 10, np.int32(img.size))
nImg = img + noise
fn = np.fft.fftshift(np.fft.fft2(noise))
Sn = np.abs(fn) ** 2.0
ffImg = np.fft.fftshift(np.fft.fft2(img))
Sf = np.abs(ffImg) ** 2.0
H = self.GenerateHDemo(img.shape)
fImg = np.fft.fftshift(np.fft.fft2(img))
gImg = np.fft.ifft2(np.fft.ifftshift(fImg * H))
gImg += noise
fgImg = np.fft.fftshift(np.fft.fft2(gImg))
wH = (H * (np.abs(H) ** 2.0 + Sn / Sf)) / np.abs(H) ** 2.0
H1 = self.IdeaLowHInverse(wH, 500)
ggImg = np.fft.ifft2(np.fft.ifftshift(fgImg * H1))
cv2.namedWindow("orig")
cv2.imshow("orig", np.uint8(img))
cv2.namedWindow("g")
cv2.imshow("g", np.uint8(gImg))
cv2.namedWindow("Wiener filter restore")
cv2.imshow("Wiener filter restore", np.uint8(ggImg))
cv2.waitKey(0)
评论列表
文章目录