
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 cvimport numpy as npimport matplotlib.pyplot as pltimg = cv.imread('learn.jpg', 0) #直接讀爲灰度圖像f = np.fft.fft2(img) #作頻率變換fshift = np.fft.fftshift(f) #轉移像素作幅度普s1 = np.log(np.abs(fshift))#取絕對值:將複數變化成實數取對數的目的爲了將數據變化到0-255plt.subplot(121)plt.imshow(img, 'gray')plt.title('original')plt.subplot(122)plt.imshow(s1,'gray')plt.title('center')plt.show()