%matplotlib inline
import numpy as np
from matplotlib import pyplot as plt
import scipy.misc
face = scipy.misc.face()
image = face[:,:,1]
# image size, square side length, number of squares
ncols, nrows = 768, 1024
sq_size, nsq = 10, 20
plt.figure(),plt.imshow(image,cmap='gray')
# Take the 2-dimensional DFT and centre the frequencies
ftimage = np.fft.fft2(np.fft.fftshift(image))
ftimage = np.fft.fftshift(ftimage)
plt.figure(),plt.imshow(np.abs(ftimage),cmap='gray',vmin=0, vmax=10000)
# Build and apply a Gaussian filter.
sigmax, sigmay = 50, 50
cx,cy = nrows/2, ncols/2
x = np.linspace(0, nrows, nrows)
y = np.linspace(0, ncols, ncols)
X, Y = np.meshgrid(x, y)
gmask = np.exp(-(((X-cx)/sigmax)**2 + ((Y-cy)/sigmay)**2))
ftimagep = ftimage * gmask
plt.figure(),plt.imshow(gmask,cmap='gray')
plt.figure(),plt.imshow(np.abs(ftimagep),cmap='gray',vmin=0, vmax=10000)
# Finally, take the inverse transform and show the blurred image
imagep = np.fft.fftshift(np.fft.ifft2(np.fft.fftshift(ftimagep)))
plt.figure(),plt.imshow(np.abs(imagep),cmap='gray')
(<matplotlib.figure.Figure at 0x2af9c4c9908>, <matplotlib.image.AxesImage at 0x2af9c51d278>)
ftimage_restore = ftimagep / gmask
plt.figure(),plt.imshow(gmask,cmap='gray')
plt.figure(),plt.imshow(np.abs(ftimage_restore),cmap='gray',vmin=0, vmax=10000)
# Finally, take the inverse transform and show the blurred image
imagep = np.fft.fftshift(np.fft.ifft2(np.fft.fftshift(ftimage_restore)))
plt.figure(),plt.imshow(np.abs(imagep),cmap='gray')
(<matplotlib.figure.Figure at 0x2af9c3e5908>, <matplotlib.image.AxesImage at 0x2af9c4990b8>)
!dir
磁碟區 C 中的磁碟沒有標籤。 磁碟區序號: F656-428C C:\github\keras-segnet 的目錄 2017/04/17 下午 11:47 <DIR> . 2017/04/17 下午 11:47 <DIR> .. 2017/04/17 下午 11:46 <DIR> .ipynb_checkpoints 2017/04/14 下午 10:57 4,005 build_model.py 2017/04/15 上午 11:21 4,057 build_model_py3.py 2017/04/15 下午 01:05 <DIR> Data 2017/04/17 下午 11:47 461,638 image_restoration.ipynb 2017/04/14 下午 10:04 <DIR> index-based-upsampling 2017/04/14 下午 10:04 1,088 LICENSE 2017/04/17 下午 11:45 472,791 minst.ipynb 2017/04/14 下午 10:04 872,606 model.png 2017/04/16 下午 08:03 55,658 model_5l.json 2017/04/16 下午 07:27 118,039,720 model_5l_weight_ep50.hdf5 2017/04/14 下午 10:04 501 README.md 2017/04/15 下午 12:49 76,447 result.png 2017/04/16 下午 08:22 266,831 SegNet.ipynb 2017/04/14 下午 10:04 4,040 SegNet.py 2017/04/14 下午 11:55 4,213 SegNet_py3.py 2017/04/15 下午 08:27 5,894 SegNet_train.py 2017/04/16 下午 08:30 <DIR> _mnist 14 個檔案 120,269,489 位元組 6 個目錄 1,978,335,232 位元組可用