Laplacian of Gaussian

白昼怎懂夜的黑 提交于 2020-01-23 01:00:08

问题


I am having trouble implementing a LoG kernel. I am trying to implement 9x9 kernal with theta = 1.4 as shown in this link http://homepages.inf.ed.ac.uk/rbf/HIPR2/log.htm.

However, I am having difficulty with the formula itself. If someone could tell me how to calculate the center ie what x and y values to use in order to get -40 in the 9x9 kernel it'd be greatly appreciated.


回答1:


You don't need to worry about the formula - that is just used to generate the coefficients. You just need to apply those 9x9 coefficients to your image.

Example (untested code !):

const int K = 9;
const int K2 = K / 2;
const int NORM = 500; // constant for normalising filter gain
const int coeffs[K][K] = { ... };
int in_image[M][N];
int out_image[M][N];

for (i = K2; i < M - K2; ++i)
{
    for (j = K2; j < N - K2; ++j)
    {
        int term = 0;
        for (di = -K2; di <= K2; ++di)
        {
            for (dj = -K2; dj <= K2; ++dj)
            {
                term += in_image[i + di][j + dj] * coeff[K2 + ii][K2 + jj];
            }
        }
        out_image = term / NORM;
    }
}



回答2:


Recently I've implemented the LoG filter, the only thing you need is that formula and sigma as a parameter. If you need a fixed size mask, you can store the filter mask values in the matrix and use it, or recalculate it each time and create the needed matrix. The size of the filter depends on sigma value, if more than that size is used - it doesn't make a sence, because the rest part that is out of some maximum size are calculated to zeros using that formula. So, for example you got a filter size = 9X9 Then in order to calculate the filter itself as a matrix, you need to run the formula through this values :

int halfsize = size / 2;    
for (int x = -halfsize; x < halfsize; ++x)
   for (int y = -halfsize; y < halfsize; ++y)
       mask[x][y] = LoGFunction(x, y);

Something like that. It also means that filter size must be an odd value. Hope this helps. In your case, size = 9 sigma = 1.4 x and y changes through -4 to 4. using formula at point (0, 0) (it is the center of the filter) you get something near to -12

But if you put the sigma to 0.2986 You will get the needed answer near to -40. I also don't understand why it is written that sigma value is equal to 1.4 May ba I'm missing something.. Correct me if I made a mistake please



来源:https://stackoverflow.com/questions/2556958/laplacian-of-gaussian

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!