示例#1
0
        public Bitmap preProcess(Bitmap image)
        {
            //The input image will be applied with preprocessing(grayscale, threshold, and reduce noise)

            image = Grayscale.CommonAlgorithms.RMY.Apply(image);

            image = new Threshold(127).Apply(image);
            int xStart = image.Width, yStart = image.Height, xEnd = 0, yEnd = 0;

            for (int i = 0; i < image.Height; i++)
            {
                for (int j = 0; j < image.Width; j++)
                {
                    if (image.GetPixel(j, i).R > 127)
                    {
                        if (xStart > j)
                        {
                            xStart = j;
                        }
                        if (yStart > i)
                        {
                            yStart = i;
                        }
                        if (xEnd < j)
                        {
                            xEnd = j;
                        }
                        if (yEnd < i)
                        {
                            yEnd = i;
                        }
                    }
                }
            }

            image = image.Clone(new Rectangle(xStart, yStart, xEnd - xStart, yEnd - yStart), System.Drawing.Imaging.PixelFormat.Format24bppRgb);
            //and will be resized it to 10x10 pixels
            image = new ResizeBilinear(10, 10).Apply(image);

            return(image);
            //  Total input neurons in neural network must be 100 neurons
        }