简体   繁体   English

如何在MATLAB或python中绘制/绘制高斯(LoG)函数的二维Laplacian函数?

[英]How to graph/plot 2D Laplacian of Gaussian (LoG) function in MATLAB or python?

在此处输入图片说明

Hello. 你好。

I am trying to make a 3-D graph similar to the one below, that illustrates the 2-D Laplacian of Gaussian (LoG) function. 我正在尝试制作类似于以下图的3-D图,该图说明了高斯(LoG)函数的2-D拉普拉斯算子。 How can I accomplish this through MATLAB or python? 如何通过MATLAB或python完成此操作? Code snippets would be greatly appreciated. 代码片段将不胜感激。

I have found that we can plot the gaussian using this method , but I am looking for how to plot the laplacian of gaussian. 我发现可以使用这种方法绘制高斯曲线,但是我正在寻找如何绘制高斯拉普拉斯曲线。

You can use the discrete laplacian function del2 : 您可以使用离散的拉普拉斯函数del2

N = 3;
x=linspace(-N, N,30);
[X,Y]=meshgrid(x,x);
z=del2((1000/sqrt(2*pi).*exp(-(X.^2/2)-(Y.^2/2))));
surf(X,Y,z);

Results: 结果:

在此处输入图片说明

Using del2 applied to a Gaussian one obtains an approximation to the true Laplacian function (it uses a discrete approximation to the derivative). 使用应用于高斯的del2逼真的拉普拉斯函数的近似值(它使用对导数的离散逼近)。 This is not necessary, we can easily compute the expression for the second derivative of the Gaussian, and use that. 这不是必需的,我们可以轻松地计算高斯二阶导数的表达式,并使用该表达式。

First we define a 1D Gaussian: 首先,我们定义一维高斯:

x = linspace(-4,4,41);
G = exp(-x.^2/2)/sqrt(2*pi);

Next, we compute the 2nd derivative of the 1D Gaussian: 接下来,我们计算一维高斯的二阶导数:

Gxx = G .* (x.^2-1);

The Gaussian has a nice property that you can multiply two 1D functions together to get the 2D function. 高斯函数具有很好的属性,您可以将两个1D函数相乘得到2D函数。 Thus, 从而,

data = G .* Gxx.';

is the 2nd derivative along the y-axis of a 2D Gaussian. 是2D高斯沿y轴的二阶导数。 The transposed of data is the 2nd derivative along the x-axis. data的转置是沿x轴的二阶导数。

The Laplace is defined as the sum of partial derivatives along each axis: 拉普拉斯定义为沿每个轴的偏导数之和:

data = data + data.';

Plotting this leads to (I tried replicating the point of view of the original graph also): 进行绘制会导致(我也尝试过复制原始图形的观点):

高斯拉普拉斯

Here's the full code: 这是完整的代码:

x = linspace(-4,4,41);
G = exp(-x.^2/2)/sqrt(2*pi);
Gxx = G .* (x.^2-1);
data = G .* Gxx.';
data = data + data.';
surf(x,x,data,'facecolor','white')
view(45,13)
set(gca,'dataaspectratio',[1,1,0.08])
grid off
xlabel('X')
ylabel('Y')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM