Laplacian of Gaussian

2020-07-14 12:30发布

问题:

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