Exemplo n.º 1
0
        public void LearningBasedWBExtractSimpleFeatures()
        {
            using (var wb = LearningBasedWB.Create(null))
                using (var src = Image("lenna.png"))
                    using (var dst = new Mat())
                    {
                        wb.ExtractSimpleFeatures(src, dst);

                        unsafe
                        {
                            // 1. Chromaticity of an average (R,G,B) tuple
                            // 2. Chromaticity of the brightest (R,G,B) tuple (while ignoring saturated pixels)
                            // 3. Chromaticity of the dominant (R,G,B) tuple (the one that has the highest value
                            //    in the RGB histogram)
                            // 4. Mode of the chromaticity palette, that is constructed by taking 300 most common
                            //    colors according to the RGB histogram and projecting them on the chromaticity plane.
                            //    Mode is the most high-density point of the palette, which is computed by a straightforward
                            //    fixed-bandwidth kernel density estimator with a Epanechnikov kernel function.
                            testOutputHelper.WriteLine($"{dst.DataPointer[0]}");
                            testOutputHelper.WriteLine($"{dst.DataPointer[1]}");
                            testOutputHelper.WriteLine($"{dst.DataPointer[2]}");
                            testOutputHelper.WriteLine($"{dst.DataPointer[3]}");
                        }
                    }
        }
Exemplo n.º 2
0
        public void Sample()
        {
            if (!Debugger.IsAttached)
            {
                return;
            }

            string[] files;
            using (var dialog = new System.Windows.Forms.OpenFileDialog
            {
                RestoreDirectory = true,
                Multiselect = true,
                Filter = "Image Files(*.png;*.jpg;*.jpeg;*.bmp)|*.png;*.jpg;*.jpeg;*.bmp"
            })
            {
                if (dialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                {
                    return;
                }
                files = dialog.FileNames;
            }

            var desktop = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            var dstDir  = System.IO.Path.Combine(desktop, "WB");

            System.IO.Directory.CreateDirectory(dstDir);

            using var simpleWB    = SimpleWB.Create();
            using var learningWB  = LearningBasedWB.Create("");
            using var grayworldWB = GrayworldWB.Create();

            foreach (var file in files)
            {
                testOutputHelper.WriteLine(System.IO.Path.GetFileNameWithoutExtension(file));

                using var src          = new Mat(file);
                using var dstSimple    = new Mat();
                using var dstLearning  = new Mat();
                using var dstGrayworld = new Mat();
                simpleWB.BalanceWhite(src, dstSimple);
                learningWB.BalanceWhite(src, dstLearning);
                grayworldWB.BalanceWhite(src, dstGrayworld);

                using var temp1 = new Mat();
                using var temp2 = new Mat();
                using var dst   = new Mat();
                Cv2.HConcat(src, dstSimple, temp1);
                Cv2.HConcat(dstLearning, dstGrayworld, temp2);
                Cv2.VConcat(temp1, temp2, dst);

                /*
                 * using (new Window("src", src))
                 * using (new Window("dst", dst))
                 * {
                 *  Cv2.WaitKey();
                 * }*/
                dst.SaveImage(System.IO.Path.Combine(dstDir, $"{System.IO.Path.GetFileNameWithoutExtension(file)}.png"));
            }
        }
Exemplo n.º 3
0
        public void LearningBasedWBProperties()
        {
            using var wb = LearningBasedWB.Create(null);
            var histBinNum          = wb.HistBinNum;
            var rangeMaxVal         = wb.RangeMaxVal;
            var saturationThreshold = wb.SaturationThreshold;

            const int   ival = 100;
            const float fval = 100f;

            wb.HistBinNum          = ival;
            wb.RangeMaxVal         = ival;
            wb.SaturationThreshold = fval;

            Assert.Equal(ival, wb.HistBinNum);
            Assert.Equal(ival, wb.RangeMaxVal);
            Assert.Equal(fval, wb.SaturationThreshold);

            Assert.NotEqual(histBinNum, wb.HistBinNum);
            Assert.NotEqual(rangeMaxVal, wb.RangeMaxVal);
            Assert.NotEqual(saturationThreshold, wb.SaturationThreshold);
        }