A frequency table defining how likely a sample will be formed during a TrigradCompression.
示例#1
0
        static void Main(string[] args)
        {
            Bitmap inputBitmap = new Bitmap("tests\\Penguins.jpg");
            FrequencyTable table = new FrequencyTable(inputBitmap);

            var results = TrigradCompressor.CompressBitmap(inputBitmap, new TrigradOptions { SampleCount = 50000, SampleRadius = 0, FrequencyTable = table });

            results.DebugVisualisation().Save("tests\\points.png");

            var returned = TrigradDecompressor.DecompressBitmap(results,new BlindDitherGrader());

            returned.Output.Save("tests\\output.png");
            returned.DebugOutput.Save("tests\\debug_output.png");
            returned.MeshOutput.Save("tests\\mesh_output.png");
        }
示例#2
0
文件: Program.cs 项目: ruarai/Trigrad
        static void Main(string[] args)
        {
            Stopwatch s = new Stopwatch();
            s.Start();
            Console.WriteLine("Trigrad");
            string input = "tests\\input\\Tulips.jpg";

            PixelMap inputBitmap = PixelMap.SlowLoad(new Bitmap(input));
            FrequencyTable table = new FrequencyTable(inputBitmap,1);

            var options = new TrigradOptions
            {
                SampleCount = 40000,
                FrequencyTable = table,
                Resamples = 4,
                Iterations =0,
                Random = new Random(0),
                ResampleColors = true,
                Renderer = new ShapeFill(3)
            };

            var results = TrigradCompressor.CompressBitmap(inputBitmap, options);

            results.DebugVisualisation().GetBitmap().Save("tests\\points.png");

            results.Mesh = MeshBuilder.BuildMesh(results.SampleTable);
            results.MeshOutput(inputBitmap).GetBitmap().Save("tests\\mesh_a.png");

            TrigradOptimiser.OptimiseMesh(results, inputBitmap, options);

            GPUT.CalculateMesh(results.Mesh);

            //results.Save(new FileStream("tests\\out.tri", FileMode.Create));

            results.MeshOutput(inputBitmap).GetBitmap().Save("tests\\mesh_b.png");

            Console.WriteLine(results.SampleTable.Count);

            //var loaded = new TrigradCompressed(new FileStream("tests\\out.tri", FileMode.Open));

            //results.Mesh = results.Mesh.OrderBy(t => t.CenterColor.Lightness).ToList();
            results.Mesh.Shuffle(options.Random);

            var returned = TrigradDecompressor.DecompressBitmap(results, options);

            returned.Output.GetBitmap().Save("tests\\output.png");
            returned.DebugOutput.GetBitmap().Save("tests\\debug_output.png");

            int error = errorBitmap(inputBitmap, returned.Output);
            double avgError = Math.Round((double)error / (inputBitmap.Width * inputBitmap.Height * 3), 2);

            Console.WriteLine("{0} error", avgError);
            Console.WriteLine("{0} s", Math.Round(s.ElapsedMilliseconds / 1000d, 2));

            saveBackup(avgError, Path.GetFileNameWithoutExtension(input), options);

            Console.Beep();
            Console.ReadKey();
        }