原來的任務是
Use np.array() to generate the following 8-bit image and obtain the result of applying the following mask:
However, the edges are padded to zero. (cv2.BORDER_CONSTANT)
[[10, 20, 40, 50]
[50, 20, 50, 20]
[10, 10, 30, 60]
[20, 40, 60, 70]]
(a) 3x3 average filter
(b) 3x3 gaussian filter, sigmaX=0
(c) If the results of (a) and (b) are M(x,y) and G(x,y),
respectively, calculate M(0,0) and G(0,0) and show that
they are consistent with the results of (a) and (b).
問題是,
(a) - 3x3 平均濾波器
(b) - 3x3 高斯濾波器,sigmaX=0
(a) 的結果是 M(x, y) 而 (b) 的結果是 G(x, y)
所以我應該證明 M(0, 0) 和 G(0, 0) 是正確的。
我寫了代碼,但我無法解決這個問題。
我怎么解決這個問題 ....
編碼 -
import cv2
import numpy as np
src = np.array([[10, 20, 40, 50],
[50, 20, 50, 20],
[10, 10, 30, 60],
[20, 40, 60, 70]], dtype=np.uint8)
dst1 = cv2.blur(src, ksize=(3, 3), borderType=cv2.BORDER_CONSTANT)
dst2 = cv2.GaussianBlur(src, ksize=(3, 3), sigmaX=0, borderType=cv2.BORDER_CONSTANT)
print(dst1)
print(dst1[0][0])
print(dst2)
print(dst2[0][0])
print(dst1[0][0] == dst2[0][0])
結果 -

M(0, 0) 是 11(dst1[0][0]) 并且 G(0, 0) 是 13(dst2[0][0])
我的意思是,我需要使 dst1[0][0] 和 dst2[0][0] 匹配。
但結果不匹配。
對不起我的英語水平不好......
uj5u.com熱心網友回復:
這是一個作業,所以我不會為你完全解決它,但這里有一些提示:
因此,卷積是濾波器內核與相同大小的像素鄰域之間的每個元素乘法之和。
在 0,0 - 給定零填充,后者看起來像這樣:
0.0 0.0 0.0
0.0 10.0 20.0
0.0 50.0 20.0
一個 3x3 的盒子內核看起來像這樣:
1.0/9 1.0/9 1.0/9
1.0/9 1.0/9 1.0/9
1.0/9 1.0/9 1.0/9
所以,M(0,0) 是:
1.0/9 * 0.0 1.0/9 * 0.0 1.0/9 * 0.0
1.0/9 * 0.0 1.0/9 * 10.0 1.0/9 * 20.0
1.0/9 * 0.0 1.0/9 * 50.0 1.0/9 * 20.0 == 11.11111
你必須證明,M(0,0) == dst1[0,0]
此處使用浮點值來避免舍入問題。請使用np.float32, 不要np.uint8在你的 opencv 代碼中實作相同的功能。
這是高斯內核,希望你知道,現在該做什么,祝你好運;)

轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/483299.html
下一篇:如何在有噪點的影像中定位圓圈?
