請撰寫一個程式,讀取一張 256 色灰階圖像。計算輸入圖的離散傅立葉轉換結果,並
將頻譜大小與相位角度各以灰階 256 色圖像方式呈現出。
===========================================================
思路:
- 256色灰阶读取图像
- 计算输入图的离散傅里叶转换结果并输出
- 输出原图像
- 将频谱以灰阶256色图像输出
- 将相位以灰阶256色图像输出
做法:
- 以cv2.imread('',0)读入图片,此时为256灰阶
- 通过搜索找到opencv2的函数opencv2.dft()可以得到图像的傅里叶转换结果
- 使用numpy.fft.fftshift()进行移频操作
- 使用cv2.phase()获得相位图
- 使用cv2.magnitude()获得频谱图
- 各以灰阶256色图像方式输出
傅里叶转换结果:
original:
[[225 225 224 ..., 230 230 230]
[225 225 225 ..., 230 230 230]
[225 225 225 ..., 230 230 230]
...,
[255 255 255 ..., 255 255 255]
[255 255 255 ..., 255 255 255]
[255 255 255 ..., 255 255 255]]
dft:
[[[ 1.18686848e+08 0.00000000e+00]
[ 6.66400700e+06 -1.01703138e+06]
[ 5.13113062e+05 1.00051762e+06]
...,
[ -1.39588925e+06 3.09186836e+04]
[ 5.13113062e+05 -1.00051762e+06]
[ 6.66400700e+06 1.01703138e+06]]
[[ 1.45740675e+06 2.16409500e+06]
[ 1.32182250e+06 -2.12420195e+04]
[ -3.22664025e+06 5.83794062e+04]
...,
[ -2.06723516e+04 1.36864638e+06]
[ -3.05901500e+06 -7.10340062e+05]
[ 1.35342000e+06 9.23397344e+04]]
[[ -7.53761562e+05 -4.72593531e+05]
[ -3.11442000e+05 2.26395000e+06]
[ 3.66675656e+05 -1.21739962e+06]
...,
[ 9.70380500e+05 -7.07127750e+05]
[ 6.20124500e+05 -2.24606391e+05]
[ -5.78688562e+05 1.64234800e+06]]
...,
[[ -8.94402812e+05 1.86397175e+06]
[ 7.91437688e+05 -1.65669188e+06]
[ 3.29240195e+04 1.21293025e+06]
...,
[ -5.91609375e+05 -9.13635812e+05]
[ -3.06096875e+05 1.04363288e+06]
[ 9.95784062e+05 -1.55982125e+06]]
[[ -7.53761625e+05 4.72593531e+05]
[ -5.78688562e+05 -1.64234800e+06]
[ 6.20124500e+05 2.24606391e+05]
...,
[ 1.04321825e+06 6.35987938e+05]
[ 3.66675656e+05 1.21739962e+06]
[ -3.11442000e+05 -2.26395000e+06]]
[[ 1.45740662e+06 -2.16409500e+06]
[ 1.35342000e+06 -9.23397344e+04]
[ -3.05901500e+06 7.10340062e+05]
...,
[ 8.36184938e+05 -7.52560688e+05]
[ -3.22664025e+06 -5.83794062e+04]
[ 1.32182250e+06 2.12420195e+04]]]
沒有留言:
張貼留言