两幅图像幅度谱和相位谱替换

两幅图像幅度谱和相位谱替换

两幅图像幅度谱和相位谱替换

例子:苹果与橘子图像的幅度谱和相位谱替换

import numpy as np
import cv2
from matplotlib import pyplot as plt

def magnitude_phase_split(img):
    # 分离幅度谱与相位谱
    dft = np.fft.fft2(img)
    dft_shift = np.fft.fftshift(dft)
    # 幅度谱
    magnitude_spectrum = np.abs(dft_shift)
    # 相位谱
    phase_spectrum = np.angle(dft_shift)
    return magnitude_spectrum,phase_spectrum 

def magnitude_phase_combine(img_m,img_p):
    # 幅度谱与相位谱结合
    img_mandp = img_m*np.e**(1j*img_p)
    img_mandp = np.uint8(np.abs(np.fft.ifft2(img_mandp)))
    img_mandp =img_mandp/np.max(img_mandp)*255
    return img_mandp

# 读取图像
img1 = cv2.imread("apple.jpg",0)
img2= cv2.imread("orange.jpg",0)

# 分离幅度谱与相位谱
img1_m,img1_p = magnitude_phase_split(img1)
img2_m,img2_p = magnitude_phase_split(img2)

# 合并幅度谱与相位谱
# 将苹果图像的幅度谱与橘子图像的相位谱结合
img_1mAnd2p = magnitude_phase_combine(img1_m,img2_p)
# 将橘子图像的幅度谱与苹果图像的相位谱结合
img_2mAnd1p = magnitude_phase_combine(img2_m,img1_p)

plt.figure(figsize=(10,8))
plt.subplot(221)
plt.xlabel("apple")
plt.imshow(img1,cmap="gray")
plt.subplot(222)
plt.imshow(img2,cmap="gray")
plt.xlabel("orange")
plt.subplot(223)
plt.imshow(img_1mAnd2p,cmap="gray")
plt.xlabel("applem_and_orangep")
plt.subplot(224)
plt.imshow(img_2mAnd1p,cmap="gray")
plt.xlabel("orangem_and_applep")
plt.show()

输出结果:

14657665-df52c9b404c89198.png
幅度谱与相位谱结合.png
  • 9
    点赞
  • 28
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

陨星落云

你的鼓励将是我创作的最大动力

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

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

打赏作者

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

抵扣说明:

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

余额充值