private string BinarizeImage(string sourcepath, int imageWidth, int imageHeight, string destinationPath, string name)
        {
            string binaryImage;

            Binarizer imageBinarizer = new Binarizer(200, 200, 200, imageWidth, imageHeight);

            //binaryImage = $"{testName}.txt";
            if (!Directory.Exists(destinationPath))
            {
                Directory.CreateDirectory(destinationPath);
            }
            string _destinationPath = Path.Combine(destinationPath, $"{name}.jpg");
            string _sourcePath      = Path.Combine(sourcepath, $"{name}.jpg");

            if (File.Exists(_destinationPath))
            {
                File.Delete(_destinationPath);
            }

            imageBinarizer.CreateBinary(_sourcePath, _destinationPath);
            binaryImage = imageBinarizer.GetBinary(_sourcePath);
            // Console.WriteLine(binaryImage);
            //int[] vector =
            return(_destinationPath);
        }
Esempio n. 2
0
        /// <summary>
        /// Returns Binarized Image in integer array and creates file of Binarized Image
        /// </summary>
        /// <param name="imageName">Name of Image to be binarized</param>
        /// <param name="height">Height of Binarized Image</param>
        /// <param name="width">Width of Binarized Image</param>
        /// <returns></returns>
        public int[] ReadImageData(String imageName, int height, int width)
        {
            Binarizer bizer = new Binarizer(targetHeight: height, targetWidth: width);

            var imgName = Path.Combine(Path.Combine(AppContext.BaseDirectory, "Images"), imageName);

            bizer.CreateBinary(imgName, Path.Combine(Path.Combine(AppContext.BaseDirectory, "Output"), $"bin-{imageName}.txt"));

            var binaryString = bizer.GetBinary(imgName);

            int[] intArray = new int[height * width];
            int   j        = 0;

            for (int i = 0; i < binaryString.Length; i++)
            {
                if (binaryString[i].Equals('0'))
                {
                    intArray[j] = 0;
                    j++;
                }
                else if (binaryString[i].Equals('1'))
                {
                    intArray[j] = 1;
                    j++;
                }
            }
            return(intArray);
        }
        public void BinarizeImageTest(String sourcePath, String destinationPath)
        {
            Binarizer imageBinarizer = new Binarizer(200, 200, 200, 32, 32);

            imageBinarizer.CreateBinary(sourcePath, destinationPath);

            string res = imageBinarizer.GetBinary(sourcePath);
        }
        // Read image and convert to binary format
        private string readImageData(string imageName, int width, int height)
        {
            //string trainingImagesPath = Path.Combine(Path.Combine(AppContext.BaseDirectory, "RestrictedBolzmannMachine"), "TrainingImages");
            Binarizer bizer = new Binarizer(targetHeight: height, targetWidth: width);

            //return bizer.GetBinary(Path.Combine(trainingImagesPath, imageName));
            return(bizer.GetBinary(imageName));
        }
        private string readImageData(string imageName, int width, int height)
        {
            Binarizer bizer = new Binarizer(targetHeight: height, targetWidth: width);

            return(bizer.GetBinary(imageName));
        }