techsharad / javacv

Automatically exported from code.google.com/p/javacv
GNU General Public License v2.0
0 stars 0 forks source link

Unexpected negative values after filter a matrix #353

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create your own big filter (91*91) kernel, with positive values
2. Create a matrix with zeros 
3. Set some values of the matrix to 3.0
4. Filter the matrix

What is the expected output? What do you see instead?
All the values of the result matrix should be positive!
Instead of this, i got some small negative values (*.*E-15 and smaller)!

What version of the product are you using? On what operating system?
Operating System: MacOSX
Version: 2.4.5

Please provide any additional information below.

Code of the filter process:

    protected void generateValueImage()
    {
        if(baseMat == null)
        {
            throw new IllegalArgumentException("base image is null");
        }

        // like specialMap 3x3 with cell size = 3 => 9x9
        final int row = (int)(9 * scale) + 1;
        final int col = (int)(9 * scale) + 1;
        final Point center = new Point((row-1)/2, (col-1)/2);

        double highest = 0.0;
        if(kernel == null)
        {
            kernel = CvMat.create(row, col, CV_64F, 1);
            cvZero(kernel);
            /* build the gaussian kernel */
            for(int x = 0; x < col; x++)
            {
                for(int y = 0; y < row; y++)
                {
                   double xMeter = (center.x-x)/scale;
                   double yMeter = (center.y-y)/scale;
                   double distance = Math.sqrt(xMeter*xMeter + yMeter*yMeter); 

                    double value = (scaleFactor * Math.exp(-distance*distance / (2*varianz)));

                    kernel.put(x, y, value);

                    if(highest < value)
                    {
                        highest = value;
                    }
                }
            }
            System.out.println("pedHighest: " + highest);
        }

        /* no normalization is needed cause the scale factor will do this! */
        cvFilter2D(baseMat, valueMat, kernel, new CvPoint(center.x, center.y));
    }

Original issue reported on code.google.com by benedikt...@googlemail.com on 18 Aug 2013 at 11:29

GoogleCodeExporter commented 9 years ago
You got your x and y reversed. Try again with the correct order and let me know 
if you still have problems that way, thanks!

Original comment by samuel.a...@gmail.com on 28 Aug 2013 at 9:57

GoogleCodeExporter commented 9 years ago
Given the lack of feedback, I'm assuming my suggestion above fixes your code...

Next time, please post your questions on the mailing list if possible, thank 
you!

Original comment by samuel.a...@gmail.com on 16 Sep 2013 at 11:32