Пример #1
0
        public static void RecognizeImage()
        {
            var size              = 1000;
            var parasitizedPath   = @"Parasitized\";
            var unparasitizedPath = @"Uninfected\";

            var converter = new PictureConverter();
            var testParasitizedImageInput   = converter.Convert(@"Images\Parasitized.png");
            var testUnparasitizedImageInput = converter.Convert(@"Images\Uninfected.png");

            var topology      = new Topology(testParasitizedImageInput.Length, 1, 0.1, testParasitizedImageInput.Length / 2);
            var neuralNetwork = new NeuralNetwork(topology);

            double[,] parasitizedInputs = GetData(parasitizedPath, converter, testParasitizedImageInput, size);
            neuralNetwork.Learn(new double[] { 1 }, parasitizedInputs, 1);

            double[,] unparasitizedInputs = GetData(unparasitizedPath, converter, testUnparasitizedImageInput, size);
            neuralNetwork.Learn(new double[] { 0 }, unparasitizedInputs, 1);

            var par   = neuralNetwork.Predict(testParasitizedImageInput.Select(t => (double)t).ToArray());
            var unpar = neuralNetwork.Predict(testUnparasitizedImageInput.Select(t => (double)t).ToArray());

            Console.WriteLine(1 + Math.Round(par.Output, 2));
            Console.WriteLine(0 + Math.Round(unpar.Output, 2));
        }
Пример #2
0
        public static void ConverterPicture()
        {
            var converter = new PictureConverter();

            var inputs = converter.Convert(@"Images\Uninfected.png");

            converter.Save("f:\\image.png", inputs);
        }
Пример #3
0
        private static double[,] GetData(string parasitizedPath, PictureConverter converter, double[] testImageInput, int size)
        {
            var images = Directory.GetFiles(parasitizedPath);
            var result = new double[size, testImageInput.Length];

            for (int i = 0; i < size; i++)
            {
                var image = converter.Convert(images[i]);
                for (int j = 0; j < image.Length; j++)
                {
                    result[i, j] = image[j];
                }
            }

            return(result);
        }