views:

594

answers:

4

This is a formula for LoG filtering: alt text

Also in applications with LoG filtering I see that function is called with only one parameter: sigma(σ). I want to try LoG filtering using that formula (previous attempt was by gaussian filter and then laplacian filter with some filter-window size ) But looking at that formula I can't understand how the size of filter is connected with this formula, does it mean that the filter size is fixed? Can you explain how to use it?

+1  A: 

It appears to be a continuous circular filter whose radius is sqrt(2) * sigma. If you want to implement this for image processing you'll need to approximate it.

There's an example for sigma = 1.4 here: http://homepages.inf.ed.ac.uk/rbf/HIPR2/log.htm

Paul R
I did the approximation by difference of gaussians, but I don't want to use that approximation. What kind of approximation are you talkingabout?
maximus
@maximums: did you *read* the page I linked to ? It' s continuous function so you have to approximate it for discrete image processing. There's an example set of coefficients for sigma = 1.4 on the page I linked to and enough info for you to generate coefficients for any value of sigma that you need.
Paul R
Thank you, I got you!
maximus
+1  A: 

This was something that confused me too, and it wasn't until I had to do the same as you for a uni project that I understood what you were supposed to do with the formula!

You can use this formula to generate a discrete LoG filter. If you write a bit of code to implement that formula, you can then to generate a filter for use in image convolution. To generate, say a 5x5 template, simply call the code with x and y ranging from -2 to +2.

This will generate the values to use in a LoG template. If you graph the values this produces you should see the "mexican hat" shape typical of this filter, like so:

LoG template

You can fine tune the template by changing how wide it is (the size) and the sigma value (how broad the peak is). The wider and broader the template the less affected by noise the result will be because it will operate over a wider area.

Once you have the filter, you can apply it to the image by convolving the template with the image. If you've not done this before, check out these few tutorials. java applet tutorials more mathsy.

Essentially, at each pixel location, you "place" your convolution template, centred at that pixel. You then multiply the surrounding pixel values by the corresponding "pixel" in the template and add up the result. This is then the new pixel value at that location (typically you also have to normalise (scale) the output to bring it back into the correct value range).

The code below gives a rough idea of how you might implement this. Please forgive any mistakes / typos etc. as it hasn't been tested.

I hope this helps.

private float LoG(float x, float y, float sigma)
{
    // implement formula here
    return (1 / (Math.PI * sigma*sigma*sigma*sigma)) * //etc etc - also, can't remember the code for "to the power of" off hand
}

private void GenerateTemplate(int templateSize, float sigma)
{
    // Make sure it's an odd number for convenience
    if(templateSize % 2 == 1)
    {
        // Create the data array
        float[][] template = new float[templateSize][templatesize];

        // Work out the "min and max" values. Log is centered around 0, 0
        // so, for a size 5 template (say) we want to get the values from
        // -2 to +2, ie: -2, -1, 0, +1, +2 and feed those into the formula.
        int min = Math.Ceil(-templateSize / 2) - 1;
        int max = Math.Floor(templateSize / 2) + 1;

        // We also need a count to index into the data array...
        int xCount = 0;
        int yCount = 0;

        for(int x = min; x <= max; ++x)
        {
            for(int y = min; y <= max; ++y)
            {
                // Get the LoG value for this (x,y) pair
                template[xCount][yCount] = LoG(x, y, sigma);
                ++yCount;
            }
            ++xCount;
        }
    }
}
xan
Thank you very much, I try it!
maximus
As Paul said in previous answer, it appears to be a filter whose radius is sqrt(2) * sigma.If it is so, then the filter size depends only on sigma value,then the sigma value is only thing which is needed.However I am not sure, and may be it is also OK to use independend parameters as sigma and template size.
maximus
+3  A: 
AVB
A: 

I have a silly question. For the life of me, I can't figure out how the center value in the 9x9 mask on the link is calculated. I don't know how they got -40 or how to use the x and y values. If you could answer this question it would be greatly appreciated. Thank you.

Don
I think the scaling was used there.
maximus