Exemplo n.º 1
0
        //--------------------------------------------------------------------------------------
        /// <summary>
        /// разбиение рисунка на части - по одной для каждого цвета
        /// </summary>
        /// <param name="pPicture">входной рисунок для разбиения</param>
        /// <returns>выходной список рисунков - в каждом только один цвет</returns>
        public Dictionary <Color, Bitmap> SplitImageByColor(Bitmap pPicture)
        {
            Dictionary <Color, Bitmap> lOutList = new Dictionary <Color, Bitmap>();

            for (int i = 0; i < pPicture.Width; i++)
            {
                for (int j = 0; j < pPicture.Height; j++)
                {
                    Color lColor = pPicture.GetPixel(i, j);
                    if (!lOutList.ContainsKey(lColor))
                    {
                        Color  lBackColor  = CImageSplitter.DefineBestBackColor(lColor);
                        Bitmap lNewPicture = new Bitmap(pPicture.Width, pPicture.Height);
                        lOutList.Add(lColor, lNewPicture);
                        for (int l = 0; l < lNewPicture.Width; l++)
                        {
                            for (int k = 0; k < lNewPicture.Height; k++)
                            {
                                lNewPicture.SetPixel(l, k, lBackColor);
                            }
                        }
                    }
                    lOutList[lColor].SetPixel(i, j, lColor);
                }
            }
            return(lOutList);
        }
Exemplo n.º 2
0
 //--------------------------------------------------------------------------------------
 private void tsbColorSplit_Click(object sender, EventArgs e)
 {
     try
     {
         byte           lWhat          = (byte)cbClearColor.SelectedIndex;
         CImageSplitter lImageSplitter = new CImageSplitter();
         if (pbAfterClean_RL.Image != null)
         {
             Bitmap lNewBmp = CBlackWhiteExplorer.BWImageToColorImage(pbAfterClean_RL.Image as Bitmap, lWhat);
             pbAfterCleanColor.Image = lNewBmp;
         }
         if (pbAfterCleanExact_RL.Image != null)
         {
             Bitmap lNewBmp = CBlackWhiteExplorer.BWImageToColorImage(pbAfterCleanExact_RL.Image as Bitmap, lWhat);
             pbAfterCleanExactColor.Image = lNewBmp;
         }
         if (pbAfterCleanExactDefault_RL.Image != null)
         {
             Bitmap lNewBmp = CBlackWhiteExplorer.BWImageToColorImage(pbAfterCleanExactDefault_RL.Image as Bitmap, lWhat);
             pbAfterCleanExactDefaultColor.Image = lNewBmp;
         }
     }
     catch (Exception ee)
     {
         MessageBox.Show(ee.ToString());
     }
 }
Exemplo n.º 3
0
 //--------------------------------------------------------------------------------------
 private void tsbRemoveSmall_Click(object sender, EventArgs e)
 {
     try
     {
         CImageSplitter lImageSplitter = new CImageSplitter();
         if (pbAfterClean.Image != null)
         {
             fMatrixAfterClean = lImageSplitter.RemoveSmallRegion(pbAfterClean.Image as Bitmap, (byte)cbClearColor.SelectedIndex, int.Parse(txtThreshold.Text));
             Bitmap lNewBmp = CBlackWhiteExplorer.BinaryMatrixToBitmap(fMatrixAfterClean);
             pbAfterClean_RL.Image = lNewBmp;
         }
         if (pbAfterCleanExact.Image != null)
         {
             fMatrixAfterClean = lImageSplitter.RemoveSmallRegion(pbAfterCleanExact.Image as Bitmap, (byte)cbClearColor.SelectedIndex, int.Parse(txtThreshold.Text));
             Bitmap lNewBmp = CBlackWhiteExplorer.BinaryMatrixToBitmap(fMatrixAfterClean);
             pbAfterCleanExact_RL.Image = lNewBmp;
         }
         if (pbAfterCleanExactDefault.Image != null)
         {
             fMatrixAfterClean = lImageSplitter.RemoveSmallRegion(pbAfterCleanExactDefault.Image as Bitmap, (byte)cbClearColor.SelectedIndex, int.Parse(txtThreshold.Text));
             Bitmap lNewBmp = CBlackWhiteExplorer.BinaryMatrixToBitmap(fMatrixAfterClean);
             pbAfterCleanExactDefault_RL.Image = lNewBmp;
         }
     }
     catch (Exception ee)
     {
         MessageBox.Show(ee.ToString());
     }
 }
Exemplo n.º 4
0
        //--------------------------------------------------------------------------------------
        public FBordersByColorForImage(Image pImage)
        {
            InitializeComponent();

            fSourceBitmap = pImage as Bitmap;
            if (fSourceBitmap != null)
            {
                pbSourceImage.Image = fSourceBitmap;
            }

            fBlackWhiteExplorer = new CBlackWhiteExplorer();

            Color[] lFinalColors = CBlackWhiteExplorer.DefineExactNeedColor(8);
            fColorsOfVariant = new Color[8];
            fTextOfColors    = new string[8];
            for (int i = 0; i < 6; i++)
            {
                fColorsOfVariant[i + 1] = lFinalColors[i];
            }
            fColorsOfVariant[0] = Color.FromArgb(255, 0, 0, 0);
            fColorsOfVariant[7] = Color.FromArgb(255, 255, 255, 255);
            for (int i = 0; i < fTextOfColors.Length; i++)
            {
                fTextOfColors[i] = fColorsOfVariant[i].R.ToString() + ":" +
                                   fColorsOfVariant[i].G.ToString() + ":" + fColorsOfVariant[i].B.ToString();
            }
            l000.Text              += "   (" + fTextOfColors[0] + ")";
            l001.Text              += "   (" + fTextOfColors[1] + ")";
            l010.Text              += "   (" + fTextOfColors[2] + ")";
            l011.Text              += "   (" + fTextOfColors[3] + ")";
            l100.Text              += "   (" + fTextOfColors[4] + ")";
            l101.Text              += "   (" + fTextOfColors[5] + ")";
            l110.Text              += "   (" + fTextOfColors[6] + ")";
            l111.Text              += "   (" + fTextOfColors[7] + ")";
            l000.BackColor          = fColorsOfVariant[0];
            l001.BackColor          = fColorsOfVariant[1];
            l010.BackColor          = fColorsOfVariant[2];
            l011.BackColor          = fColorsOfVariant[3];
            l100.BackColor          = fColorsOfVariant[4];
            l101.BackColor          = fColorsOfVariant[5];
            l110.BackColor          = fColorsOfVariant[6];
            l111.BackColor          = fColorsOfVariant[7];
            l000.ForeColor          = CImageSplitter.DefineBestBackColor(fColorsOfVariant[0]);
            l001.ForeColor          = CImageSplitter.DefineBestBackColor(fColorsOfVariant[1]);
            l010.ForeColor          = CImageSplitter.DefineBestBackColor(fColorsOfVariant[2]);
            l011.ForeColor          = CImageSplitter.DefineBestBackColor(fColorsOfVariant[3]);
            l100.ForeColor          = CImageSplitter.DefineBestBackColor(fColorsOfVariant[4]);
            l101.ForeColor          = CImageSplitter.DefineBestBackColor(fColorsOfVariant[5]);
            l110.ForeColor          = CImageSplitter.DefineBestBackColor(fColorsOfVariant[6]);
            l111.ForeColor          = CImageSplitter.DefineBestBackColor(fColorsOfVariant[7]);
            fBordersByColorForImage = new CBordersByColorForImage(fSourceBitmap);
        }
Exemplo n.º 5
0
 //--------------------------------------------------------------------------------------
 private void PrepareLookSeparatePartForPicture(Bitmap pPictureForLook)
 {
     try
     {
         CImageSplitter             lImageSplitter = new CImageSplitter();
         FLookSeparatePart          form           = new FLookSeparatePart();
         Dictionary <Color, Bitmap> lDictPicture   = lImageSplitter.SplitImageByColor(pPictureForLook);
         List <Bitmap> lImages = new List <Bitmap>();
         List <Color>  lColors = new List <Color>();
         form.PictureList    = lImages;
         form.ColorList      = lColors;
         form.PictureForLook = pPictureForLook;
         int lNumber = 0;
         foreach (Color lWhat in lDictPicture.Keys)
         {
             Bitmap lBitmap = lDictPicture[lWhat];
             lImages.Add(lBitmap);
             lColors.Add(lWhat);
             int lQuantity    = 0;
             int lQuantityAll = 0;
             int lCentreX     = 0;
             int lCentreY     = 0;
             for (int n = 0; n < lBitmap.Width; n++)
             {
                 lQuantityAll += lBitmap.Height;
                 for (int m = 0; m < lBitmap.Height; m++)
                 {
                     if (lBitmap.GetPixel(n, m) == lWhat)
                     {
                         lQuantity++;
                         lCentreX += n;
                         lCentreY += m;
                     }
                 }
             }
             lCentreX /= lQuantity;
             lCentreY /= lQuantity;
             form.imageListDataSet1.Images.AddImagesRow(lNumber++, lQuantity,
                                                        lCentreX, lCentreY, "R:" + lWhat.R.ToString("G") +
                                                        "G:" + lWhat.G.ToString("G") +
                                                        "B:" + lWhat.B.ToString("G"),
                                                        lWhat.R + lWhat.G + lWhat.B);
         }
         form.Show();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }
Exemplo n.º 6
0
        //--------------------------------------------------------------------------------------
        private Bitmap CommonSplit(Bitmap pInBitmap)
        {
            byte              lWhat          = (byte)cbClearColor.SelectedIndex;
            CImageSplitter    lImageSplitter = new CImageSplitter();
            FLookSeparatePart form           = new FLookSeparatePart();
            List <byte[][]>   lMatrixList    = lImageSplitter.SplitByMatrix(pInBitmap, lWhat);
            List <Bitmap>     lImages        = CBlackWhiteExplorer.BinaryMatrixListToBitmapList(lMatrixList);

            form.PictureList = lImages;
            for (int i = 0; i < lMatrixList.Count; i++)
            {
                int      lNumber      = i;
                int      lQuantity    = 0;
                int      lQuantityAll = 0;
                int      lCentreX     = 0;
                int      lCentreY     = 0;
                byte[][] lMatrix      = lMatrixList[i];
                for (int n = 0; n < lMatrix.Length; n++)
                {
                    lQuantityAll += lMatrix[n].Length;
                    for (int m = 0; m < lMatrix[n].Length; m++)
                    {
                        if (lMatrix[n][m] == lWhat)
                        {
                            lQuantity++;
                            lCentreX += n;
                            lCentreY += m;
                        }
                    }
                }
                lCentreX /= lQuantityAll;
                lCentreY /= lQuantityAll;
                form.imageListDataSet1.Images.AddImagesRow(lNumber, lQuantity,
                                                           lCentreX, lCentreY, "", 0);
            }
            form.Show();
            int[][] lColorMatrix = CBlackWhiteExplorer.BinaryMatrixListToColorMatrix(lMatrixList, lWhat);
            Bitmap  lColorImage  = CBlackWhiteExplorer.ColorMatrixToColorBitmap(lColorMatrix, lMatrixList.Count);

//            pbAfterCleanColor.Image = lColorImage;
            return(lColorImage);
        }