MCPcopy
hub / github.com/makelove/OpenCV-Python-Tutorial / update

Function update

官方samples/deconvolution.py:93–115  ·  view source on GitHub ↗
(_)

Source from the content-addressed store, hash-verified

91 defocus = '--circle' in opts
92
93 def update(_):
94 ang = np.deg2rad( cv2.getTrackbarPos('angle', win) )
95 d = cv2.getTrackbarPos('d', win)
96 noise = 10**(-0.1*cv2.getTrackbarPos('SNR (db)', win))
97
98 if defocus:
99 psf = defocus_kernel(d)
100 else:
101 psf = motion_kernel(ang, d)
102 cv2.imshow('psf', psf)
103
104 psf /= psf.sum()
105 psf_pad = np.zeros_like(img)
106 kh, kw = psf.shape
107 psf_pad[:kh, :kw] = psf
108 PSF = cv2.dft(psf_pad, flags=cv2.DFT_COMPLEX_OUTPUT, nonzeroRows = kh)
109 PSF2 = (PSF**2).sum(-1)
110 iPSF = PSF / (PSF2 + noise)[...,np.newaxis]
111 RES = cv2.mulSpectrums(IMG, iPSF, 0)
112 res = cv2.idft(RES, flags=cv2.DFT_SCALE | cv2.DFT_REAL_OUTPUT )
113 res = np.roll(res, -kh//2, 0)
114 res = np.roll(res, -kw//2, 1)
115 cv2.imshow(win, res)
116
117 cv2.namedWindow(win)
118 cv2.namedWindow('psf', 0)

Callers 1

deconvolution.pyFile · 0.70

Calls 2

defocus_kernelFunction · 0.85
motion_kernelFunction · 0.85

Tested by

no test coverage detected