Beispiel #1
0
        public override void compressFile(NormaliseText norm)
        {
            List <int> indices = new List <int>();

            bool[] indexarray = new bool[norm._map.Count];
            for (int t = 0; t < indexarray.Length; t++)
            {
                indexarray[t] = false;
            }

            for (int i = 0; i < norm._inputData.Length; i++)
            {
                double[] tmpInput  = new double[1];
                double[] tmpOutput = new double[1];

                tmpInput[0] = norm._inputData[i];
                bpnetwork.run(ref tmpInput, out tmpOutput);

                double checkVal = Math.Round(tmpOutput[0], 2);

                int check = 0;
                foreach (KeyValuePair <string, double> kv in norm._map)
                {
                    if ((kv.Value - checkVal >= -0.03) && (kv.Value - checkVal <= 0.03))
                    {
                        indexarray[check] = true;
                    }
                    check++;
                }
            }
            for (int b = 0; b < indexarray.Length; b++)
            {
                if (indexarray[b])
                {
                    double val  = norm._map[b].Value;
                    string word = norm._map[b].Key;
                    string var  = RandomString(2);
                    while (ranVariable.Contains(var))
                    {
                        var = RandomString(2);
                    }
                    legendlist.Add(new KeyValuePair <string, string>(word, var));
                    norm._map[b] = new KeyValuePair <string, double>(var, val);
                    ranVariable.Add(var);
                }
            }
            foreach (KeyValuePair <string, double> kv in norm._map)
            {
                for (int j = 0; j < norm._worddata.Length; j++)
                {
                    if (norm._inputData[j] == kv.Value)
                    {
                        norm._worddata[j] = kv.Key;
                    }
                }
            }
            foreach (KeyValuePair <string, string> lgd in legendlist)
            {
                legend += lgd.ToString() + "\n";
            }
            for (int k = 0; k < norm._worddata.Length; k++)
            {
                compressedString += norm._worddata[k];
                compressedString += " ";
            }

            compressedString += "\n" + "\n";
            compressedString += legend;
        }
        public override void compressFile(NormaliseImage norm)
        {
            double[]             tmpInput  = new double[8];
            double[]             tmpOutput = new double[8];
            List <CImage.posCol> pcList    = new List <CImage.posCol>();

            ci = new CImage(norm._image.Width, norm._image.Height);
            bool checkloopdone;

            for (int y = 0; y < norm._image.Height; y++)
            {
                checkloopdone = true;
                int           num = 1;
                CImage.posCol pc  = new CImage.posCol();
                for (int x = 0; x < norm._image.Width; x++)
                {
                    foreach (KeyValuePair <double, double[]> kv in norm._DataList)
                    {
                        if (kv.Key == norm._numArray[x, y])
                        {
                            tmpInput = kv.Value;
                            break;
                        }
                    }
                    bpnetwork.run(ref tmpInput, out tmpOutput);
                    for (int i = 0; i < 8; i++)
                    {
                        tmpOutput[i] = Math.Round(tmpOutput[i]);
                    }
                    double checkVal = 0;
                    foreach (KeyValuePair <double, double[]> kvk in norm._DataList)
                    {
                        if (tmpOutput.SequenceEqual(kvk.Value))
                        {
                            checkVal = kvk.Key;
                            break;
                        }
                    }
                    bool  one = false;
                    Color col = new Color();
                    foreach (KeyValuePair <Color, double> kv in norm._ColourList)
                    {
                        if (kv.Value == checkVal)
                        {
                            one = true;
                            col = kv.Key;
                            num++;
                            break;
                        }
                    }
                    if (checkloopdone)
                    {
                        if (one)
                        {
                            pc.x   = x;
                            pc.y   = y;
                            pc.col = col;
                            pc.num = num;
                        }
                    }
                    else if (one)
                    {
                        pc.num = num;
                    }
                    if (!one)
                    {
                        foreach (KeyValuePair <Color, double> kv in norm._ColourList)
                        {
                            if (kv.Value == tmpInput[0])
                            {
                                pc.col = kv.Key;
                                break;
                            }
                        }
                        pc.x   = x;
                        pc.y   = y;
                        pc.num = 1;
                        pcList.Add(pc);
                    }
                    one           = false;
                    checkloopdone = false;
                }
                pcList.Add(pc);
            }
            ci._PosList = pcList.ToArray();
        }