Login  Register

Re: Computing a neighborhood window efficiently

Posted by Serafino on Jan 16, 2011; 4:27pm
URL: http://imagej.273.s1.nabble.com/Computing-a-neighborhood-window-efficiently-tp3685960p3685962.html

It seems that the mean filter does something like my second optimization, for each row it calculates the sum and for each row it subtract the values gone out the window and sums the new ones that entered the window (it uses arrays and not collections). I did a new version of it using one array for the row and now it performs better but still worse than the simple way sometimes.
I will do more work on it to have a deeper understanding.
Concerning the integral image I guess that the formula to compute the sum vector shall be:
        int[] sum = new int[w * h];

        sum[0] = mat[0];
        for (int i = 1; i < w; i++)
                sum[i] = sum[i - 1] + mat[i];
        for (int j = 1; j < h; j++)
        {
            sum[j * w] = sum[(j - 1) * w] + mat[j * w];
            for (int i = 1; i < w; i++)
                sum[j * w + i] = sum[(j - 1) * w + i] + sum[j * w + i - 1] +
                       mat[j * w + i] - sum[(j - 1) * w + i -1];
        }
am I wrong?