Example #1
0
        //Конструктор дерева
        public BlockTree(Object.Block block, int blockSize)
        {
            mainBlock           = block;
            mainBlock.X         = block.X;
            mainBlock.Y         = block.Y;
            mainBlock.SumR      = block.SumR;
            mainBlock.SumG      = block.SumG;
            mainBlock.SumB      = block.SumB;
            mainBlock.BlockSize = blockSize;
            mainBlock.Depth     = QuadTreeCompression.numLock;
            if (QuadTreeCompression.numLock == (-1))
            {
                QuadTreeCompression.numLock = 2;
            }
            else
            {
                ++QuadTreeCompression.numLock;
            }
            //Для ранговых блоковы
            if (mainBlock.BlockSize > 2)
            {
                Object.Block tmpBlock = QuadTreeCompression.CreateBlockRange(block.X, block.Y, QuadTreeCompression.classImageColor, block.BlockSize / 2, QuadTreeCompression.brightnessImage);
                ul = new BlockTree(tmpBlock, tmpBlock.BlockSize);

                tmpBlock = QuadTreeCompression.CreateBlockRange(block.X + block.BlockSize / 2, block.Y, QuadTreeCompression.classImageColor, block.BlockSize / 2, QuadTreeCompression.brightnessImage);
                ur       = new BlockTree(tmpBlock, tmpBlock.BlockSize);

                tmpBlock = QuadTreeCompression.CreateBlockRange(block.X, block.Y + block.BlockSize / 2, QuadTreeCompression.classImageColor, block.BlockSize / 2, QuadTreeCompression.brightnessImage);
                dl       = new BlockTree(tmpBlock, tmpBlock.BlockSize);

                tmpBlock = QuadTreeCompression.CreateBlockRange(block.X + block.BlockSize / 2, block.Y + block.BlockSize / 2, QuadTreeCompression.classImageColor, block.BlockSize / 2, QuadTreeCompression.brightnessImage);
                dr       = new BlockTree(tmpBlock, tmpBlock.BlockSize);
            }
        }
Example #2
0
        static void Main(string[] args)
        {
            System.Diagnostics.Stopwatch comSw = new Stopwatch();
            System.Diagnostics.Stopwatch decSw = new Stopwatch();

            //System.Console.WriteLine("Classic compression: ");
            //comSw.Start();
            //BlockCompression.Compression(@"C:\Users\Admin\Documents\GitHub\Fractal-Compression\NewFractalCompression\NewFractalCompression\messi.bmp", "Color");
            //comSw.Stop();
            //System.Console.WriteLine((comSw.Elapsed));

            //decSw.Start();
            //BlockCompression.ColorDecompression();
            //decSw.Stop();
            //System.Console.WriteLine((decSw.Elapsed));


            System.Console.WriteLine("Quad Tree compression: ");
            comSw.Start();
            QuadTreeCompression.Compression(@"C:\Users\Admin\Documents\GitHub\Fractal-Compression\NewFractalCompression\NewFractalCompression\messi.bmp", "Color");
            comSw.Stop();
            System.Console.WriteLine((comSw.Elapsed));

            decSw.Start();
            QuadTreeCompression.FakeDecompression();
            decSw.Stop();
            System.Console.WriteLine((decSw.Elapsed));

            System.Console.WriteLine("Please, press enter");
            Console.ReadKey();
        }
Example #3
0
        //Обход дерева и нахождение для нужных узлов коэффициентов
        public void RoundTree(BlockTree rangeTree, Object.BlockArray[] domainArray, Color[,] classImageColor, int range_block_size)
        {
            if (!(QuadTreeCompression.CheckMonotoneBlock(rangeTree.mainBlock)) && (rangeTree.mainBlock.BlockSize > 2))
            {
                RoundTree(rangeTree.ul, domainArray, classImageColor, rangeTree.mainBlock.BlockSize);
                RoundTree(rangeTree.ur, domainArray, classImageColor, rangeTree.mainBlock.BlockSize);
                RoundTree(rangeTree.dl, domainArray, classImageColor, rangeTree.mainBlock.BlockSize);
                RoundTree(rangeTree.dr, domainArray, classImageColor, rangeTree.mainBlock.BlockSize);
            }
            else
            {
                int    current_x        = 0;
                int    current_y        = 0;
                double current_distance = Double.MaxValue;
                double current_shiftR   = 0;
                double current_shiftG   = 0;
                double current_shiftB   = 0;
                bool   oneflag          = false;
                //System.Console.WriteLine("Depth: " + RangeTree.Depth + " " + RangeTree.MainBlock.BlockSize + " " + DomainArray[CurrentSize].BlockSize);
                int CurrentSize = 0;
                for (int i = 0; i < domainArray.Length; ++i)
                {
                    if ((domainArray[i].BlockSize) == (rangeTree.mainBlock.BlockSize * 2))
                    {
                        CurrentSize = i;
                    }
                }
                for (int k = 0; k < domainArray[CurrentSize].num_width; ++k)
                {
                    for (int l = 0; l < domainArray[CurrentSize].num_height; ++l)
                    {
                        double shiftR   = QuadTreeCompression.Shift(rangeTree.mainBlock, domainArray[CurrentSize].Blocks[k, l], rangeTree.mainBlock.BlockSize, 0);
                        double shiftG   = QuadTreeCompression.Shift(rangeTree.mainBlock, domainArray[CurrentSize].Blocks[k, l], rangeTree.mainBlock.BlockSize, 1);
                        double shiftB   = QuadTreeCompression.Shift(rangeTree.mainBlock, domainArray[CurrentSize].Blocks[k, l], rangeTree.mainBlock.BlockSize, 2);
                        double distance = Metrics.DistanceQuad(classImageColor, rangeTree.mainBlock, domainArray[CurrentSize].Blocks[k, l], rangeTree.mainBlock.BlockSize, shiftR);
                        if (distance < 1000000)
                        {
                            oneflag          = true;
                            current_x        = k;
                            current_y        = l;
                            current_shiftR   = shiftR;
                            current_shiftG   = shiftG;
                            current_shiftB   = shiftB;
                            current_distance = distance;
                            //System.Console.WriteLine(current_x + " " + current_y + " " + current_shiftR + " " + current_shiftG + " " + current_shiftB);
                        }
                        else
                        {
                            if (distance < current_distance)
                            {
                                current_x        = k;
                                current_y        = l;
                                current_shiftR   = shiftR;
                                current_shiftG   = shiftG;
                                current_shiftB   = shiftB;
                                current_distance = distance;
                            }
                        }
                        if (oneflag == true)
                        {
                            break;
                        }
                    }
                    if (oneflag == true)
                    {
                        break;
                    }
                }

                rangeTree.mainBlock.Active       = true;
                rangeTree.mainBlock.Coeff.X      = current_x;
                rangeTree.mainBlock.Coeff.Y      = current_y;
                rangeTree.mainBlock.Coeff.shiftR = (int)current_shiftR;
                rangeTree.mainBlock.Coeff.shiftG = (int)current_shiftG;
                rangeTree.mainBlock.Coeff.shiftB = (int)current_shiftB;
                rangeTree.mainBlock.Coeff.Depth  = rangeTree.mainBlock.Depth;
                if (QuadTreeCompression.blockChecker == 0)
                {
                    rangeTree.mainBlock.Coeff.Depth *= (-1);
                }
                ++QuadTreeCompression.blockChecker;
                QuadTreeCompression.listCoeff.Add(rangeTree.mainBlock.Coeff);
                //System.Console.WriteLine(RangeTree.MainBlock.Depth);
                //Запись в файл всех нужные чисел, а так же глубину нахождения узла в дереве
                //Byte[] D = BitConverter.GetBytes(RangeTree.MainBlock.Depth);
                //Byte[] X = BitConverter.GetBytes(RangeTree.MainBlock.Coeff.X);
                //Byte[] Y = BitConverter.GetBytes(RangeTree.MainBlock.Coeff.Y);
                //Byte[] SR = BitConverter.GetBytes(RangeTree.MainBlock.Coeff.shiftR);
                //Byte[] SG = BitConverter.GetBytes(RangeTree.MainBlock.Coeff.shiftG);
                //Byte[] SB = BitConverter.GetBytes(RangeTree.MainBlock.Coeff.shiftB);

                //bw.Write(MyConverter.Convert(D, 1));
                //bw.Write(MyConverter.Convert(X, 1));
                //bw.Write(MyConverter.Convert(Y, 1));
                //bw.Write(MyConverter.Convert(SR, 2));
                //bw.Write(MyConverter.Convert(SG, 2));
                //bw.Write(MyConverter.Convert(SB, 2));
            }
        }