Exemplo n.º 1
0
        //tabcontrol indexChange
        private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
        {
            TabControl page = sender as TabControl;
            switch (page.SelectedIndex)
            {
                case 1:
                    #region Transfer to grayscale
                    imageConverter.Progress += ImageConverter_Progress;
                    if (originalImage != null)
                    {
                        grayBitmap = imageConverter.TransferToGrayscaleGetBitmap(originalImage);
                        GrayScalePictureBox.Image = grayBitmap;
                    }
                    else
                    {
                        grayBitmap = OpenImage();
                        GrayScalePictureBox.Image = grayBitmap;
                    }

                    break;
                #endregion
                case 2:
                    #region Binarization image
                    ThresholdValue();
                    if (grayBitmap != null)
                    {
                        imageConverter.Progress += ImageConverter_Progress;
                        Bitmap binarizationImage = imageConverter.BinarizationThresholdMethodGetBitmap(grayBitmap);
                        binary = binarizationImage;
                        //rotate image
                        Bitmap afterRotete = rotateBitmapImage.RotateBitmap(binary, GetAngleRotate());
                        binary = afterRotete;
                        BinarizationPictureBox.Image = binary;
                        var resultGisto = transformation.Parameters(imageConverter.BinarizationThresholdMethodGetArray(binary));
                        mainList = resultGisto;

                    }
                    else if (binary == null)
                    {
                        binary = OpenImage();
                        //rotate image
                        Bitmap afterRotete = rotateBitmapImage.RotateBitmap(binary, GetAngleRotate());
                        BinarizationPictureBox.Image = afterRotete;
                        binary = afterRotete;
                        var resultGisto = transformation.Parameters(imageConverter.BinarizationThresholdMethodGetArray(afterRotete));
                        mainList = resultGisto;
                    }
                    break;
                #endregion
                case 3:
                    #region Segmentation
                    imageConverter.Progress += ImageConverter_Progress;
                    var arrayImage = imageConverter.BinarizationThresholdMethodGetArray(binary);
                    Segmentation segment = new Segmentation(arrayImage, mainList);
                    // remove up and down element image and
                    Bitmap UpDownRemove = imageConverter.CreateBitmap(segment.RemoveUpAndDownElementImage(mainList, arrayImage));
                    //removing unnecessary lines segment.SelectionOfAreas()
                    var segmentImageInfo = imageConverter.CreateBitmap(segment.SelectionOfAreas());
                    //get array new small image
                    var arrayNewImage = imageConverter.BinarizationThresholdMethodGetArray(segmentImageInfo);
                    //get list params histogramm
                    var paramsForHistogrammNewImage = transformation.HorizontalImageGetParameters(arrayNewImage);
                    var miniArray = segment.SelectionOfAreasInHorizontalImage(paramsForHistogrammNewImage, arrayNewImage);
                    miniArray = segment.RemoveBorder(miniArray);
                    var finishImageRecognition = imageConverter.CreateBitmap(miniArray);
                    SegmentationPictureBox.Image = finishImageRecognition;
                    //var afterBin = imageConverter.BinarizationThresholdMethodGetArray(seg);
                    //var Gisto2 = trans.HorizontalImageGetParameters(afterBin);
                    DividedImage = miniArray;
                    //get params miniImage fo segmentations numbers
                    DividedImageList = transformation.HorizontalImageGetParameters(miniArray);
                    ImageRecognitionPictureBox1.Image = finishImageRecognition;
                    DividedIntoImageButton.Enabled = true;
                    binary = null;
                    grayBitmap = null;
                    numberImageCollection.Clear();
                    #endregion
                    break;
            }
        }
Exemplo n.º 2
0
 //save collection image
 private void DividedIntoImageButton_Click(object sender, EventArgs e)
 {
     ObjectSerializer<Perceptron> objSerializer = new ObjectSerializer<Perceptron>();
     Perceptron yourObjectFromFile = objSerializer.GetSerializedObject(PathObjectSerializer);
     if (yourObjectFromFile != null)
     {
         per = yourObjectFromFile;
     }
     else
     {
         MessageBox.Show("Perceptron not trained");
     }
     Segmentation segment = new Segmentation(null, null);
     numberImageCollection = segment.GetCollectionofImage(DividedImageList, DividedImage);
     ImageFormat format = ImageFormat.Bmp;
     SaveFileDialog saveFileDialog = new SaveFileDialog();
     if (saveFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
     {
         int x = 0;
         DividedimageList1.ImageSize = new Size(50, 50);
         foreach (var item in numberImageCollection)
         {
             item.bitmap.Save(saveFileDialog.FileName + item.Name + ".bmp", format);
             DividedimageList1.Images.Add(Image.FromFile(saveFileDialog.FileName + item.Name + ".bmp"));
             DividedListView.Items.Add("image", x++);
         }
         DividedListView.LargeImageList = DividedimageList1;
     }
 }