二维图像的功率谱分析与计算

原理:
对于MxN的数字图像f(x,y),其二维傅里叶变换的公式为:
在这里插入图片描述
u和v分别在0,1,…,M-1和0,1,…,N-1取值。

而功率谱的定义为:
在这里插入图片描述
在这里插入图片描述

  1. matlab代码实现:
clc; clear all; close all;
img = imread('a.jpg','jpg');
img = rgb2gray(img);    
% 图像的功率谱
psd = abs(fftshift(fft2(img))).^2
% 通过对数变换,便于观察
psd = 10 * log10(psd); 
mesh(psd)

在这里插入图片描述
2. python代码实现(批处理,求数据集的平均功率谱)



from PIL import Image
from numpy.fft import fft2, fftshift
import matplotlib.pyplot as plt
import numpy as np

def calculate_psd(imgPath):
	srcIm = Image.open(imgPath).convert('L')
	# 图像的功率谱
	fd_Im = fftshift(fft2(srcIm))
	psd = abs(fd_Im) ** 2
	# psd = 10 * np.log10(psd)
	return psd

## power spectral
path = r'D:\Project\edges2shoes\results\edges2shoes'
label = '_generated'
fpath_list = []
for root, _, fnames in sorted(os.walk(path, followlinks=True)):
	for fname in fnames:
		if label in fname:
			fpath_list.append(os.path.join(root, fname))

average_psd = []
for i in range(len(fpath_list)):
	psd = calculate_psd(fpath_list[i])
	average_psd.append(psd)
average_psd = sum(average_psd) / len(fpath_list)
# 通过对数变换,便于观察
average_psd = 10 * np.log10(average_psd)

# Plot the surface.
fig = plt.figure()
ax = fig.gca(projection='3d')
X = np.arange(0, 256)
Y = np.arange(0, 256)
X, Y = np.meshgrid(X, Y)
surf = ax.plot_surface(X, Y, average_psd)
# Add a color bar which maps values to colors.
fig.colorbar(surf, shrink=0.5, aspect=5)
plt.show()
plt.savefig("gt_py.png")

在这里插入图片描述

  • 12
    点赞
  • 45
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

代码小白的成长

计算机网络PPT下载

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值