1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| import matplotlib.pyplot as pylab
freq = np.fft.fft2(im) assert(freq.shape == gauss_kernel.shape) freq_kernel = np.fft.fft2(np.fft.ifftshift(gauss_kernel)) conv = freq * freq_kernel im1 = fp.ifft2(conv).real
pylab.figure(figsize = (20, 8)) pylab.gray() pylab.subplot(2, 3, 1), pylab.pcolormesh(im.T, cmap = 'bwr'), pylab.title('Original Image', size = 30), pylab.axis('off') pylab.subplot(2, 3, 2), pylab.pcolormesh(gauss_kernel.T, cmap = 'jet'), pylab.title('Gaussian Kernel', size = 30), pylab.axis('off') pylab.subplot(2, 3, 3), pylab.pcolormesh(im1.T, cmap = 'bwr'), pylab.title('Output Image', size = 30), pylab.axis('off')
imOrigin = (20*np.log10(np.abs(0.1+fp.ifftshift(freq)))).astype(int) pylab.subplot(2, 3, 4), pylab.pcolormesh(imOrigin.T, cmap = 'bwr') pylab.title('Origin Image Spectrum', size = 30), pylab.axis('off')
imGuassian = (20*np.log10(np.abs(0.1+fp.ifftshift(freq_kernel)))).astype(int) pylab.subplot(2, 3, 5), pylab.pcolormesh(imGuassian.T, cmap = 'jet') pylab.title('Gaussian Kernel Spectrum', size = 30), pylab.axis('off')
imOutSpec = (20*np.log10(np.abs(0.1+fp.ifftshift(conv)))).astype(int) pylab.subplot(2, 3, 6), pylab.pcolormesh(imOutSpec.T, cmap = 'jet') pylab.title('Output Image Spectrum', size = 30), pylab.axis('off')
|