傅里叶变换

我的博客即将搬运同步至腾讯云+社区,邀请大家一同入驻:https://cloud.tencent.com/developer/support-plan?invite_code=1av1razbeyfk3

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

%matplotlib inline

# Read in the images
image_stripes = cv2.imread('images/stripes.jpg')
# Change color to RGB (from BGR)
image_stripes = cv2.cvtColor(image_stripes, cv2.COLOR_BGR2RGB)

# Read in the images
image_solid = cv2.imread('images/pink_solid.jpg')
# Change color to RGB (from BGR)
image_solid = cv2.cvtColor(image_solid, cv2.COLOR_BGR2RGB)


# Display the images
f, (ax1,ax2) = plt.subplots(1, 2, figsize=(10,5))

ax1.imshow(image_stripes)
ax2.imshow(image_solid)
# convert to grayscale to focus on the intensity patterns in the image
gray_stripes = cv2.cvtColor(image_stripes, cv2.COLOR_RGB2GRAY)
gray_solid = cv2.cvtColor(image_solid, cv2.COLOR_RGB2GRAY)

# normalize the image color values from a range of [0,255] to [0,1] for further processing
norm_stripes = gray_stripes/255.0
norm_solid = gray_solid/255.0

# perform a fast fourier transform and create a scaled, frequency transform image
def ft_image(norm_image):
    '''This function takes in a normalized, grayscale image
       and returns a frequency spectrum transform of that image. '''
    f = np.fft.fft2(norm_image)
    fshift = np.fft.fftshift(f)
    frequency_tx = 20*np.log(np.abs(fshift))
    
    return frequency_tx
# Call the function on the normalized images
# and display the transforms
f_stripes = ft_image(norm_stripes)
f_solid = ft_image(norm_solid)

# display the images
# original images to the left of their frequency transform
f, (ax1,ax2,ax3,ax4) = plt.subplots(1, 4, figsize=(20,10))

ax1.set_title('original image')
ax1.imshow(image_stripes)
ax2.set_title('frequency transform image')
ax2.imshow(f_stripes, cmap='gray')

ax3.set_title('original image')
ax3.imshow(image_solid)
ax4.set_title('frequency transform image')
ax4.imshow(f_solid, cmap='gray')

低频位于频率变换图像的中心。 这些示例的变换图像显示实心图像具有大多数低频分量(如中心亮点所示)。 条纹转换图像包含白色和黑色区域的低频以及这些颜色之间的边缘的高频。 条纹变换图像也告诉我们这些频率有一个主导方向; 垂直条纹由穿过频率变换图像中心的水平线表示

# Read in an image
image = cv2.imread('images/birds.jpg')
# Change color to RGB (from BGR)
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

# convert to grayscale
gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
# normalize the image
norm_image = gray/255.0

f_image = ft_image(norm_image)

# Display the images
f, (ax1,ax2) = plt.subplots(1, 2, figsize=(20,10))

ax1.imshow(image)
ax2.imshow(f_image, cmap='gray')

此图像包含所有频率的分量。 你可以在变换图像的中心看到一个亮点,它告诉我们图像的很大一部分是低频的; 这是有道理的,因为鸟类和背景的身体是纯色。 变换图像还告诉我们这些频率有两个主导方向; 垂直边缘(来自鸟的边缘)由穿过频率变换图像中心的水平线表示,水平边缘(来自鸟头的分支和顶部)由穿过中心的垂直线表示。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 参考: 傅里叶变换学习图像变换第四章 图像变换图像傅里叶变换频谱特性研究 傅里叶定理指出: 任何信号都可以表示成(...
    安安zoe阅读 32,550评论 0 9
  • 1,二维离散傅里叶变换公式的理解,DFT公式中,我们可以将指数项扩展为正弦项和余弦项的形式, 所以从公式的角度可以...
    北风知我意阅读 1,942评论 0 0
  • 闪光耀辉智者著, 流芳溢香声名出。 尽读百科方博学, 饱览万卷才满腹。 架上满积饰于居, 脑中盈刻贵如珠。 天才爱...
    匿身幽处阅读 176评论 0 1
  • 不合时宜
    胡一飘阅读 173评论 5 0

友情链接更多精彩内容