public AdvancedConvolutionMatrixFilter(Matrix convolutionKernal, BiModulator Value1Op, BiModulator Value2Op)
        {
            if (convolutionKernal == null)
            {
                throw new ArgumentNullException("convolutionKernal");
            }

            _convolutionKernal = convolutionKernal;
            _Value1Op          = Value1Op;
            _Value2Op          = Value2Op;
        }
Beispiel #2
0
 public BiModulatorMatrixFilter(BiModulator modulator)
 {
     _modulator = modulator;
 }
Beispiel #3
0
        public Matrix AdvancedConvolution(Matrix convolvee,
                                          BiModulator Value1Op, BiModulator Value2Op)
        {
            int r = RowCount + convolvee.RowCount - 1;
            int c = ColumnCount + convolvee.ColumnCount - 1;

            Matrix ret = new Matrix(r, c);

            //int iiend;
            //int jjend;

            //List<float> group = new List<float>();
            float term;



            int n1;
            int n2;
            int k1;
            int k2;

            int[] times    = new int[16];
            int   lasttime = System.Environment.TickCount;
            int   time;

            time = System.Environment.TickCount; times[0] += time - lasttime; lasttime = time;
            for (n1 = 0; n1 < r; n1++)
            {
                ////time = Environment.TickCount; times[1] += time - lasttime; lasttime = time;
                for (n2 = 0; n2 < c; n2++)
                {
                    //group.Clear();
                    term = 0;//Literal.Zero;

                    for (k1 = 0; k1 < RowCount; k1++)
                    {
                        ////time = Environment.TickCount; times[2] += time - lasttime; lasttime = time;
                        if (n1 - k1 < 0)
                        {
                            break;
                        }
                        if (n1 - k1 >= convolvee.RowCount)
                        {
                            continue;
                        }
                        ////time = Environment.TickCount; times[3] += time - lasttime; lasttime = time;

                        ////time = Environment.TickCount; times[4] += time - lasttime; lasttime = time;

                        ////time = Environment.TickCount; times[5] += time - lasttime; lasttime = time;
                        for (k2 = 0; k2 < ColumnCount; k2++)
                        {
                            ////time = Environment.TickCount; times[6] += time - lasttime; lasttime = time;
                            if (n2 - k2 < 0)
                            {
                                break;
                            }
                            if (n2 - k2 >= convolvee.ColumnCount)
                            {
                                continue;
                            }

                            ////time = Environment.TickCount; times[7] += time - lasttime; lasttime = time;

                            //float expr = new FunctionCall(
                            //    Value1Op,
                            //    this[k1, k2],
                            //    convolvee[n1 - k1, n2 - k2]);

                            term = Value2Op(term, Value1Op(this[k1, k2], convolvee[n1 - k1, n2 - k2]));
                            ////time = Environment.TickCount; times[11] += time - lasttime; lasttime = time;
                            //////expr = expr.CleanUp();
                            ////time = Environment.TickCount; times[10] += time - lasttime; lasttime = time;
                            //////expr = new FunctionCall(
                            //////    Value2Op,
                            //////    term,
                            //////    expr);

                            //group.Add(
                            //    (expr));

                            ////time = Environment.TickCount; times[9] += time - lasttime; lasttime = time;
                            //////term = expr.CleanUp();
                            ////time = Environment.TickCount; times[8] += time - lasttime; lasttime = time;
                        }
                    }

                    //float[] terms = group.ToArray();
                    //FunctionCall fc = new FunctionCall(Value2Op, terms);
                    //float expr2 = fc.CleanUp();
                    //time = Environment.TickCount; times[12] += time - lasttime; lasttime = time;
                    ret[n1, n2] = term;// fc.CleanUp();
                    ////time = Environment.TickCount; times[13] += time - lasttime; lasttime = time;
                }
                ////time = Environment.TickCount; times[14] += time - lasttime; lasttime = time;
            }
            time = System.Environment.TickCount; times[15] += time - lasttime; lasttime = time;



            ////////int i;
            ////////int j;
            ////////int ii;
            ////////int jj;
            //////int r = RowCount + convolvee.RowCount - 1;
            //////int c = ColumnCount + convolvee.ColumnCount - 1;

            //////Matrix2 ret = new Matrix2(r, c);

            ////////int iiend;
            ////////int jjend;

            //////List<float> group = new List<float>();
            //////float term;

            //////int n1;
            //////int n2;
            //////int k1;
            //////int k2;

            //////int[] times = new int[16];
            //////int lasttime = Environment.TickCount;
            //////int time;

            //////time = Environment.TickCount; times[0] += time - lasttime; lasttime = time;
            //////for (n1 = 0; n1 < r; n1++)
            //////{
            //////    time = Environment.TickCount; times[1] += time - lasttime; lasttime = time;
            //////    for (k1 = 0; k1 < RowCount; k1++)
            //////    {
            //////        time = Environment.TickCount; times[2] += time - lasttime; lasttime = time;
            //////        if (n1 - k1 < 0) { break; }
            //////        if (n1 - k1 >= convolvee.RowCount) { continue; }
            //////        time = Environment.TickCount; times[3] += time - lasttime; lasttime = time;

            //////        //group.Clear();
            //////        term = Literal.Zero;

            //////        time = Environment.TickCount; times[4] += time - lasttime; lasttime = time;
            //////        for (n2 = 0; n2 < c; n2++)
            //////        {
            //////            time = Environment.TickCount; times[5] += time - lasttime; lasttime = time;
            //////            for (k2 = 0; k2 < ColumnCount; k2++)
            //////            {
            //////                time = Environment.TickCount; times[6] += time - lasttime; lasttime = time;
            //////                if (n2 - k2 < 0) { break; }
            //////                if (n2 - k2 >= convolvee.ColumnCount) { continue; }

            //////                time = Environment.TickCount; times[7] += time - lasttime; lasttime = time;

            //////                float expr = new FunctionCall(
            //////                    Value1Op,
            //////                    this[k1, k2],
            //////                    convolvee[n1 - k1, n2 - k2]);
            //////            time = Environment.TickCount; times[11] += time - lasttime; lasttime = time;
            //////                expr = expr.CleanUp();
            //////            time = Environment.TickCount; times[10] += time - lasttime; lasttime = time;
            //////                expr = new FunctionCall(
            //////                    Value2Op,
            //////                    term,
            //////                    expr);

            //////                //group.Add(
            //////                //    (expr));

            //////            time = Environment.TickCount; times[9] += time - lasttime; lasttime = time;
            //////                term = expr.CleanUp();
            //////                time = Environment.TickCount; times[8] += time - lasttime; lasttime = time;
            //////            }

            //////            float[] terms = group.ToArray();
            //////            FunctionCall fc = new FunctionCall(Value2Op, terms);
            //////            ret[n1, n2] = term;// fc.CleanUp();
            //////            time = Environment.TickCount; times[12] += time - lasttime; lasttime = time;
            //////        }
            //////        time = Environment.TickCount; times[13] += time - lasttime; lasttime = time;
            //////    }
            //////    time = Environment.TickCount; times[14] += time - lasttime; lasttime = time;
            //////}
            //////time = Environment.TickCount; times[15] += time - lasttime; lasttime = time;

            //////for (i = 0; i < r; i++)
            //////{
            //////    for (j = 0; j < c; j++)
            //////    {
            //////        iiend = Math.Min(i, convolvee.RowCount);
            //////        jjend = Math.Min(j, convolvee.ColumnCount);
            //////
            //////        group.Clear();
            //////        term = this[i - convolvee.RowCount + 1, j - convolvee.ColumnCount + 1];
            //////
            //////        for (ii = Math.Max(0, i - r); ii < iiend; ii++)
            //////        {
            //////            for (jj = Math.Min(0, j - c); jj < jjend; jj++)
            //////            {
            //////                group.Add(
            //////                    new FunctionCall(
            //////                    Value1Op,
            //////                    term,
            //////                    convolvee[ii, jj]));
            //////            }
            //////        }
            //////
            //////        ret[i, j] = _engine.CleanUp(new FunctionCall(Value2Op, group.ToArray()));
            //////    }
            //////}

            return(ret);
        }