数字图像处理 第四章 P157 小错误

问题

我认为P157中部的卷积公式是错的,f(x)h(x-m)应当写为f(m)h(x-m)

解决方法

为了证明,我就用我蹩脚的python实现一下图4.28左列

源代码如下

 1 import numpy as np
 2 import matplotlib.pyplot as plt
 3 
 4 m = np.arange(-1000,1000)#本来想设置为0-1000呢,但是有h(-m)存在,只能设置为(-1000,1000)
 5 
 6 #实现函数f(m)并绘制
 7 fm = np.zeros(2000)
 8 fm[1000:1300] = 3
 9 f1 = plt.figure(1)
10 p1 = plt.subplot(511)
11 p1.plot(m,fm)
12 plt.xlabel('m')
13 plt.ylabel("f(m)")
14 plt.xlim(-1000,1000)
15 
16 #实现h(m)
17 hm = np.zeros(2000)
18 hm[1000:1200] = 2
19 p2 = plt.subplot(512)
20 p2.plot(m,hm)
21 plt.xlabel('m')
22 plt.ylabel("h(m)")
23 plt.xlim(-1000,1000)
24 
25 #实现h(-m)
26 h_m = np.zeros(2000)
27 for i in range(2000):
28     h_m[i] = hm[1999-i]#哈哈,初中的知识诶
29 p3 = plt.subplot(513)
30 p3.plot(m,h_m)
31 plt.xlabel('m')
32 plt.ylabel("h(-m)")
33 plt.xlim(-1000,1000)
34 
35 #实现h(x-m)
36 x = 800
37 h_x_m = np.zeros(2000)
38 h_x_m[800:2000] = h_m[800-x:2000-x]#左加右减,至于为啥选800-2000,这是为了适应x的值,x的范围是0-800
39 p4 = plt.subplot(514)
40 p4.plot(m,h_x_m)
41 plt.xlabel('m')
42 plt.ylabel("h(x-m)")
43 plt.xlim(-1000,1000)
44 
45 #实现f(x)卷积g(x)
46 fx_gx = np.zeros(2000)
47 for x in range(800):
48     h_x_m[800:2000] = h_m[800 - x:2000 - x]  # 左加右减
49     sum = 0
50     for m_temp in range(400):
51         sum += fm[1000+m_temp]*h_x_m[1000+m_temp]
52     fx_gx[1000+x] = sum
53 p5 = plt.subplot(515)
54 p5.plot(m,fx_gx)
55 plt.xlabel('m')
56 plt.ylabel("f(x)*g(x)")
57 plt.xlim(-1000,1000)
58 
59 plt.show()

使用f(m)h(x-m),得到书中的结果,如下:

和书中的结果相同,若使用f(x)h(x-m),得到如下结果:

与书中结果不一致

结论

f(x)h(x-m)应当写为f(m)h(x-m)

原文地址:https://www.cnblogs.com/jingxin-gewu/p/13280182.html