MATLAB psf2otf function. Borrowed from https://github.com/aboucaud/pypher/blob/master/pypher/pypher.py. Input: psf : h x w numpy array shape : list or tuple, output shape of the OTF array Output: otf : OTF array with the desirable shape
(psf, shape)
| 551 | return out |
| 552 | |
| 553 | def psf2otf(psf, shape): |
| 554 | """ |
| 555 | MATLAB psf2otf function. |
| 556 | Borrowed from https://github.com/aboucaud/pypher/blob/master/pypher/pypher.py. |
| 557 | Input: |
| 558 | psf : h x w numpy array |
| 559 | shape : list or tuple, output shape of the OTF array |
| 560 | Output: |
| 561 | otf : OTF array with the desirable shape |
| 562 | """ |
| 563 | if np.all(psf == 0): |
| 564 | return np.zeros_like(psf) |
| 565 | |
| 566 | inshape = psf.shape |
| 567 | # Pad the PSF to outsize |
| 568 | psf = zero_pad(psf, shape, position='corner') |
| 569 | |
| 570 | # Circularly shift OTF so that the 'center' of the PSF is [0,0] element of the array |
| 571 | for axis, axis_size in enumerate(inshape): |
| 572 | psf = np.roll(psf, -int(axis_size / 2), axis=axis) |
| 573 | |
| 574 | # Compute the OTF |
| 575 | otf = fft.fft2(psf) |
| 576 | |
| 577 | # Estimate the rough number of operations involved in the FFT |
| 578 | # and discard the PSF imaginary part if within roundoff error |
| 579 | # roundoff error = machine epsilon = sys.float_info.epsilon |
| 580 | # or np.finfo().eps |
| 581 | n_ops = np.sum(psf.size * np.log2(psf.shape)) |
| 582 | otf = np.real_if_close(otf, tol=n_ops) |
| 583 | |
| 584 | return otf |
| 585 | |
| 586 | # ----------------------Patch Cropping---------------------------- |
| 587 | def random_crop(im, pch_size): |