TODO: Update summary.
示例#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);
        }
示例#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]);
        }
示例#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]);
        }
示例#4
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);
        }
示例#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]);
        }
示例#6
0
 public void Test1()
 {
     Image image = new Image(12, 0);
     ImageBuilder builder = new ImageBuilder(image);
     ChromaResampler resampler = new ChromaResampler(2, builder);
     double[] d1 = { 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
     double[] d2 = { 1.0, 6.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
     double[] d3 = { 2.0, 7.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
     resampler.Consume(d1);
     resampler.Consume(d2);
     resampler.Consume(d3);
     Assert.AreEqual(1, image.Rows);
     Assert.AreEqual(0.5, image.Get(0, 0));
     Assert.AreEqual(5.5, image.Get(0, 1));
 }
        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));
        }
示例#8
0
        /// <summary>
        /// Computes the chromagram of an audio file.
        /// </summary>
        /// <param name="decoder">The <see cref="IDecoder"/> instance.</param>
        /// <returns>Chroma image.</returns>
        public static Image ComputeChromagram(IDecoder decoder)
        {
            var image = new Image(12);
            var image_builder = new ImageBuilder(image);

            var chroma_normalizer = new ChromaNormalizer(image_builder);
            var chroma_filter = new ChromaFilter(ChromaFilterCoefficients, chroma_normalizer);
            var chroma = new Chroma(MIN_FREQ, MAX_FREQ, FRAME_SIZE, SAMPLE_RATE, chroma_filter);

            var fft = new FFT(FRAME_SIZE, OVERLAP, chroma, new LomontFFTService());
            var processor = new AudioProcessor(SAMPLE_RATE, fft);

            processor.Reset(decoder.SampleRate, decoder.Channels);
            decoder.Decode(processor, 120);
            processor.Flush();

            return image;
        }
示例#9
0
 public void TestBlur2()
 {
     double[] coefficients = { 0.5, 0.5 };
     Image image = new Image(12);
     ImageBuilder builder = new ImageBuilder(image);
     ChromaFilter filter = new ChromaFilter(coefficients, builder);
     double[] d1 = { 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
     double[] d2 = { 1.0, 6.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
     double[] d3 = { 2.0, 7.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
     filter.Consume(d1);
     filter.Consume(d2);
     filter.Consume(d3);
     Assert.AreEqual(2, image.Rows);
     Assert.AreEqual(0.5, image.Get(0, 0));
     Assert.AreEqual(1.5, image.Get(1, 0));
     Assert.AreEqual(5.5, image.Get(0, 1));
     Assert.AreEqual(6.5, image.Get(1, 1));
 }
示例#10
0
        //static int MAX_FILTER_WIDTH = 20;

        public static Image Compute(string file, IDecoder decoder)
        {
            int numBands = 72;

            Image image = new Image(numBands);
            ImageBuilder image_builder = new ImageBuilder(image);
            Spectrum chroma = new Spectrum(numBands, MIN_FREQ, MAX_FREQ, FRAME_SIZE, SAMPLE_RATE, image_builder);
            FFT fft = new FFT(FRAME_SIZE, OVERLAP, chroma);
            AudioProcessor processor = new AudioProcessor(SAMPLE_RATE, fft);

            processor.Reset(decoder.SampleRate, decoder.Channels);
            decoder.Decode(processor, 120);
            processor.Flush();

            //ExportImage(image, name, 0.5);

            return image;
        }
示例#11
0
        /// <summary>
        /// Computes the spectogram of an audio file.
        /// </summary>
        /// <param name="decoder">The <see cref="IDecoder"/> instance.</param>
        /// <returns>Chroma image.</returns>
        public static Image ComputeSpectrogram(IDecoder decoder)
        {
            int numBands = 72;

            var image = new Image(numBands);
            var image_builder = new ImageBuilder(image);

            var chroma = new Spectrum(numBands, MIN_FREQ, MAX_FREQ, FRAME_SIZE, SAMPLE_RATE, image_builder);

            var fft = new FFT(FRAME_SIZE, OVERLAP, chroma, new LomontFFTService());
            var processor = new AudioProcessor(SAMPLE_RATE, fft);

            processor.Reset(decoder.SampleRate, decoder.Channels);
            decoder.Decode(processor, 120);
            processor.Flush();

            return image;
        }
示例#12
0
        public static Image Compute(string file, IDecoder decoder)
        {
            Image image = new Image(12);
            ImageBuilder image_builder = new ImageBuilder(image);
            ChromaNormalizer chroma_normalizer = new ChromaNormalizer(image_builder);
            ChromaFilter chroma_filter = new ChromaFilter(ChromaFilterCoefficients, chroma_normalizer);
            //Chroma chroma = new Chroma(MIN_FREQ, MAX_FREQ, FRAME_SIZE, SAMPLE_RATE, &chroma_normalizer);
            Chroma chroma = new Chroma(MIN_FREQ, MAX_FREQ, FRAME_SIZE, SAMPLE_RATE, chroma_filter);
            FFT fft = new FFT(FRAME_SIZE, OVERLAP, chroma);
            AudioProcessor processor = new AudioProcessor(SAMPLE_RATE, fft);

            processor.Reset(decoder.SampleRate, decoder.Channels);
            decoder.Decode(processor, 120);
            processor.Flush();

            //ExportImage(image, name);

            return image;
        }
示例#13
0
 public void TestBlur3()
 {
     double[] coefficients = { 0.5, 0.7, 0.5 };
     Image image = new Image(12, 0);
     ImageBuilder builder = new ImageBuilder(image);
     ChromaFilter filter = new ChromaFilter(coefficients, builder);
     double[] d1 = { 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
     double[] d2 = { 1.0, 6.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
     double[] d3 = { 2.0, 7.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
     double[] d4 = { 3.0, 8.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
     filter.Consume(d1);
     filter.Consume(d2);
     filter.Consume(d3);
     filter.Consume(d4);
     Assert.AreEqual(2, image.Rows);
     Assert.AreEqual(1.7, image.Get(0, 0), TestsHelper.EPS);
     Assert.AreEqual(3.399999999999999, image.Get(1, 0), TestsHelper.EPS);
     Assert.AreEqual(10.199999999999999, image.Get(0, 1), TestsHelper.EPS);
     Assert.AreEqual(11.899999999999999, image.Get(1, 1), TestsHelper.EPS);
 }
        public void TestCalculate()
        {
            Image image = new Image(2, 3);
            image[0, 0] = 0.0;
            image[0, 1] = 1.0;
            image[1, 0] = 2.0;
            image[1, 1] = 3.0;
            image[2, 0] = 4.0;
            image[2, 1] = 5.0;

            Classifier[] classifiers = {
		        new Classifier(new Filter(0, 0, 1, 1), new Quantizer(0.01, 1.01, 1.5)),	
	        };
            FingerprintCalculator calculator = new FingerprintCalculator(classifiers);

            int[] fp = calculator.Calculate(image);
            Assert.AreEqual(3, fp.Length);
            Assert.AreEqual(TestsHelper.GrayCode(0), fp[0]);
            Assert.AreEqual(TestsHelper.GrayCode(2), fp[1]);
            Assert.AreEqual(TestsHelper.GrayCode(3), fp[2]);
        }
示例#15
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);
        }
示例#16
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));
        }
示例#17
0
        /// <summary>
        /// Export image to a PNG file
        /// </summary>
        public static void Save(Chroma.Image data, string fileName, double power = 1.0)
        {
            int numColors = 6;

            int[,] colors =
            {
                {   0,   0,   0 },
                { 218,  38,   0 },
                { 221,  99,   0 },
                { 255, 253,   0 },
                { 255, 254,  83 },
                { 255, 255, 200 },
                { 255, 255, 255 },
                {   0,   0,   0 },       // TODO: prevent index out of range exception below
            };

            Bitmap image = new Bitmap(data.Columns, data.Rows);

            double min_value = data[0, 0], max_value = data[0, 0];

            for (int y = 0; y < data.Rows; y++)
            {
                for (int x = 0; x < data.Columns; x++)
                {
                    double value = data[y, x];
                    min_value = Math.Min(min_value, value);
                    max_value = Math.Max(max_value, value);
                }
            }

            int    r, g, b;
            double dr, dg, db;

            for (int y = 0; y < data.Rows; y++)
            {
                for (int x = 0; x < data.Columns; x++)
                {
                    double value = (data[y, x] - min_value) / (max_value - min_value);
                    value = Math.Pow(value, power);
                    double color_value = numColors * value;
                    int    color_index = (int)color_value;
                    double color_alpha = color_value - color_index;
                    if (color_index < 0)
                    {
                        color_index = 0;
                        color_alpha = 0;
                    }
                    else if (color_index > numColors)
                    {
                        color_index = numColors;
                        color_alpha = 0;
                    }

                    dr = colors[color_index, 0] + (colors[color_index + 1, 0] - colors[color_index, 0]) * color_alpha;
                    dg = colors[color_index, 1] + (colors[color_index + 1, 1] - colors[color_index, 1]) * color_alpha;
                    db = colors[color_index, 2] + (colors[color_index + 1, 2] - colors[color_index, 2]) * color_alpha;

                    r = (int)dr;
                    g = (int)dg;
                    b = (int)db;
                    //int color = 255 * vlue + 0.5;
                    image.SetPixel(data.Columns - x - 1, y, Color.FromArgb(r, g, b));
                }
            }

            image.Save(fileName, ImageFormat.Png);
        }
示例#18
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
        }
示例#19
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)
        }
示例#20
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
        }