コード例 #1
0
        public Spiht3DCoder(IntPtr image, int width, int height, int depth)
        {
            _coefficients = (short *)image.ToPointer();



            _quantization = (short *)Marshal.AllocHGlobal(width * height * depth * 2);

            for (int i = 0; i < width * height * depth; i++)
            {
                *(_quantization + i) = 0;
            }

            _imageSize = new SubbandSize {
                Width = width, Height = height, Depth = depth
            };

            _subbandSizes = SpihtHelpers.CalculateSubbands(width, height, depth);

            _threshold = SpihtHelpers.AbsoluteMax((short *)image.ToPointer(), width * height * depth);

            _lsp = new LinkedList <Spiht3DPixel>();
            _lip = new LinkedList <Spiht3DPixel>();
            _lis = new LinkedList <Spiht3DSet>();

            _thresholdModel = new ArithmeticModel(4096);
            _bitModel       = new ArithmeticModel(2, true);
        }
コード例 #2
0
        private void Init()
        {
            _lip.Clear();
            _lsp.Clear();
            _lis.Clear();

            SubbandSize lowestSubband = _subbandSizes.Last();

            for (byte band = 0; band < lowestSubband.Depth; band++)
            {
                for (short row = 0; row < lowestSubband.Height; row++)
                {
                    for (short column = 0; column < lowestSubband.Width; column++)
                    {
                        _lip.AddLast(new Spiht3DPixel {
                            X = column, Y = row, Z = band
                        });

                        // Not all of them roots
                        if ((row & 0x1) != 0 || (column & 0x1) != 0 || (band & 0x1) != 0)
                        {
                            _lis.AddLast(new Spiht3DSet {
                                Type = SetType.Descendent, X = column, Y = row, Z = band
                            });
                        }
                    }
                }
            }
        }
コード例 #3
0
        private void ReconstructD(short x, short y, byte z)
        {
            SubbandSize lowestSubband = _subbandSizes.Last();

            if (x >= lowestSubband.Width || y >= lowestSubband.Height || z >= lowestSubband.Depth)
            {
                if (2 * x < _imageSize.Width && 2 * y < _imageSize.Height && 2 * z < _imageSize.Depth)
                {
                    SubReconstructD((short)(x * 2), (short)(y * 2), (byte)(z * 2));
                }
            }
            else if ((x & 0x1) == 1 && (y & 0x1) == 0 && (z & 0x1) == 0)
            {
                SubReconstructD((short)(x + lowestSubband.Width - 1), y, z);
            }
            else if ((x & 0x1) == 0 && (y & 0x1) == 1 && (z & 0x1) == 0)
            {
                SubReconstructD(x, (short)(y + lowestSubband.Height - 1), z);
            }
            else if ((x & 0x1) == 1 && (y & 0x1) == 1 && (z & 0x1) == 0)
            {
                SubReconstructD((short)(x + lowestSubband.Width - 1), (short)(y + lowestSubband.Height - 1), z);
            }
            else if ((x & 0x1) == 0 && (y & 0x1) == 0 && (z & 0x1) == 1)
            {
                SubReconstructD(x, y, (byte)(z + lowestSubband.Depth - 1));
            }
            else if ((x & 0x1) == 1 && (y & 0x1) == 0 && (z & 0x1) == 1)
            {
                SubReconstructD((short)(x + lowestSubband.Width - 1), y, (byte)(z + lowestSubband.Depth - 1));
            }
            else if ((x & 0x1) == 0 && (y & 0x1) == 1 && (z & 0x1) == 1)
            {
                SubReconstructD(x, (short)(y + lowestSubband.Height - 1), (byte)(z + lowestSubband.Depth - 1));
            }
            else if ((x & 0x1) == 1 && (y & 0x1) == 1 && (z & 0x1) == 1)
            {
                SubReconstructD((short)(x + lowestSubband.Width - 1), (short)(y + lowestSubband.Height - 1),
                                (byte)(z + lowestSubband.Depth - 1));
            }

            if (4 * x < _imageSize.Width && 4 * y < _imageSize.Height && 4 * z < _imageSize.Depth)
            {
                _lis.AddLast(new Spiht3DSet {
                    Type = SetType.Grandchildren, X = x, Y = y, Z = z
                });
            }
        }
コード例 #4
0
        private void ReconstructG(short x, short y, byte z)
        {
            SubbandSize lowestSubband = _subbandSizes.Last();

            if (x >= lowestSubband.Width || y >= lowestSubband.Height || z >= lowestSubband.Depth)
            {
                if (2 * x < _imageSize.Width && 2 * y < _imageSize.Height && 2 * z < _imageSize.Depth)
                {
                    SubReconstructG((short)(x * 2), (short)(y * 2), (byte)(z * 2));
                }
            }
            else if ((x & 0x1) == 1 && (y & 0x1) == 0 && (z & 0x1) == 0)
            {
                SubReconstructG((short)(x + lowestSubband.Width - 1), y, z);
            }
            else if ((x & 0x1) == 0 && (y & 0x1) == 1 && (z & 0x1) == 0)
            {
                SubReconstructG(x, (short)(y + lowestSubband.Height - 1), z);
            }
            else if ((x & 0x1) == 1 && (y & 0x1) == 1 && (z & 0x1) == 0)
            {
                SubReconstructG((short)(x + lowestSubband.Width - 1), (short)(y + lowestSubband.Height - 1), z);
            }
            else if ((x & 0x1) == 0 && (y & 0x1) == 0 && (z & 0x1) == 1)
            {
                SubReconstructG(x, y, (byte)(z + lowestSubband.Depth - 1));
            }
            else if ((x & 0x1) == 1 && (y & 0x1) == 0 && (z & 0x1) == 1)
            {
                SubReconstructG((short)(x + lowestSubband.Width - 1), y, (byte)(z + lowestSubband.Depth - 1));
            }
            else if ((x & 0x1) == 0 && (y & 0x1) == 1 && (z & 0x1) == 1)
            {
                SubReconstructG(x, (short)(y + lowestSubband.Height - 1), (byte)(z + lowestSubband.Depth - 1));
            }
            else if ((x & 0x1) == 1 && (y & 0x1) == 1 && (z & 0x1) == 1)
            {
                SubReconstructG((short)(x + lowestSubband.Width - 1), (short)(y + lowestSubband.Height - 1),
                                (byte)(z + lowestSubband.Depth - 1));
            }
        }