Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
shyu216 committed Feb 19, 2025
1 parent b9a4561 commit 25a91c8
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 140 deletions.
Binary file removed src/.vuepress/public/EVMBandpassdemo.png
Binary file not shown.
Binary file modified src/.vuepress/public/EVMFTdemo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/.vuepress/public/EVMFilterdemo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
141 changes: 1 addition & 140 deletions src/master/paper/evm.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,79 +30,6 @@ First decompose the video into different spatial frequency bands. Then perform t

Originally, image was a matrix of pixels (spatial domain). Through FT, it becomes a combination of frequency planes (spectrum) with different weight (frequency domain). Each plane represents a different spatial frequency. High frequency spectrum looks like dense wave.

A demo of 2D Fourier transform is shown below.

```python
import numpy as np
import matplotlib.pyplot as plt
import cv2

# 读取图像
image = cv2.imread('cuhk.jpg', cv2.IMREAD_GRAYSCALE)

# 计算傅里叶变换
f_transform = np.fft.fft2(image)
f_transform_shifted = np.fft.fftshift(f_transform)

# 计算幅度谱
magnitude_spectrum = np.abs(f_transform_shifted)

# 找出权重最大的10个频率成分
indices = np.unravel_index(np.argsort(magnitude_spectrum.ravel())[-10:], magnitude_spectrum.shape)

# 创建一个空的复数数组,用于存储合成图像的傅里叶变换
f_transform_combined = np.zeros_like(f_transform_shifted, dtype=complex)

# 可视化原始图像和幅度谱
plt.figure(figsize=(15, 15))

# 原始图像
plt.subplot(4, 4, 1)
plt.imshow(image, cmap='gray')
plt.title('Original Image')
plt.axis('off')

# 幅度谱
plt.subplot(4, 4, 2)
plt.imshow(20 * np.log(magnitude_spectrum + 1), cmap='gray')
plt.title('Magnitude Spectrum')
plt.axis('off')

# 生成仅包含一个频率成分的图像并合成
for i, (row, col) in enumerate(zip(*indices)):
single_freq_mask = np.zeros_like(f_transform_shifted, dtype=complex)
single_freq_mask[row, col] = f_transform_shifted[row, col]

# 计算仅包含一个频率成分的图像
f_transform_single_freq = np.fft.ifftshift(single_freq_mask)
image_single_freq = np.fft.ifft2(f_transform_single_freq)
image_single_freq = np.abs(image_single_freq)

# 将单频图像的傅里叶变换累加到合成图像的傅里叶变换中
f_transform_combined += single_freq_mask

# 可视化仅包含一个频率成分的图像
plt.subplot(4, 4, i + 3)
plt.imshow(image_single_freq, cmap='gray')
plt.title(f'Single Frequency {i + 1}')
plt.axis('off')

# 计算合成图像
f_transform_combined_shifted = np.fft.ifftshift(f_transform_combined)
image_combined = np.fft.ifft2(f_transform_combined_shifted)
image_combined = np.abs(image_combined)

# 可视化合成图像
plt.subplot(4, 4, 13)
plt.imshow(image_combined, cmap='gray')
plt.title('Combined Image')
plt.axis('off')

plt.show()
```

Output:

![Fourier Transform](/EVMFTdemo.png)

### What is frequency band? What information does it contain? How to get from a video file?
Expand All @@ -116,73 +43,7 @@ Fourier transform can be used to get frequency bands.

Band-pass filter can be used to isolate a specific frequency band. A demo of band-pass filter is shown below.

```python
import cv2
import numpy as np
import matplotlib.pyplot as plt

# 读取图像
image = cv2.imread("cuhk.jpg", cv2.IMREAD_GRAYSCALE)

# 显示原始图像
plt.figure(figsize=(10, 5))
plt.subplot(231), plt.imshow(image, cmap='gray')
plt.title("Original Image"), plt.xticks([]), plt.yticks([])

# 对图像进行二维傅里叶变换
f_transform = np.fft.fft2(image)
f_transform_shifted = np.fft.fftshift(f_transform) # 将零频率分量移到中心

# 计算幅度谱并显示
magnitude_spectrum = 20 * np.log(np.abs(f_transform_shifted))
plt.subplot(232), plt.imshow(magnitude_spectrum, cmap='gray')
plt.title("Magnitude Spectrum"), plt.xticks([]), plt.yticks([])

# 获取图像的尺寸
rows, cols = image.shape
crow, ccol = rows // 2, cols // 2 # 中心点

# 创建一个掩码(初始值为0)
mask = np.zeros((rows, cols), np.uint8)

# 定义带通滤波器的频率范围
r_inner = 0 # 内半径(低频截止)
r_outer = 60 # 外半径(高频截止)

# 在掩码上创建一个环形区域(值为1)
center = [crow, ccol]
x, y = np.ogrid[:rows, :cols]
mask_area = (x - center[0]) ** 2 + (y - center[1]) ** 2
mask[(mask_area >= r_inner ** 2) & (mask_area <= r_outer ** 2)] = 1

# 显示掩码
plt.subplot(233), plt.imshow(mask, cmap='gray')
plt.title("Band-Pass Mask"), plt.xticks([]), plt.yticks([])

# 将掩码应用到傅里叶变换结果上
f_transform_filtered = f_transform_shifted * mask

# 计算滤波后的幅度谱
magnitude_spectrum_filtered = 20 * np.log(np.abs(f_transform_filtered) + 1e-5) # 避免log(0)

# 显示滤波后的幅度谱
plt.subplot(234), plt.imshow(magnitude_spectrum_filtered, cmap='gray')
plt.title("Filtered Magnitude Spectrum"), plt.xticks([]), plt.yticks([])

# 将滤波后的结果逆变换回空间域
f_transform_filtered_shifted = np.fft.ifftshift(f_transform_filtered)
image_filtered = np.fft.ifft2(f_transform_filtered_shifted)
image_filtered = np.abs(image_filtered)

# 显示滤波后的图像
plt.subplot(235), plt.imshow(image_filtered, cmap='gray')
plt.title("Filtered Image"), plt.xticks([]), plt.yticks([])
plt.show()
```

Output:

![Band-Pass Filter](/EVMBandpassdemo.png)
![Band-Pass Filter](/EVMFilterdemo.png)

## What are spatial decomposition techniques?

Expand Down

0 comments on commit 25a91c8

Please sign in to comment.