基于python的图像傅里叶处理



import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(-10, 10, 1000)
a = np.cos(x)
b = a + np.cos(3 * x)
# d = np.log(x)
c = b + np.cos(7 * x)
d = c - np.cos(10 * x)
plt.subplot(2, 2, 1)
plt.plot(x, a, label='$cos(x)$', color='green', linewidth=1)
plt.title("cosx")
plt.xlim(-2, 2)
plt.ylim(-3, 3)
plt.subplot(2, 2, 2)
plt.plot(x, b, label='$cos(x)+cos(3x)$', color='red', linewidth=1)
plt.title("cosx+cos(3x)")
plt.xlim(-2, 2)
plt.ylim(-3, 3)
plt.subplot(2, 2, 4)
plt.plot(x, d, label='$cos(x)+cos(3x)+cos(7x)$', color='blue', linewidth=1)
plt.title("cosx+cos(3x)+cos(7x)-cos(10x)")
plt.xlim(-2, 2)
plt.ylim(-3, 3)
plt.subplot(2, 2, 3)
plt.plot(x, c, label='$cos(x)+cos(3x)+cos(7x)$', color='black', linewidth=1)
plt.title("cosx+cos(3x)+cos(7x)")
plt.xlim(-2, 2)
plt.ylim(-3, 3)
plt.show()

import cv2 as cv
import numpy as np
import matplotlib.pyplot as plt
img = cv.imread('learn.jpg', 0) #直接读为灰度图像
f = np.fft.fft2(img) #做频率变换
fshift = np.fft.fftshift(f) #转移像素做幅度普
s1 = np.log(np.abs(fshift))#取绝对值:将复数变化成实数取对数的目的为了将数据变化到0-255
plt.subplot(121)
plt.imshow(img, 'gray')
plt.title('original')
plt.subplot(122)
plt.imshow(s1,'gray')
plt.title('center')
plt.show()

import cv2 as cv
import numpy as np
import matplotlib.pyplot as plt
img = cv.imread('learn.jpg', 0) #直接读为灰度图像
img=cv.resize(img,(10,10))
f = np.fft.fft2(img) #做频率变换
fshift = np.fft.fftshift(f) #转移像素做幅度普
s1 = np.log(np.abs(fshift))#取绝对值:将复数变化成实数取对数的目的为了将数据变化到0-255
plt.subplot(121)
plt.imshow(img, 'gray')
plt.title('original')
plt.subplot(122)
plt.imshow(s1,'gray')
plt.title('center')
plt.show()
print(img)
print(' ')
print(f)
print(' ')
print(fshift)
print(' ')
print(s1)







原文地址:https://www.cnblogs.com/tangjunjun/p/11148763.html