Convolution with FFT Input: im: h1 x w1 x c numpy array weight: h2 x w2 numpy array Output: out: h1 x w1 x c numpy array
(im, weight)
| 535 | return {'gradx': gradx, 'grady': grady, 'grad':grad} |
| 536 | |
| 537 | def convfft(im, weight): |
| 538 | ''' |
| 539 | Convolution with FFT |
| 540 | Input: |
| 541 | im: h1 x w1 x c numpy array |
| 542 | weight: h2 x w2 numpy array |
| 543 | Output: |
| 544 | out: h1 x w1 x c numpy array |
| 545 | ''' |
| 546 | axes = (0,1) |
| 547 | otf = psf2otf(weight, im.shape[:2]) |
| 548 | if im.ndim == 3: |
| 549 | otf = np.tile(otf[:, :, None], (1,1,im.shape[2])) |
| 550 | out = fft.ifft2(fft.fft2(im, axes=axes) * otf, axes=axes).real |
| 551 | return out |
| 552 | |
| 553 | def psf2otf(psf, shape): |
| 554 | """ |