2016-11-27 146 views
0

我正在撰寫關於SIFT算法的研究論文,並且我想在描述離散過程之前創建一個圖形以幫助解釋連續函數環境中高斯模糊的概念。我想要創建的圖形是一個標準高斯卷積與正弦函數的圖形。我可以繪製高斯曲線,我可以繪製正弦曲線,但我不知道如何繪製它們的卷積曲線。我不知道如何計算它們的卷積來繪製它,並且我不知道任何允許我在圖中使用卷積算子的軟件。我對tikz和gnuplot很熟悉,但我不知道如何與他們中的任何一個做這個。任何建議,如何我可以去這個將不勝感激。謝謝。繪製高斯卷積圖

+1

對於卷積使用程序(如「八度」)的數值計算。或者將您的案例中的分析解決方案作爲函數進行繪製 – Christoph

回答

0

你可以使用Python matplotlib和np.convolve

請參見下面的代碼

__author__ = 'kgeorge' 
import os 
import numpy as np 
import math 
import matplotlib.pyplot as plt 
from matplotlib import gridspec 

#create gaussian for the x values in x-axis 
def create_gaussian(x_axis): 
    sigma = 1.0 
    denom = math.sqrt(2 * math.pi) * sigma 
    twoSigmaSq = 2.0*sigma**2 
    e=np.zeros_like(x_axis) 
    for i,x in enumerate(x_axis): 
     e[i]=math.exp (-(x*x)/twoSigmaSq) 
    e = e/denom 
    return e 


def main(): 
    #x_axis 
    sz=100 
    halfW = int(sz/2) 
    x_axis=np.linspace(-halfW, halfW, 1000) 

    #cos fun 
    cos_f=np.cos(x_axis) 
    #gaussian 
    gaussian_f=create_gaussian(x_axis) 

    fig = plt.figure() 
    gs = gridspec.GridSpec(3, 1) 

    ax1 = fig.add_subplot(gs[0,0]) 
    ax1.plot(x_axis, cos_f) 
    ax1.set_title('cos') 

    ax2 = fig.add_subplot(gs[1,0]) 
    ax2.plot(x_axis, gaussian_f) 
    ax2.set_title('gaussian') 

    ax3 = fig.add_subplot(gs[2,0]) 
    convolved_ret=np.convolve(cos_f, gaussian_f, mode='same') 
    ax3.plot(x_axis, convolved_ret) 
    ax3.set_title('cos convolved with gaussian') 

    gs.update(wspace=0.5, hspace=0.5) 

    plt.show() 

請在這裏看到的輸出。 output of convolustion of cos and gaussian