完成傅里叶变换后的频率幅度和相位角的重组
BIN
Result_Photo/Square_Woman.png
Normal file
After Width: | Height: | Size: 105 KiB |
BIN
Result_Photo/Woman_Square.png
Normal file
After Width: | Height: | Size: 108 KiB |
BIN
Result_Photo/Woman_Translation.png
Normal file
After Width: | Height: | Size: 189 KiB |
BIN
Result_Photo/assignment3.png
Normal file
After Width: | Height: | Size: 95 KiB |
66
Woman_Square.py
Normal file
@ -0,0 +1,66 @@
|
||||
import cv2
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
plt.rcParams['font.sans-serif'] = ['simHei']
|
||||
plt.rcParams['axes.unicode_minus'] = False
|
||||
|
||||
#读取照片
|
||||
image_woman = cv2.imread("file/woman.jpg", cv2.IMREAD_GRAYSCALE)
|
||||
image_square = cv2.imread("file/square.jpg", cv2.IMREAD_GRAYSCALE)
|
||||
|
||||
#进行快速傅里叶变换获取频谱幅度和相位角
|
||||
dft_woman = np.fft.fft2(image_woman)
|
||||
sm_woman = np.abs(dft_woman)
|
||||
pa_woman = np.angle(dft_woman)
|
||||
|
||||
dft_square = np.fft.fft2(image_square)
|
||||
sm_square = np.abs(dft_square)
|
||||
pa_square = np.angle(dft_square)
|
||||
|
||||
#利用频谱幅度和相位角重构图像
|
||||
image_woman_square_dft = np.multiply(sm_woman, np.exp(1j*pa_square))
|
||||
image_woman_square = np.abs(np.fft.ifft2(image_woman_square_dft))
|
||||
|
||||
image_square_woman_dft = np.multiply(sm_square, np.exp(1j*pa_woman))
|
||||
image_square_woman = np.abs(np.fft.ifft2(image_square_woman_dft))
|
||||
|
||||
#将woman频谱幅度的最亮点移到中心
|
||||
shift_woman = np.fft.fftshift(dft_woman)
|
||||
image_woman_translation = np.log(np.abs(shift_woman))
|
||||
|
||||
shift_square = np.fft.fftshift(dft_square)
|
||||
image_square_translation = np.log(np.abs(shift_square))
|
||||
|
||||
#展示图像
|
||||
plt.subplot(3,2,1)
|
||||
plt.imshow(image_woman, cmap='gray')
|
||||
plt.title('woman')
|
||||
plt.axis('off')
|
||||
|
||||
plt.subplot(3,2,2)
|
||||
plt.imshow(image_square, cmap='gray')
|
||||
plt.title('square')
|
||||
plt.axis('off')
|
||||
|
||||
plt.subplot(3,2,3)
|
||||
plt.imshow(image_woman_square, cmap='gray')
|
||||
plt.title('1.woman的幅频和square的相角')
|
||||
plt.axis('off')
|
||||
|
||||
plt.subplot(3,2,4)
|
||||
plt.imshow(image_square_woman, cmap='gray')
|
||||
plt.title('2.square的幅频和woman的相角')
|
||||
plt.axis('off')
|
||||
|
||||
plt.subplot(3,2,5)
|
||||
plt.imshow(image_woman_translation, cmap='gray')
|
||||
plt.title('3.将woman频谱幅度最亮处移到中心')
|
||||
plt.axis('off')
|
||||
|
||||
plt.subplot(3,2,6)
|
||||
plt.imshow(image_square_translation, cmap='gray')
|
||||
plt.title('将square频谱幅度最亮处移到中心')
|
||||
plt.axis('off')
|
||||
|
||||
plt.tight_layout()
|
||||
plt.show()
|
BIN
file/boy34.jpg
Normal file
After Width: | Height: | Size: 315 KiB |
BIN
file/characterTestPattern2.jpg
Normal file
After Width: | Height: | Size: 221 KiB |
BIN
file/square.jpg
Normal file
After Width: | Height: | Size: 66 KiB |
BIN
file/woman.jpg
Normal file
After Width: | Height: | Size: 7.4 KiB |
BIN
file/zeropad.jpg
Normal file
After Width: | Height: | Size: 8.8 KiB |