commit 968d9e91101d02da4924fe17d85b4b073e59e7de Author: Cx330 <1487537121@qq.com> Date: Tue May 6 19:38:19 2025 +0800 完成傅里叶变换后的频率幅度和相位角的重组 diff --git a/Result_Photo/Square_Woman.png b/Result_Photo/Square_Woman.png new file mode 100644 index 0000000..650aa38 Binary files /dev/null and b/Result_Photo/Square_Woman.png differ diff --git a/Result_Photo/Woman_Square.png b/Result_Photo/Woman_Square.png new file mode 100644 index 0000000..764c24d Binary files /dev/null and b/Result_Photo/Woman_Square.png differ diff --git a/Result_Photo/Woman_Translation.png b/Result_Photo/Woman_Translation.png new file mode 100644 index 0000000..f2c4de1 Binary files /dev/null and b/Result_Photo/Woman_Translation.png differ diff --git a/Result_Photo/assignment3.png b/Result_Photo/assignment3.png new file mode 100644 index 0000000..b0405ca Binary files /dev/null and b/Result_Photo/assignment3.png differ diff --git a/Woman_Square.py b/Woman_Square.py new file mode 100644 index 0000000..167cd34 --- /dev/null +++ b/Woman_Square.py @@ -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() \ No newline at end of file diff --git a/file/boy34.jpg b/file/boy34.jpg new file mode 100644 index 0000000..8a2ea59 Binary files /dev/null and b/file/boy34.jpg differ diff --git a/file/characterTestPattern2.jpg b/file/characterTestPattern2.jpg new file mode 100644 index 0000000..39d7a24 Binary files /dev/null and b/file/characterTestPattern2.jpg differ diff --git a/file/square.jpg b/file/square.jpg new file mode 100644 index 0000000..d367266 Binary files /dev/null and b/file/square.jpg differ diff --git a/file/woman.jpg b/file/woman.jpg new file mode 100644 index 0000000..67de3e5 Binary files /dev/null and b/file/woman.jpg differ diff --git a/file/zeropad.jpg b/file/zeropad.jpg new file mode 100644 index 0000000..1593b0d Binary files /dev/null and b/file/zeropad.jpg differ