先贴上原始的完整的图片
>>> import numpy as np
>>> from numpy.fft import fft,ifft
>>> #fft是傅里叶转换,ifft傅里叶反转
>>> from PIL import Image
>>> cat =Image.open('C:/a/a.jpg')#获取一张图片
>>> cat
<PIL.JpegImagePlugin.JpegImageFile image mode=RGB size=1800x1273 at 0xCDF8EB8>
>>> cat.show()
>>> #转换成int类型数据,int8==128
>>> np.fromstring(cat.tobytes() ,dtype=np.int8)
array([ 11, 117, -55, ..., 92, -55, -12], dtype=int8)
>>> #之所以有负数,是因为int8<128,颜色值0-255
>>> #傅里叶转换,傅里叶转换的结果包含实数和虚数
>>> a=np.fromstring(cat.tobytes() ,dtype=np.int8)
>>> a=fft(a)
>>> a
array([-1.71761120e+08 +0.j ,
-2.20943522e+07+17384940.60301246j,
3.10160552e+07 +9074920.52415055j, ...,
-1.32824910e+07 -2714223.17490176j,
3.10160552e+07 -9074920.52415086j,
-2.20943522e+07-17384940.60301225j])
>>> #将真实的数据转换成频率
>>> #将傅里叶的数据去除低频的波,设置为零
>>> np.where(np.abs(a)<1e5,0,a)
array([-1.71761120e+08 +0.j ,
-2.20943522e+07+17384940.60301246j,
3.10160552e+07 +9074920.52415055j, ...,
-1.32824910e+07 -2714223.17490176j,
3.10160552e+07 -9074920.52415086j,
-2.20943522e+07-17384940.60301225j])
>>> #下面是傅里叶的反转
>>> a=ifft(a)
>>> a
array([ 11.-3.32958784e-13j, 117.+1.65327672e-13j, -55.+1.93279434e-14j,
..., 92.-3.39755573e-13j, -55.+3.72622577e-13j,
-12.+1.22327445e-13j])
>>> #只获取实数部分则
>>> a=np.real(a)
>>> a
array([ 11., 117., -55., ..., 92., -55., -12.])
>>> aa=np.int8(a)#转换为int8
>>> aa
array([ 10, 116, -54, ..., 91, -55, -11], dtype=int8)
>>> pa=Image.frombytes (size=cat.size,mode=cat.mode,data=aa )
>>> pa
<PIL.Image.Image image mode=RGB size=1800x1273 at 0xCE1A208>
>>> pa.show()#获得图像的轮廓展示出来
>>>
轮廓如图: