Ejemplo n.º 1
0
        private void SendBtn_Click(object sender, EventArgs e)
        {
            //DrawPanel.Invalidate();
            Bitmap Scale = new Bitmap(DigitMap, new Size(DigitMap.Width / SCALE_RATIO, DigitMap.Height / SCALE_RATIO));

            byte[] Input = new byte[ImgWidth * ImgHeight];

            int i = 0;

            for (int x = 0; x < ImgWidth; x++)
            {
                for (int y = 0; y < ImgHeight; y++)
                {
                    byte Value = Scale.GetPixel(y, x).R;
                    Input[i] = (byte)(255 - Value);

                    i++;
                }
            }

            NN_Digit InputDigit = new NN_Digit();

            InputDigit.Image = Input;
            InputDigit.Label = 10;
            DisplayDigits    = new NN_Digit[] { InputDigit };

            DigitIndex = 0;

            Refresh();
        }
Ejemplo n.º 2
0
        public static void ShuffleArray(NN_Digit[] Digits)
        {
            Random Rand = new Random();

            for (int i = Digits.Length - 1; i > 0; i--)
            {
                int j = Rand.Next(i);

                NN_Digit temp = Digits[i];
                Digits[i] = Digits[j];
                Digits[j] = temp;
            }
        }
Ejemplo n.º 3
0
        private static NN_Digit[] LoadData()
        {
            NN_Digit[] Digits = null;

            OpenFileDialog OpenFile = new OpenFileDialog();

            if (OpenFile.ShowDialog() == DialogResult.OK)
            {
                FileStream Labels = (FileStream)OpenFile.OpenFile();

                //Reads in the header information for labels file
                byte[] bMagic  = new byte[4];
                byte[] bLength = new byte[4];

                Labels.Read(bMagic, 0, bMagic.Length);
                Labels.Read(bLength, 0, bLength.Length);

                Int32[] MagicNum  = new Int32[1];
                Int32[] NumDigits = new Int32[1];

                Buffer.BlockCopy(bMagic.Reverse().ToArray(), 0, MagicNum, 0, 4);
                Buffer.BlockCopy(bLength.Reverse().ToArray(), 0, NumDigits, 0, 4);

                //Initializes Digit Array
                Digits = new NN_Digit[NumDigits[0]];

                //Assigns the labels to each Digit
                for (int i = 0; i < NumDigits[0]; i++)
                {
                    Digits[i].Label = (byte)Labels.ReadByte();
                }

                Labels.Close();
            }

            //Maybe add null check for digits before reading image data

            if (OpenFile.ShowDialog() == DialogResult.OK)
            {
                FileStream Images = (FileStream)OpenFile.OpenFile();

                //Reads in header info for Images
                byte[] bMagic   = new byte[4];
                byte[] bLength  = new byte[4];
                byte[] bRows    = new byte[4];
                byte[] bColumns = new byte[4];

                Images.Read(bMagic, 0, bMagic.Length);
                Images.Read(bLength, 0, bLength.Length);
                Images.Read(bRows, 0, bRows.Length);
                Images.Read(bColumns, 0, bColumns.Length);

                Int32[] MagicNum  = new Int32[1];
                Int32[] NumDigits = new Int32[1];
                Int32[] Rows      = new Int32[1];
                Int32[] Columns   = new Int32[1];

                Buffer.BlockCopy(bMagic.Reverse().ToArray(), 0, MagicNum, 0, 4);
                Buffer.BlockCopy(bLength.Reverse().ToArray(), 0, NumDigits, 0, 4);
                Buffer.BlockCopy(bRows.Reverse().ToArray(), 0, Rows, 0, 4);
                Buffer.BlockCopy(bColumns.Reverse().ToArray(), 0, Columns, 0, 4);

                //Initializes dimensions of the images
                ImgWidth  = Columns[0];
                ImgHeight = Rows[0];

                int ImageSize = Rows[0] * Columns[0];

                //Assigns image to each Digit
                for (int i = 0; i < NumDigits[0]; i++)
                {
                    Digits[i].Image = new byte[ImageSize];
                    Images.Read(Digits[i].Image, 0, ImageSize);
                }

                Images.Close();
            }

            return(Digits);
        }