Image transformation that allows us to quickly calculate the sum of values in a rectangular area.
http://en.wikipedia.org/wiki/Summed_area_table
Ejemplo n.º 1
0
        public void TestStaticFilter0()
        {
            double[] data = {
		        1.0, 2.0, 3.0,
		        4.0, 5.0, 6.0,
		        7.0, 8.0, 9.0,
	        };
            Image image = new Image(3, data);
            IntegralImage integral_image = new IntegralImage(image);
            double res;
            res = Filter.Filter0(integral_image, 0, 0, 1, 1, Filter.Subtract);
            Assert.AreEqual(1.0, res, TestsHelper.EPS);
            res = Filter.Filter0(integral_image, 0, 0, 2, 2, Filter.Subtract);
            Assert.AreEqual(12.0, res, TestsHelper.EPS);
            res = Filter.Filter0(integral_image, 0, 0, 3, 3, Filter.Subtract);
            Assert.AreEqual(45.0, res, TestsHelper.EPS);
            res = Filter.Filter0(integral_image, 1, 1, 2, 2, Filter.Subtract);
            Assert.AreEqual(28.0, res, TestsHelper.EPS);
            res = Filter.Filter0(integral_image, 2, 2, 1, 1, Filter.Subtract);
            Assert.AreEqual(9.0, res, TestsHelper.EPS);
            res = Filter.Filter0(integral_image, 0, 0, 3, 1, Filter.Subtract);
            Assert.AreEqual(12.0, res, TestsHelper.EPS);
            res = Filter.Filter0(integral_image, 0, 0, 1, 3, Filter.Subtract);
            Assert.AreEqual(6.0, res, TestsHelper.EPS);
        }
Ejemplo n.º 2
0
        public void TestVertical1D()
        {
            double[] data = {
		        1.0, 2.0, 3.0
	        };
            Image image = new Image(1, data);
            IntegralImage integral_image = new IntegralImage(image);
            Assert.AreEqual(1.0, integral_image[0][0]);
            Assert.AreEqual(3.0, integral_image[1][0]);
            Assert.AreEqual(6.0, integral_image[2][0]);
        }
Ejemplo n.º 3
0
        public void TestHorizontal1D()
        {
            double[] data = {
		        1.0, 2.0, 3.0
	        };
            Image image = new Image(3, data);
            IntegralImage integral_image = new IntegralImage(image);
            Assert.AreEqual(1.0, integral_image[0][0]);
            Assert.AreEqual(3.0, integral_image[0][1]);
            Assert.AreEqual(6.0, integral_image[0][2]);
        }
Ejemplo n.º 4
0
 public int CalculateSubfingerprint(IntegralImage image, int offset)
 {
     uint bits = 0;
     for (int i = 0; i < m_num_classifiers; i++)
     {
         //for (int i = m_num_classifiers - 1; i >= 0; i--) {
         // TODO: cast uint
         bits = (bits << 2) | GrayCode[m_classifiers[i].Classify(image, offset)];
         //bits = (bits << 2) | m_classifiers[i].Classify(image, offset);
     }
     return (int)bits;
 }
Ejemplo n.º 5
0
        public void TestBasic2D()
        {
            double[] data = {
		        1.0, 2.0,
		        3.0, 4.0,
	        };
            Image image = new Image(2, data);
            IntegralImage integral_image = new IntegralImage(image);
            Assert.AreEqual(1.0, integral_image[0][0]);
            Assert.AreEqual(3.0, integral_image[0][1]);
            Assert.AreEqual(4.0, integral_image[1][0]);
            Assert.AreEqual(10.0, integral_image[1][1]);
        }
Ejemplo n.º 6
0
        public void TestFilter0()
        {
            Image image = new Image(2, 2);
            image.Set(0, 0, 0.0);
            image.Set(0, 1, 1.0);
            image.Set(1, 0, 2.0);
            image.Set(1, 1, 3.0);

            Filter flt1 = new Filter(0, 0, 1, 1);
            IntegralImage integral_image = new IntegralImage(image);
            Assert.AreEqual(0.0, flt1.Apply(integral_image, 0), TestsHelper.EPS);
            Assert.AreEqual(1.0986123, flt1.Apply(integral_image, 1), TestsHelper.EPS);
        }
Ejemplo n.º 7
0
        public void TestCalculateSubfingerprint()
        {
            Image image = new Image(2, 2);
            image[0, 0] = 0.0;
            image[0, 1] = 1.0;
            image[1, 0] = 2.0;
            image[1, 1] = 3.0;

            Classifier[] classifiers = {
		        new Classifier(new Filter(0, 0, 1, 1), new Quantizer(0.01, 1.01, 1.5)),	
	        };
            FingerprintCalculator calculator = new FingerprintCalculator(classifiers);
            
            IntegralImage integral_image = new IntegralImage(image);
            Assert.AreEqual(TestsHelper.GrayCode(0), calculator.CalculateSubfingerprint(integral_image, 0));
            Assert.AreEqual(TestsHelper.GrayCode(2), calculator.CalculateSubfingerprint(integral_image, 1));
        }
Ejemplo n.º 8
0
        public void TestStaticFilter1()
        {
            double[] data = {
		        1.0, 2.0, 3.0,
		        3.0, 4.0, 5.0,
		        6.0, 7.0, 8.0,
	        };
            Image image = new Image(3, data);
            IntegralImage integral_image = new IntegralImage(image);
            double res;
            res = Filter.Filter1(integral_image, 0, 0, 1, 1, Filter.Subtract);
            Assert.AreEqual(1.0, res, TestsHelper.EPS); // 2 - 1
            res = Filter.Filter1(integral_image, 0, 0, 2, 2, Filter.Subtract);
            Assert.AreEqual(2.0, res, TestsHelper.EPS); // 2+4 - 1+3
            res = Filter.Filter1(integral_image, 0, 0, 3, 2, Filter.Subtract);
            Assert.AreEqual(3.0, res, TestsHelper.EPS); // 2+4+7 - 1+3+6
        }
Ejemplo n.º 9
0
 public int[] Calculate(Image image)
 {
     int length = image.Rows - m_max_filter_width + 1;
     if (length <= 0)
     {
         //DEBUG() << "Chromaprint::FingerprintCalculator::Calculate() -- Not "
         //		<< "enough data. Image has " << image.NumRows() << " rows, "
         //		<< "needs at least " << m_max_filter_width << " rows.\n";
         return null;
     }
     IntegralImage integral_image = new IntegralImage(image);
     var fingerprint = new int[length];
     for (int i = 0; i < length; i++)
     {
         fingerprint[i] = CalculateSubfingerprint(integral_image, i);
     }
     return fingerprint;
 }
Ejemplo n.º 10
0
 public double Apply(IntegralImage image, int x)
 {
     switch (m_type)
     {
         case 0:
             return Filter0(image, x, m_y, m_width, m_height, SubtractLog);
         case 1:
             return Filter1(image, x, m_y, m_width, m_height, SubtractLog);
         case 2:
             return Filter2(image, x, m_y, m_width, m_height, SubtractLog);
         case 3:
             return Filter3(image, x, m_y, m_width, m_height, SubtractLog);
         case 4:
             return Filter4(image, x, m_y, m_width, m_height, SubtractLog);
         case 5:
             return Filter5(image, x, m_y, m_width, m_height, SubtractLog);
     }
     return 0.0;
 }
Ejemplo n.º 11
0
        public void TestStaticFilter1()
        {
            double[] data = {
		        1.0, 2.1, 3.4,
		        3.1, 4.1, 5.1,
		        6.0, 7.1, 8.0
	        };
            Image image = new Image(3, data);
            IntegralImage integral_image = new IntegralImage(image);
            double res;

            res = Filter.Filter1(integral_image, 0, 0, 1, 1, Filter.Subtract);
            Assert.AreEqual(1.0 - 0.0, res);
            res = Filter.Filter1(integral_image, 1, 1, 1, 1, Filter.Subtract);
            Assert.AreEqual(4.1 - 0.0, res);
            res = Filter.Filter1(integral_image, 0, 0, 1, 2, Filter.Subtract);
            Assert.AreEqual(2.1 - 1.0, res);
            res = Filter.Filter1(integral_image, 0, 0, 2, 2, Filter.Subtract);
            Assert.AreEqual((2.1 + 4.1) - (1.0 + 3.1), res);
            res = Filter.Filter1(integral_image, 0, 0, 3, 2, Filter.Subtract);
            Assert.AreEqual((2.1 + 4.1 + 7.1) - (1.0 + 3.1 + 6.0), res);
        }
Ejemplo n.º 12
0
        public void TestArea()
        {
            double[] data = {
		        1.0, 2.0, 3.0,
		        4.0, 5.0, 6.0,
		        7.0, 8.0, 9.0,
	        };

            Image image = new Image(3, data);
            IntegralImage integral_image = new IntegralImage(image);

            Assert.AreEqual((1.0), integral_image.Area(0, 0, 0, 0));
            Assert.AreEqual((1.0 + 4.0), integral_image.Area(0, 0, 1, 0));
            Assert.AreEqual((1.0 + 4.0 + 7.0), integral_image.Area(0, 0, 2, 0));

            Assert.AreEqual((1.0) + (2.0), integral_image.Area(0, 0, 0, 1));
            Assert.AreEqual((1.0 + 4.0) + (2.0 + 5.0), integral_image.Area(0, 0, 1, 1));
            Assert.AreEqual((1.0 + 4.0 + 7.0) + (2.0 + 5.0 + 8.0), integral_image.Area(0, 0, 2, 1));

            Assert.AreEqual((2.0), integral_image.Area(0, 1, 0, 1));
            Assert.AreEqual((2.0 + 5.0), integral_image.Area(0, 1, 1, 1));
            Assert.AreEqual((2.0 + 5.0 + 8.0), integral_image.Area(0, 1, 2, 1));
        }
Ejemplo n.º 13
0
        // .......ooooooooo
        // .......ooooooooo
        // ooooooo.........
        // ooooooo.........
        public static double Filter3(IntegralImage image, int x, int y, int w, int h, Func<double, double, double> cmp)
        {
            int w_2 = w / 2;
            int h_2 = h / 2;

            double a = image.Area(x, y + h_2, x + w_2 - 1, y + h - 1) +
                       image.Area(x + w_2, y, x + w - 1, y + h_2 - 1);
            double b = image.Area(x, y, x + w_2 - 1, y + h_2 - 1) +
                       image.Area(x + w_2, y + h_2, x + w - 1, y + h - 1);

            return cmp(a, b);
        }
Ejemplo n.º 14
0
        // oooooooooooooooo
        // oooooooooooooooo
        // oooooooooooooooo
        // oooooooooooooooo
        public static double Filter0(IntegralImage image, int x, int y, int w, int h, Func<double, double, double> cmp)
        {
            //Debug.Assert(x >= 0);
            //Debug.Assert(y >= 0);
            //Debug.Assert(w >= 1);
            //Debug.Assert(h >= 1);

            double a = image.Area(x, y, x + w - 1, y + h - 1);
            double b = 0;
            return cmp(a, b);
        }
Ejemplo n.º 15
0
        // .......ooooooooo
        // .......ooooooooo
        // ooooooo.........
        // ooooooo.........
        public static double Filter3(IntegralImage image, int x, int y, int w, int h, Func<double, double, double> cmp)
        {
            //Debug.Assert(x >= 0);
            //Debug.Assert(y >= 0);
            //Debug.Assert(w >= 1);
            //Debug.Assert(h >= 1);

            int w_2 = w / 2;
            int h_2 = h / 2;

            double a = image.Area(x, y + h_2, x + w_2 - 1, y + h - 1) +
                       image.Area(x + w_2, y, x + w - 1, y + h_2 - 1);
            double b = image.Area(x, y, x + w_2 - 1, y + h_2 - 1) +
                       image.Area(x + w_2, y + h_2, x + w - 1, y + h - 1);

            return cmp(a, b);
        }
Ejemplo n.º 16
0
        public void TestStaticFilter3()
        {
            double[] data = {
		        1.0, 2.1, 3.4,
		        3.1, 4.1, 5.1,
		        6.0, 7.1, 8.0,
	        };
            Image image = new Image(3, data);
            IntegralImage integral_image = new IntegralImage(image);
            double res;
            res = Filter.Filter3(integral_image, 0, 0, 2, 2, Filter.Subtract);
            Assert.AreEqual(0.1, res, TestsHelper.EPS); // 2.1+3.1 - 1+4.1
            res = Filter.Filter3(integral_image, 1, 1, 2, 2, Filter.Subtract);
            Assert.AreEqual(0.1, res, TestsHelper.EPS); // 4+8 - 5+7
            res = Filter.Filter3(integral_image, 0, 1, 2, 2, Filter.Subtract);
            Assert.AreEqual(0.3, res, TestsHelper.EPS); // 2.1+5.1 - 3.4+4.1
        }
Ejemplo n.º 17
0
        public void TestStaticFilter5()
        {
            double[] data = {
		        1.0, 2.0, 3.0,
		        3.0, 4.0, 5.0,
		        6.0, 7.0, 8.0,
	        };
            Image image = new Image(3, data);
            IntegralImage integral_image = new IntegralImage(image);
            double res = Filter.Filter5(integral_image, 0, 0, 3, 3, Filter.Subtract);
            Assert.AreEqual(-15.0, res, TestsHelper.EPS); // 3+4+5 - (1+2+3) - (6+7+8)
        }
Ejemplo n.º 18
0
 // oooooooooooooooo
 // oooooooooooooooo
 // oooooooooooooooo
 // oooooooooooooooo
 public static double Filter0(IntegralImage image, int x, int y, int w, int h, Func<double, double, double> cmp)
 {
     double a = image.Area(x, y, x + w - 1, y + h - 1);
     double b = 0;
     return cmp(a, b);
 }
Ejemplo n.º 19
0
        // .....oooooo.....
        // .....oooooo.....
        // .....oooooo.....
        // .....oooooo.....
        public static double Filter5(IntegralImage image, int x, int y, int w, int h, Func<double, double, double> cmp)
        {
            int w_3 = w / 3;

            double a = image.Area(x + w_3, y, x + 2 * w_3 - 1, y + h - 1);
            double b = image.Area(x, y, x + w_3 - 1, y + h - 1) +
                       image.Area(x + 2 * w_3, y, x + w - 1, y + h - 1);

            return cmp(a, b);
        }
Ejemplo n.º 20
0
 public int Classify(IntegralImage image, int offset)
 {
     double value = m_filter.Apply(image, offset);
     return m_quantizer.Quantize(value);
 }
Ejemplo n.º 21
0
        public void TestStaticFilter2()
        {
            double[] data = {
		        1.0, 2.0, 3.0,
		        3.0, 4.0, 5.0,
		        6.0, 7.0, 8.0,
	        };
            Image image = new Image(3, data);
            IntegralImage integral_image = new IntegralImage(image);
            double res;
            res = Filter.Filter2(integral_image, 0, 0, 2, 1, Filter.Subtract);
            Assert.AreEqual(2.0, res, TestsHelper.EPS); // 3 - 1
            res = Filter.Filter2(integral_image, 0, 0, 2, 2, Filter.Subtract);
            Assert.AreEqual(4.0, res, TestsHelper.EPS); // 3+4 - 1+2
            res = Filter.Filter2(integral_image, 0, 0, 2, 3, Filter.Subtract);
            Assert.AreEqual(6.0, res, TestsHelper.EPS); // 3+4+5 - 1+2+3
        }