Esempio n. 1
0
        /* WL_FwtVolume
         *
         * Perform a LEVELS-deep separable forward wavelet transform of SOURCE using
         * the filters HIPASS and LOWPASS,  storing results in DEST.
         * ROWS and COLS indicate the size of the SOURCE & DEST volume.
         * The transformed coefficients in DEST are stored in the Mallat
         * representation.
         *
         * The edge treatment is to perform periodic extension.
         */
        public static int WL_FwtVolume(double[,,] source, ref double[,,] dest,
                                       int depth, int rows, int cols, int levels,
                                       WL_Filter lowpass, WL_Filter hipass)
        {
            double[] tempSource;
            double[] tempDest;
            int      d, c, r, level;

            /* allocate the temp arrays for columns */
            tempSource = new double[Math.Max(rows, depth)];
            tempDest   = new double[Math.Max(rows, depth)];

            /* copy the source to dest to facilitate multiple levels */
            for (d = 0; d < depth; d++)
            {
                for (r = 0; r < rows; r++)
                {
                    for (int colNum = 0; colNum < cols; colNum++)
                    {
                        dest[d, r, colNum] = source[d, r, colNum];
                    }
                }
            }

            for (level = 0; level < levels; level++, rows /= 2, cols /= 2, depth /= 2)
            {
                /* transform each row */
                for (d = 0; d < depth; d++)
                {
                    for (r = 0; r < rows; r++)
                    {
                        var extract = WaveletUtil.Extract1DArray(dest, d, r, cols);
                        var result  = WL_FwtVector(extract, ref extract, cols, 1, lowpass, hipass);
                        WaveletUtil.Patch1DArray(extract, ref dest, d, r, cols);

                        if (result != 0)
                        {
                            return(1);
                        }
                    }
                }

//# ifdef DEBUG_MATRIX
//                fprintf(stderr, "level %d ROW:\n", level);
//                for (r = 0; r < rows; r++)
//                {
//                    for (c = 0; c < cols; c++) fprintf(stderr, "%f ", dest[r][c]);
//                    fprintf(stderr, "\n");
//                }
//#endif

                /* transform each column */
                for (d = 0; d < depth; d++)
                {
                    for (c = 0; c < cols; c++)
                    {
                        for (r = 0; r < rows; r++)
                        {
                            tempSource[r] = dest[d, r, c];
                        }
                        if (WL_FwtVector(tempSource, ref tempDest, rows, 1, lowpass, hipass)
                            != 0)
                        {
                            return(1);
                        }
                        for (r = 0; r < rows; r++)
                        {
                            dest[d, r, c] = tempDest[r];
                        }
                    }
                }

                /* transform each depth line */
                for (r = 0; r < rows; r++)
                {
                    for (c = 0; c < cols; c++)
                    {
                        for (d = 0; d < depth; d++)
                        {
                            tempSource[d] = dest[d, r, c];
                        }
                        if (WL_FwtVector(tempSource, ref tempDest, depth, 1, lowpass, hipass)
                            != 0)
                        {
                            return(1);
                        }
                        for (d = 0; d < depth; d++)
                        {
                            dest[d, r, c] = tempDest[d];
                        }
                    }
                }

//# ifdef DEBUG_MATRIX
//                fprintf(stderr, "level %d COL:\n", level);
//                for (r = 0; r < rows; r++)
//                {
//                    for (c = 0; c < cols; c++) fprintf(stderr, "%f ", dest[r][c]);
//                    fprintf(stderr, "\n");
//                }
//#endif
            }

            return(0);
        }
Esempio n. 2
0
        /* WL_IwtMatrix
         *
         * Perform a LEVELS-deep separable inverse wavelet transform of SOURCE using
         * the filters HIPASS and LOWPASS,  storing results in DEST.
         * ROWS and COLS indicate the size of the SOURCE & DEST matrix.
         * The transformed coefficients in SOURCE must be stored in the Mallat
         * format.
         *
         * The edge treatment is to perform periodic extension.
         */
        public static int WL_IwtMatrix(double[,] source, double[,] dest,
                                       int rows, int cols, int levels,
                                       WL_Filter lowpass, WL_Filter hipass)
        {
            double[] tempSource;
            double[] tempDest;
            int      c, r, level;

            /* allocate the temp arrays for columns */
            tempSource = new double[rows];
            tempDest   = new double[rows];

            /* copy the source to dest to facilitate multiple levels */
            for (r = 0; r < rows; r++)
            {
                Array.Copy(source, r * cols, dest, r * cols, cols);
            }

            rows = rows / WaveletUtil.WL_pow2(levels - 1);
            cols = cols / WaveletUtil.WL_pow2(levels - 1);

            for (level = 0; level < levels; level++, rows *= 2, cols *= 2)
            {
                /* transform each column */
                for (c = 0; c < cols; c++)
                {
                    for (r = 0; r < rows; r++)
                    {
                        tempSource[r] = dest[r, c];
                    }

                    if (WL_IwtVector(tempSource, ref tempDest, rows, 1, lowpass, hipass)
                        != 0)
                    {
                        return(1);
                    }
                    for (r = 0; r < rows; r++)
                    {
                        dest[r, c] = tempDest[r];
                    }
                }

//# ifdef DEBUG_MATRIX
//                fprintf(stderr, "level %d COL:\n", level);
//                for (r = 0; r < rows; r++)
//                {
//                    for (c = 0; c < cols; c++) fprintf(stderr, "%f ", dest[r][c]);
//                    fprintf(stderr, "\n");
//                }
//#endif


                /* transform each row */
                for (r = 0; r < rows; r++)
                {
                    var extract = WaveletUtil.Extract1DArray(dest, r, cols);
                    var result  = WL_IwtVector(extract, ref extract, cols, 1, lowpass, hipass);
                    WaveletUtil.Patch1DArray(extract, ref dest, r, cols);
                    if (result != 0)
                    {
                        return(1);
                    }
                }

//# ifdef DEBUG_MATRIX
//                fprintf(stderr, "level %d ROW:\n", level);
//                for (r = 0; r < rows; r++)
//                {
//                    for (c = 0; c < cols; c++) fprintf(stderr, "%f ", dest[r][c]);
//                    fprintf(stderr, "\n");
//                }
//#endif
            }

            return(0);
        }
Esempio n. 3
0
        /* WL_IwtVolume
         *
         * Perform a LEVELS-deep separable inverse wavelet transform of SOURCE using
         * the filters HIPASS and LOWPASS,  storing results in DEST.
         * ROWS and COLS indicate the size of the SOURCE & DEST volume.
         * The transformed coefficients in SOURCE must be stored in the Mallat
         * format.
         *
         * The edge treatment is to perform periodic extension.
         */
        public static int WL_IwtVolume(double[,,] source, ref double[,,] dest,
                                       int depth, int rows, int cols, int levels,
                                       WL_Filter lowpass, WL_Filter hipass)
        {
            double[] tempSource;
            double[] tempDest;
            int      d, c, r, level;

            /* allocate the temp arrays for columns */
            tempSource = new double[Math.Max(rows, depth)];
            tempDest   = new double[Math.Max(rows, depth)];

            /* copy the source to dest to facilitate multiple levels */
            for (d = 0; d < depth; d++)
            {
                for (r = 0; r < rows; r++)
                {
                    for (int colNum = 0; colNum < cols; colNum++)
                    {
                        dest[d, r, colNum] = source[d, r, colNum];
                    }
                }
            }

            rows  = rows / WaveletUtil.WL_pow2(levels - 1);
            cols  = cols / WaveletUtil.WL_pow2(levels - 1);
            depth = depth / WaveletUtil.WL_pow2(levels - 1);

            for (level = 0; level < levels; level++, rows *= 2, cols *= 2, depth *= 2)
            {
                /* transform each column */
                for (d = 0; d < depth; d++)
                {
                    for (c = 0; c < cols; c++)
                    {
                        for (r = 0; r < rows; r++)
                        {
                            tempSource[r] = dest[d, r, c];
                        }
                        if (WL_IwtVector(tempSource, ref tempDest, rows, 1, lowpass, hipass)
                            != 0)
                        {
                            return(1);
                        }
                        for (r = 0; r < rows; r++)
                        {
                            dest[d, r, c] = tempDest[r];
                        }
                    }
                }

                /* transform each row */
                for (d = 0; d < depth; d++)
                {
                    for (r = 0; r < rows; r++)
                    {
                        var extract = WaveletUtil.Extract1DArray(dest, d, r, cols);
                        var result  = WL_IwtVector(extract, ref extract, cols, 1, lowpass, hipass);
                        WaveletUtil.Patch1DArray(extract, ref dest, d, r, cols);

                        if (result != 0)
                        {
                            return(1);
                        }
                    }
                }

                /* transform each depth line */
                for (r = 0; r < rows; r++)
                {
                    for (c = 0; c < cols; c++)
                    {
                        for (d = 0; d < depth; d++)
                        {
                            tempSource[d] = dest[d, r, c];
                        }
                        if (WL_IwtVector(tempSource, ref tempDest, depth, 1, lowpass, hipass)
                            != 0)
                        {
                            return(1);
                        }
                        for (d = 0; d < depth; d++)
                        {
                            dest[d, r, c] = tempDest[d];
                        }
                    }
                }
            }

            return(0);
        }
Esempio n. 4
0
        /* WL_IswtMatrix
         *
         * Perform a LEVELS-deep separable inverse symmetric wavelet
         * transform of SOURCE using
         * the filters HIPASS and LOWPASS,  storing results in DEST.
         * ROWS and COLS indicate the size of the SOURCE & DEST vectors.
         * The transformed coefficients in SOURCE must be stored in the Mallat
         * format.
         */
        public static int WL_IswtMatrix(double[,] source, ref double[,] dest,
                                        int rows, int cols, int levels,
                                        WL_Filter lowpass, WL_Filter hipass)
        {
            int[]    rSplit;
            int[]    cSplit;
            double[] tempSource;
            double[] tempDest;
            int      c, r, level;

            rSplit = new int[levels + 1];
            cSplit = new int[levels + 1];

            /* allocate the temp arrays for columns */
            tempSource = new double[rows];
            tempDest   = new double[rows];

            /* copy the source to dest to facilitate multiple levels */
            for (r = 0; r < rows; r++)
            {
                for (int colNum = 0; colNum < cols; colNum++)
                {
                    dest[r, colNum] = source[r, colNum];
                }
            }

            /* Determine the way the dimensions of the signal is partitioned. */
            for (level = levels, c = cols, r = rows; level > 0; level--)
            {
                rSplit[level] = r / 2;
                r             = (r + 1) / 2;
                cSplit[level] = c / 2;
                c             = (c + 1) / 2;
            }
            rSplit[0] = r;
            cSplit[0] = c;

            rows = rSplit[0];
            cols = cSplit[0];

            for (level = 1; level < levels + 1; level++)
            {
                rows += (rSplit[level]);
                cols += (cSplit[level]);

                /* transform each column */
                for (c = 0; c < cols; c++)
                {
                    for (r = 0; r < rows; r++)
                    {
                        tempSource[r] = dest[r, c];
                    }
                    if (WL_IswtVector(tempSource, ref tempDest, rows, 1, lowpass, hipass)
                        != 0)
                    {
                        return(1);
                    }
                    for (r = 0; r < rows; r++)
                    {
                        dest[r, c] = tempDest[r];
                    }
                }

//# ifdef DEBUG_MATRIX
//                fprintf(stderr, "level %d COL:\n", level);
//                for (r = 0; r < rows; r++)
//                {
//                    for (c = 0; c < cols; c++) fprintf(stderr, "%f ", dest[r][c]);
//                    fprintf(stderr, "\n");
//                }
//#endif

                /* transform each row */
                for (r = 0; r < rows; r++)
                {
                    var extract = WaveletUtil.Extract1DArray(dest, r, cols);
                    var result  = WL_IswtVector(extract, ref extract, cols, 1, lowpass, hipass);
                    WaveletUtil.Patch1DArray(extract, ref dest, r, cols);

                    if (result != 0)
                    {
                        return(1);
                    }
                }

//# ifdef DEBUG_MATRIX
//                fprintf(stderr, "level %d ROW:\n", level);
//                for (r = 0; r < rows; r++)
//                {
//                    for (c = 0; c < cols; c++) fprintf(stderr, "%f ", dest[r][c]);
//                    fprintf(stderr, "\n");
//                }
//#endif
            }

            return(0);
        }
Esempio n. 5
0
        /* WL_IswtVolume
         *
         * Perform a LEVELS-deep separable inverse symmetric wavelet
         * transform of SOURCE using
         * the filters HIPASS and LOWPASS,  storing results in DEST.
         * DEPTH, ROWS and COLS indicate the size of the SOURCE & DEST volumes.
         * The transformed coefficients in SOURCE must be stored in the Mallat
         * format.
         */
        public static int WL_IswtVolume(double[,,] source, ref double[,,] dest,
                                        int depth, int rows, int cols, int levels,
                                        WL_Filter lowpass, WL_Filter hipass)
        {
            int[]    dSplit;
            int[]    rSplit;
            int[]    cSplit;
            double[] tempSource;
            double[] tempDest;
            int      d, c, r, level;

            rSplit = new int[levels + 1];
            cSplit = new int[levels + 1];
            dSplit = new int[levels + 1];

            /* allocate the temp arrays for columns */
            tempSource = new double[Math.Max(depth, rows)];
            tempDest   = new double[Math.Max(depth, rows)];

            /* copy the source to dest to facilitate multiple levels */
            for (d = 0; d < depth; d++)
            {
                for (r = 0; r < rows; r++)
                {
                    for (int colNum = 0; colNum < cols; colNum++)
                    {
                        dest[d, r, colNum] = source[d, r, colNum];
                    }
                }
            }

            /* Determine the way the dimensions of the signal is partitioned. */
            for (level = levels, c = cols, r = rows, d = depth; level > 0; level--)
            {
                rSplit[level] = r / 2;
                r             = (r + 1) / 2;
                cSplit[level] = c / 2;
                c             = (c + 1) / 2;
                dSplit[level] = d / 2;
                d             = (d + 1) / 2;
            }
            rSplit[0] = r;
            cSplit[0] = c;
            dSplit[0] = d;

            rows  = rSplit[0];
            cols  = cSplit[0];
            depth = dSplit[0];

            for (level = 1; level < levels + 1; level++)
            {
                rows  += (rSplit[level]);
                cols  += (cSplit[level]);
                depth += (dSplit[level]);

                /* transform each row */
                for (d = 0; d < depth; d++)
                {
                    for (r = 0; r < rows; r++)
                    {
                        var extract = WaveletUtil.Extract1DArray(dest, d, r, cols);
                        var result  = WL_IswtVector(extract, ref extract, cols, 1, lowpass, hipass);
                        WaveletUtil.Patch1DArray(extract, ref dest, d, r, cols);

                        if (result != 0)
                        {
                            return(1);
                        }
                    }
                }

                /* transform each column */
                for (d = 0; d < depth; d++)
                {
                    for (c = 0; c < cols; c++)
                    {
                        for (r = 0; r < rows; r++)
                        {
                            tempSource[r] = dest[d, r, c];
                        }

                        if (WL_IswtVector(tempSource, ref tempDest, rows, 1, lowpass, hipass)
                            != 0)
                        {
                            return(1);
                        }
                        for (r = 0; r < rows; r++)
                        {
                            dest[d, r, c] = tempDest[r];
                        }
                    }
                }

                /* transform each depth line */
                for (r = 0; r < rows; r++)
                {
                    for (c = 0; c < cols; c++)
                    {
                        for (d = 0; d < depth; d++)
                        {
                            tempSource[d] = dest[d, r, c];
                        }
                        if (WL_IswtVector(tempSource, ref tempDest, depth, 1, lowpass, hipass)
                            != 0)
                        {
                            return(1);
                        }
                        for (d = 0; d < depth; d++)
                        {
                            dest[d, r, c] = tempDest[d];
                        }
                    }
                }
            }

            return(0);
        }
Esempio n. 6
0
        /* WL_IrwtVolume
         *
         * Perform a LEVELS-deep separable inverse redundant transform of SOURCE using
         * the filters HIPASS and LOWPASS,  storing results in matrix DEST.
         * ROWS and COLS indicate the size of the rows and columns of volume SOURCE
         * and the size of matrix DEST.
         * The transformed coefficients in SOURCE are stored using an overcomplete
         * representation, each ROWSxCOLS matrix representing a level in the
         * multiresolution pyramid with coarse approximation in zeroth matrix and
         * the 3 detail signals at level i in matrix 3*i+j, where 1<=j<=3.
         * The input volume SOURCE has depth levels+1.
         */
        public static int WL_IrwtVolume(
            double[,,] source,
            ref double[,] dest,
            int rows,
            int cols,
            int levels,
            WL_Filter lowpass,
            WL_Filter hipass
            )
        {
            double[] tempDest;
            double[,] HighMatrix;
            double[,] RowMatrix;
            double[,] ColMatrix;
            int c, r, level;
            int hori, vert, diag;

            /* allocate the temp arrays to hold 1-D results */
            RowMatrix = new double[2, cols];

            ColMatrix = new double[2, rows];

            HighMatrix = new double[rows, cols];

            tempDest = new double[rows];

            /* copy the source to dest to facilitate multiple levels */
            for (r = 0; r < rows; r++)
            {
                for (int colNum = 0; colNum < cols; colNum++)
                {
                    dest[r, colNum] = source[0, r, colNum];
                }
            }

            for (level = levels; level >= 1; level--)
            {
                /* setup indices to horizontal,vertical & diagonal detail signals */
                vert = 3 * (level - 1) + 1;
                hori = vert + 1;
                diag = hori + 1;

                /* transform each column */
                /* first, run the inverse transform using the lowpass output */
                /* from the 1D forward redundant transform along the columns */
                for (c = 0; c < cols; c++)
                {
                    for (r = 0; r < rows; r++)
                    {
                        ColMatrix[0, r] = dest[r, c];
                        ColMatrix[1, r] = source[vert, r, c];
                    }
                    if (WL_IrwtMatrix(ColMatrix, ref tempDest, rows, level, lowpass, hipass) != 1)
                    {
                        return(0);
                    }
                    for (r = 0; r < rows; r++)
                    {
                        dest[r, c] = tempDest[r];
                    }
                }

                /* now, for the high pass output */
                for (c = 0; c < cols; c++)
                {
                    for (r = 0; r < rows; r++)
                    {
                        ColMatrix[0, r] = source[hori, r, c];
                        ColMatrix[1, r] = source[diag, r, c];
                    }
                    if (WL_IrwtMatrix(ColMatrix, ref tempDest, rows, level, lowpass, hipass) != 1)
                    {
                        return(0);
                    }
                    for (r = 0; r < rows; r++)
                    {
                        HighMatrix[r, c] = tempDest[r];
                    }
                }

                /* transform each row */
                for (r = 0; r < rows; r++)
                {
                    for (int colNum = 0; colNum < cols; colNum++)
                    {
                        RowMatrix[0, colNum] = dest[r, colNum];
                        RowMatrix[1, colNum] = HighMatrix[r, colNum];
                    }

                    var extract = WaveletUtil.Extract1DArray(dest, r, cols);
                    var result  = WL_IrwtMatrix(RowMatrix, ref extract, cols, level, lowpass, hipass);
                    WaveletUtil.Patch1DArray(extract, ref dest, r, cols);

                    if (result != 1)
                    {
                        return(0);
                    }
                }
            }

            return(1);
        }