Python cv2.DFT_SCALE Examples
The following are 14
code examples of cv2.DFT_SCALE().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
cv2
, or try the search function
.
Example #1
Source File: deconvolution.py From OpenCV-Python-Tutorial with MIT License | 6 votes |
def update(_): ang = np.deg2rad( cv2.getTrackbarPos('angle', win) ) d = cv2.getTrackbarPos('d', win) noise = 10**(-0.1*cv2.getTrackbarPos('SNR (db)', win)) if defocus: psf = defocus_kernel(d) else: psf = motion_kernel(ang, d) cv2.imshow('psf', psf) psf /= psf.sum() psf_pad = np.zeros_like(img) kh, kw = psf.shape psf_pad[:kh, :kw] = psf PSF = cv2.dft(psf_pad, flags=cv2.DFT_COMPLEX_OUTPUT, nonzeroRows = kh) PSF2 = (PSF**2).sum(-1) iPSF = PSF / (PSF2 + noise)[...,np.newaxis] RES = cv2.mulSpectrums(IMG, iPSF, 0) res = cv2.idft(RES, flags=cv2.DFT_SCALE | cv2.DFT_REAL_OUTPUT ) res = np.roll(res, -kh//2, 0) res = np.roll(res, -kw//2, 1) cv2.imshow(win, res)
Example #2
Source File: deconvolution.py From PyCV-time with MIT License | 6 votes |
def update(_): ang = np.deg2rad( cv2.getTrackbarPos('angle', win) ) d = cv2.getTrackbarPos('d', win) noise = 10**(-0.1*cv2.getTrackbarPos('SNR (db)', win)) if defocus: psf = defocus_kernel(d) else: psf = motion_kernel(ang, d) cv2.imshow('psf', psf) psf /= psf.sum() psf_pad = np.zeros_like(img) kh, kw = psf.shape psf_pad[:kh, :kw] = psf PSF = cv2.dft(psf_pad, flags=cv2.DFT_COMPLEX_OUTPUT, nonzeroRows = kh) PSF2 = (PSF**2).sum(-1) iPSF = PSF / (PSF2 + noise)[...,np.newaxis] RES = cv2.mulSpectrums(IMG, iPSF, 0) res = cv2.idft(RES, flags=cv2.DFT_SCALE | cv2.DFT_REAL_OUTPUT ) res = np.roll(res, -kh//2, 0) res = np.roll(res, -kw//2, 1) cv2.imshow(win, res)
Example #3
Source File: deconvolution.py From PyCV-time with MIT License | 6 votes |
def update(_): ang = np.deg2rad( cv2.getTrackbarPos('angle', win) ) d = cv2.getTrackbarPos('d', win) noise = 10**(-0.1*cv2.getTrackbarPos('SNR (db)', win)) if defocus: psf = defocus_kernel(d) else: psf = motion_kernel(ang, d) cv2.imshow('psf', psf) psf /= psf.sum() psf_pad = np.zeros_like(img) kh, kw = psf.shape psf_pad[:kh, :kw] = psf PSF = cv2.dft(psf_pad, flags=cv2.DFT_COMPLEX_OUTPUT, nonzeroRows = kh) PSF2 = (PSF**2).sum(-1) iPSF = PSF / (PSF2 + noise)[...,np.newaxis] RES = cv2.mulSpectrums(IMG, iPSF, 0) res = cv2.idft(RES, flags=cv2.DFT_SCALE | cv2.DFT_REAL_OUTPUT ) res = np.roll(res, -kh//2, 0) res = np.roll(res, -kw//2, 1) cv2.imshow(win, res)
Example #4
Source File: mosse.py From OpenCV-Python-Tutorial with MIT License | 5 votes |
def state_vis(self): f = cv2.idft(self.H, flags=cv2.DFT_SCALE | cv2.DFT_REAL_OUTPUT ) h, w = f.shape f = np.roll(f, -h//2, 0) f = np.roll(f, -w//2, 1) kernel = np.uint8( (f-f.min()) / f.ptp()*255 ) resp = self.last_resp resp = np.uint8(np.clip(resp/resp.max(), 0, 1)*255) vis = np.hstack([self.last_img, kernel, resp]) return vis
Example #5
Source File: mosse.py From OpenCV-Python-Tutorial with MIT License | 5 votes |
def correlate(self, img): C = cv2.mulSpectrums(cv2.dft(img, flags=cv2.DFT_COMPLEX_OUTPUT), self.H, 0, conjB=True) resp = cv2.idft(C, flags=cv2.DFT_SCALE | cv2.DFT_REAL_OUTPUT) h, w = resp.shape _, mval, _, (mx, my) = cv2.minMaxLoc(resp) side_resp = resp.copy() cv2.rectangle(side_resp, (mx-5, my-5), (mx+5, my+5), 0, -1) smean, sstd = side_resp.mean(), side_resp.std() psr = (mval-smean) / (sstd+eps) return resp, (mx-w//2, my-h//2), psr
Example #6
Source File: tracker.py From KCF-DSST-py with MIT License | 5 votes |
def fftd(img, backwards=False, byRow=False): # shape of img can be (m,n), (m,n,1) or (m,n,2) # in my test, fft provided by numpy and scipy are slower than cv2.dft # return cv2.dft(np.float32(img), flags=((cv2.DFT_INVERSE | cv2.DFT_SCALE) if backwards else cv2.DFT_COMPLEX_OUTPUT)) # 'flags =' is necessary! # DFT_INVERSE: 用一维或二维逆变换取代默认的正向变换, # DFT_SCALE: 缩放比例标识符,根据数据元素个数平均求出其缩放结果,如有N个元素,则输出结果以1/N缩放输出,常与DFT_INVERSE搭配使用。 # DFT_COMPLEX_OUTPUT: 对一维或二维的实数数组进行正向变换,这样的结果虽然是复数阵列,但拥有复数的共轭对称性 if byRow: return cv2.dft(np.float32(img), flags=(cv2.DFT_ROWS | cv2.DFT_COMPLEX_OUTPUT)) else: return cv2.dft(np.float32(img), flags=((cv2.DFT_INVERSE | cv2.DFT_SCALE) if backwards else cv2.DFT_COMPLEX_OUTPUT)) # 实部图像
Example #7
Source File: complex.py From open-vot with MIT License | 5 votes |
def ifft2(img): img = np.float32(img) if img.ndim == 3: out = cv2.dft(img, flags=cv2.DFT_INVERSE | cv2.DFT_SCALE) elif img.ndim == 4: out = [] for c in range(img.shape[2]): out.append(cv2.dft( img[:, :, c, :], flags=cv2.DFT_INVERSE | cv2.DFT_SCALE)) else: raise Exception('only supports 3 or 4 dimensional array') return out
Example #8
Source File: complex.py From open-vot with MIT License | 5 votes |
def ifft1(img): img = np.float32(img) if img.ndim == 2: img = img[np.newaxis, :, :] out = cv2.dft(img, flags=cv2.DFT_ROWS | cv2.DFT_SCALE) out = out.squeeze(0) elif img.ndim == 3: out = cv2.dft(img, flags=cv2.DFT_ROWS | cv2.DFT_SCALE) else: raise Exception('only supports 2 or 3 dimensional array') return out
Example #9
Source File: mosse.py From open-vot with MIT License | 5 votes |
def _linear_correlation(self, img): C = cv2.mulSpectrums( cv2.dft(img, flags=cv2.DFT_COMPLEX_OUTPUT), self.H, 0, conjB=True) resp = cv2.idft(C, flags=cv2.DFT_SCALE | cv2.DFT_REAL_OUTPUT) h, w = resp.shape _, mval, _, (mx, my) = cv2.minMaxLoc(resp) side_resp = resp.copy() cv2.rectangle(side_resp, (mx - 5, my - 5), (mx + 5, my + 5), 0, -1) smean, sstd = side_resp.mean(), side_resp.std() psr = (mval - smean) / (sstd + self.cfg.eps) return resp, (mx - w // 2, my - h // 2), psr
Example #10
Source File: kcftracker.py From KCFnb with MIT License | 5 votes |
def fftd(img, backwards=False): # shape of img can be (m,n), (m,n,1) or (m,n,2) # in my test, fft provided by numpy and scipy are slower than cv2.dft return cv2.dft(np.float32(img), flags = ((cv2.DFT_INVERSE | cv2.DFT_SCALE) if backwards else cv2.DFT_COMPLEX_OUTPUT)) # 'flags =' is necessary!
Example #11
Source File: kcftracker.py From KCFpy with MIT License | 5 votes |
def fftd(img, backwards=False): # shape of img can be (m,n), (m,n,1) or (m,n,2) # in my test, fft provided by numpy and scipy are slower than cv2.dft return cv2.dft(np.float32(img), flags = ((cv2.DFT_INVERSE | cv2.DFT_SCALE) if backwards else cv2.DFT_COMPLEX_OUTPUT)) # 'flags =' is necessary!
Example #12
Source File: mosse.py From PyCV-time with MIT License | 5 votes |
def state_vis(self): f = cv2.idft(self.H, flags=cv2.DFT_SCALE | cv2.DFT_REAL_OUTPUT ) h, w = f.shape f = np.roll(f, -h//2, 0) f = np.roll(f, -w//2, 1) kernel = np.uint8( (f-f.min()) / f.ptp()*255 ) resp = self.last_resp resp = np.uint8(np.clip(resp/resp.max(), 0, 1)*255) vis = np.hstack([self.last_img, kernel, resp]) return vis
Example #13
Source File: mosse.py From PyCV-time with MIT License | 5 votes |
def correlate(self, img): C = cv2.mulSpectrums(cv2.dft(img, flags=cv2.DFT_COMPLEX_OUTPUT), self.H, 0, conjB=True) resp = cv2.idft(C, flags=cv2.DFT_SCALE | cv2.DFT_REAL_OUTPUT) h, w = resp.shape _, mval, _, (mx, my) = cv2.minMaxLoc(resp) side_resp = resp.copy() cv2.rectangle(side_resp, (mx-5, my-5), (mx+5, my+5), 0, -1) smean, sstd = side_resp.mean(), side_resp.std() psr = (mval-smean) / (sstd+eps) return resp, (mx-w//2, my-h//2), psr
Example #14
Source File: mosse.py From PyCV-time with MIT License | 5 votes |
def state_vis(self): f = cv2.idft(self.H, flags=cv2.DFT_SCALE | cv2.DFT_REAL_OUTPUT ) h, w = f.shape f = np.roll(f, -h//2, 0) f = np.roll(f, -w//2, 1) kernel = np.uint8( (f-f.min()) / f.ptp()*255 ) resp = self.last_resp resp = np.uint8(np.clip(resp/resp.max(), 0, 1)*255) vis = np.hstack([self.last_img, kernel, resp]) return vis