Exemplo n.º 1
0
        public void Execute(object parameter)
        {
            var b = parameter as ViewModel;

            if (b.ImageSource == null)
            {
                return;
            }
            var    myBitmapImage = b.ImageSource as BitmapImage;
            Bitmap bmp           = BitmapConverter.BitmapImage2Bitmap(myBitmapImage);


            var p = Mouse.GetPosition(Picture.PICTURE);


            p.X /= Picture.PICTURE.ActualWidth / b.ImageSource.Width;
            p.Y /= Picture.PICTURE.ActualHeight / b.ImageSource.Height;
            if (p.X < b.Skin.Width && p.X > 0 && p.Y < b.Skin.Height && p.Y > 0)
            {
                var col = new Color();
                col = Color.FromArgb(b.BrushColorPick.A, b.BrushColorPick.R, b.BrushColorPick.G, b.BrushColorPick.B);
                bmp.SetPixel((int)p.X, (int)p.Y, col);
                b.Skin        = bmp;
                b.ImageSource = BitmapConverter.BitmapToImageSource(bmp);
            }
        }
Exemplo n.º 2
0
        private void NoiseButton_Click(object sender, RoutedEventArgs e)
        {
            if (!int.TryParse(NoiseValueTextBox.Text, out _noiseValue))
            {
                MessageBox.Show("Bad noise value!");
                return;
            }
            Bitmap bitmap         = BitmapConverter.BitmapImage2Bitmap(_sourceImage);
            var    random         = new Random();
            var    pointsHashSet  = new HashSet <Point>();
            int    pixelsToInvert = _pixelsNumber * _noiseValue / 100;

            for (int i = 0; i < pixelsToInvert; i++)
            {
                bool wasInverted = false;
                while (!wasInverted)
                {
                    Point point;
                    point.X = random.Next(0, _width);
                    point.Y = random.Next(0, _height);
                    if (pointsHashSet.Add(point))
                    {
                        Color curColor = bitmap.GetPixel(point.X, point.Y);
                        bitmap.SetPixel(point.X, point.Y, curColor.R > 230 ? Color.Black : Color.White);
                        wasInverted = true;
                    }
                }
            }
            _noisedImage       = BitmapConverter.Bitmap2BitmapImage(bitmap);
            SourceImage.Source = _noisedImage;
        }
Exemplo n.º 3
0
        private void AddImageMenuItem_Click(object sender, RoutedEventArgs e)
        {
            var openFileDialog = new OpenFileDialog
            {
                InitialDirectory = @"C:\Users\Dmitry\Pictures",
                FilterIndex      = 2,
                RestoreDirectory = true
            };

            if (openFileDialog.ShowDialog() != null)
            {
                try
                {
                    var image = new BitmapImage(new Uri(openFileDialog.FileName));
                    if (_height == 0)
                    {
                        _height       = image.PixelHeight;
                        _width        = image.PixelWidth;
                        _pixelsNumber = _width * _height;
                    }
                    _standardImages.Add(image);
                    _standardImageVectors.Add(GetImageVector(BitmapConverter.BitmapImage2Bitmap(image)));
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                }
            }
        }
Exemplo n.º 4
0
        private void RecognizeButton_Click(object sender, RoutedEventArgs e)
        {
            _knowledgeMatrix = new int[_pixelsNumber, _pixelsNumber];
            foreach (var stdVector in _standardImageVectors)
            {
                for (int i = 0; i < _pixelsNumber; i++)
                {
                    for (int j = 0; j < _pixelsNumber; j++)
                    {
                        _knowledgeMatrix[j, i] += (i == j) ? 0 : stdVector[j] * stdVector[i];
                    }
                }
            }

            Bitmap sourceBitmap = BitmapConverter.BitmapImage2Bitmap(_noisedImage);

            int[] sourceImageVector = GetImageVector(sourceBitmap);
            int   counter           = 0;

            int[] temp = new int[_pixelsNumber];
            while (true)
            {
                temp = Copy(sourceImageVector);
                sourceImageVector = MultiplyMatrixAndColumn(_knowledgeMatrix, sourceImageVector);
                counter++;
                if (IsEqual(temp, sourceImageVector))
                {
                    ResultImage.Source = BitmapConverter.Bitmap2BitmapImage(GetImageFromVector(sourceImageVector));
                    MessageBox.Show("Iterations" + counter.ToString());
                    return;
                }
            }
        }
Exemplo n.º 5
0
        private void Window_Loaded_1(object sender, RoutedEventArgs e)
        {
            const string baseUri = @"C:\Users\Dmitry\Pictures\DPSI\";

            _knowledgeImages[0] = new BitmapImage(new Uri(string.Format("{0}{1}.png", baseUri, "A")));

            _width        = _knowledgeImages[0].PixelWidth;
            _height       = _knowledgeImages[0].PixelHeight;
            _pixelsNumber = _width * _height;

            _knowledgeImages[1] = new BitmapImage(new Uri(string.Format("{0}{1}.png", baseUri, "C")));
            _knowledgeImages[2] = new BitmapImage(new Uri(string.Format("{0}{1}.png", baseUri, "K")));
            _knowledgeImages[3] = new BitmapImage(new Uri(string.Format("{0}{1}.png", baseUri, "A2")));
            _knowledgeImages[4] = new BitmapImage(new Uri(string.Format("{0}{1}.png", baseUri, "C2")));
            _knowledgeImages[5] = new BitmapImage(new Uri(string.Format("{0}{1}.png", baseUri, "K2")));
            _knowledgeImages[6] = new BitmapImage(new Uri(string.Format("{0}{1}.png", baseUri, "A3")));
            _knowledgeImages[7] = new BitmapImage(new Uri(string.Format("{0}{1}.png", baseUri, "C3")));
            _knowledgeImages[8] = new BitmapImage(new Uri(string.Format("{0}{1}.png", baseUri, "K3")));

            for (int i = 0; i < NumberOfImages; i++)
            {
                _knowledgeMatrix[i] = GetImageVector(BitmapConverter.BitmapImage2Bitmap(_knowledgeImages[i]));
            }

            W = new double[_pixelsNumber, NumberOfClasses];
            for (int i = 0; i < _pixelsNumber; i++)
            {
                for (int j = 0; j < NumberOfClasses; j++)
                {
                    W[i, j] = 1;
                }
            }

            InitFrequency();

            Y = new double[NumberOfClasses];

            StartLearning();

            var learningResults = new List <LearningResult>();

            for (int i = 0; i < _knowledgeImages.Length; i++)
            {
                learningResults.Add(new LearningResult
                {
                    Image        = _knowledgeImages[i],
                    ClassNumnber = RecognizeClass(_knowledgeImages[i])
                });
            }

            var learningResultsWindow = new LearningResultsWindow(learningResults);

            learningResultsWindow.Show();
        }
Exemplo n.º 6
0
        private void Render(IEnumerable<ClientMarker> mapLocations)
        {
            _mapBitmap?.Dispose();

            var worldMapBitmapImage =
                new BitmapImage(
                    new Uri(
                        "pack://application:,,,/Orcus.Administration.Resources;component/Images/world-map-black.jpg",
                        UriKind.Absolute));

            if (mapLocations == null)
            {
                CurrentMapImage = worldMapBitmapImage;
                _mapBitmap = BitmapConverter.BitmapImage2Bitmap(worldMapBitmapImage);
                return;
            }

            var worldMap = BitmapConverter.BitmapImage2Bitmap(worldMapBitmapImage);

            var offlineComputer =
                BitmapConverter.BitmapImage2Bitmap(
                    new BitmapImage(
                        new Uri(
                            "pack://application:,,,/Orcus.Administration;component/Resources/Images/OfflineComputer.png",
                            UriKind.Absolute)));
            var onlineComputer =
                BitmapConverter.BitmapImage2Bitmap(
                    new BitmapImage(
                        new Uri(
                            "pack://application:,,,/Orcus.Administration;component/Resources/Images/OnlineComputer.png",
                            UriKind.Absolute)));

            using (var g = Graphics.FromImage(worldMap))
            {
                foreach (var clientLocation in mapLocations.OrderBy(x => x.Client.IsOnline))
                {
                    if (!clientLocation.Client.IsOnline && !RenderOfflineClients)
                        continue;
                    g.DrawImage(clientLocation.Client.IsOnline ? onlineComputer : offlineComputer,
                        new RectangleF(
                            new PointF((float) worldMap.Width/(180*2)*(clientLocation.Longitude + 180) - 8,
                                worldMap.Height - (float) worldMap.Height/(90*2)*(clientLocation.Latitude + 90) - 8),
                            new SizeF(16, 16)));
                }
            }

            offlineComputer.Dispose();
            onlineComputer.Dispose();

            CurrentMapImage = BitmapConverter.ToBitmapSource(worldMap);
            _mapBitmap = worldMap;
        }
Exemplo n.º 7
0
        private void Window_Loaded_1(object sender, RoutedEventArgs e)
        {
            const string baseUri = @"C:\Users\Dmitry\Pictures\DPSI\";

            _knowledgeImages[0] = new BitmapImage(new Uri(string.Format("{0}{1}.png", baseUri, "A")));
            Image1.Source       = _knowledgeImages[0];

            _width        = _knowledgeImages[0].PixelWidth;
            _height       = _knowledgeImages[0].PixelHeight;
            _pixelsNumber = _width * _height;

            _knowledgeImages[1] = new BitmapImage(new Uri(string.Format("{0}{1}.png", baseUri, "A2")));
            Image2.Source       = _knowledgeImages[1];
            _knowledgeImages[2] = new BitmapImage(new Uri(string.Format("{0}{1}.png", baseUri, "A3")));
            Image3.Source       = _knowledgeImages[2];
            _knowledgeImages[3] = new BitmapImage(new Uri(string.Format("{0}{1}.png", baseUri, "C")));
            Image4.Source       = _knowledgeImages[3];
            _knowledgeImages[4] = new BitmapImage(new Uri(string.Format("{0}{1}.png", baseUri, "C2")));
            Image5.Source       = _knowledgeImages[4];
            _knowledgeImages[5] = new BitmapImage(new Uri(string.Format("{0}{1}.png", baseUri, "C3")));
            Image6.Source       = _knowledgeImages[5];
            _knowledgeImages[6] = new BitmapImage(new Uri(string.Format("{0}{1}.png", baseUri, "K")));
            Image7.Source       = _knowledgeImages[6];
            _knowledgeImages[7] = new BitmapImage(new Uri(string.Format("{0}{1}.png", baseUri, "K2")));
            Image8.Source       = _knowledgeImages[7];
            _knowledgeImages[8] = new BitmapImage(new Uri(string.Format("{0}{1}.png", baseUri, "K3")));
            Image9.Source       = _knowledgeImages[8];

            for (int i = 0; i < NumberOfImages; i++)
            {
                _knowledgeMatrix[i] = GetImageVector(BitmapConverter.BitmapImage2Bitmap(_knowledgeImages[i]));
            }

            var random = new Random();

            G = new double[NumberOfClasses];

            W = new double[NumberOfClasses, NumberOfClasses];
            for (int i = 0; i < NumberOfClasses; i++)
            {
                for (int j = 0; j < NumberOfClasses; j++)
                {
                    W[i, j] = 1 - 2 * random.NextDouble();
                }
            }

            Y = new double[NumberOfClasses];

            CalculateClustersCenters();
            StartLearning();
        }
Exemplo n.º 8
0
        private int RecognizeClass(BitmapImage image)
        {
            X = GetImageVector(BitmapConverter.BitmapImage2Bitmap(image));

            CalculateY();

            for (int i = 0; i < Y.Length; i++)
            {
                if (Y[i] == Y.Max())
                {
                    return(i + 1);
                }
            }

            return(0);
        }
Exemplo n.º 9
0
        private void RecognizeButton_Click(object sender, RoutedEventArgs e)
        {
            X = GetImageVector(BitmapConverter.BitmapImage2Bitmap(_noisedImage));
            CalculateG();
            CalculateY();
            Result1.Content = Y[0];
            Result4.Content = Y[1];
            Result7.Content = Y[2];

            for (int i = 0; i < Y.Length; i++)
            {
                if (Y[i] == Y.Max())
                {
                    MessageBox.Show("Class: " + (i + 1).ToString());
                }
            }
        }
Exemplo n.º 10
0
        private void BtnProccess_OnClick(object sender, RoutedEventArgs e)
        {
            int limit = 1;
            IDetectingAlgorithm algrorithm = (IDetectingAlgorithm)SelectedAlgorithm.SelectedItem;

            if (Limit.Text != "" && Int32.TryParse(Limit.Text, out limit) && algrorithm != null && this._source != null)
            {
                Bitmap      bitmap     = BitmapConverter.BitmapImage2Bitmap(this._source);
                Bitmap      edges      = algrorithm.DetecteEdges(bitmap, limit);
                BitmapImage imageEdges = BitmapConverter.Bitmap2ImageSource(edges);
                FilteredImage.Source = imageEdges;
            }
            else
            {
                MessageBox.Show(
                    "Please input a limit for filtering. \nYou may not select file. \nYou have to select algorithm for filtering");
            }
        }