Advertisement
nex036ara

vezba4

Nov 14th, 2013
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.77 KB | None | 0 0
  1. Dictionary<Color, int> colorHistogram = new Dictionary<Color, int>();
  2.  
  3.                 /************/
  4.                 List<Color> elementi = new List<Color>();
  5.                 /************/
  6.  for (int y = yMin; y < yMax; y++){
  7. ........................................................
  8.  
  9.  
  10.  
  11.  
  12.  Color cc = Color.FromArgb(cbR, cbG, cbB);
  13.  
  14.                   /************/
  15.                         elementi.Add(cc);
  16.                   /************/       
  17.  
  18. if (colorHistogram.ContainsKey(cc)) {
  19. ...............................................
  20.  
  21.  
  22.  
  23. KMeans kmeans = new KMeans(); // inicijalizacija
  24.  
  25.                 /************/
  26.                 int brojGrupa = Convert.ToInt32(tbBrojGrupa.Text);
  27.                 kmeans.elementi = elementi;
  28.                 // TODO 1: inicijalizovati podatke koje ce K-means da klasterizuje i pokrenuti algoritam
  29.                 kmeans.podeliUGRupe(brojGrupa, 0.01);
  30.                 /************/
  31.  
  32.  
  33.  // iscrtavanje podataka
  34.      for (int i = 0; i < brojGrupa; i++)
  35.   {
  36. ..............................................
  37.  
  38.  
  39.  
  40.  for (int y = 0; y < h; y++)
  41.                 {
  42.                     for (int x = 0; x < w; x++)
  43.                     {
  44.                         byte cbR = slika[y, x, 0];
  45.                         byte cbG = slika[y, x, 1];
  46.                         byte cbB = slika[y, x, 2];
  47.                         Color cc = Color.FromArgb(255, cbR, cbG, cbB);
  48.                      
  49.                        
  50.                         /************/     
  51.                                  double minRastojanje = kmeans.grupe[0].rastojanje(cc);
  52.                                 int indexOfMin = 0;
  53.                                 for (int i = 0; i < kmeans.grupe.Count; i++)
  54.                                 {
  55.                                   if (kmeans.grupe[i].rastojanje(cc) < minRastojanje)
  56.                                   {
  57.                                         minRastojanje = kmeans.grupe[i].rastojanje(cc);
  58.                                         indexOfMin = i;
  59.                                   }
  60.                                  }
  61.                                  nslika[y, x, 0] = kmeans.grupe[indexOfMin].centar.R;
  62.                                   nslika[y, x, 1] = kmeans.grupe[indexOfMin].centar.G;
  63.                                  nslika[y, x, 2] = kmeans.grupe[indexOfMin].centar.B;
  64.                         /************/
  65.  
  66.  
  67.                         //kmeans.grupe
  68.                         // TODO 2: za svaki piksel na slici odrediti kojem klasteru pripada
  69.                        
  70.                     }
  71.                 }
  72. ***********************************************
  73.  
  74.  
  75.  private void btnBayesKlasifikacija_Click(object sender, EventArgs e)
  76.         {
  77.             if (mainForm.imageEditorDisplay1.mapa.poligoni.Count > 1)
  78.             {
  79.                 byte[, ,] slika = ImageUtil.bitmapToColorMatrix(orginalImage);
  80.                 List<Color> skupK1 = new List<Color>();
  81.                 List<Color> skupK2 = new List<Color>();
  82.                 for (int i = 0; i < mainForm.imageEditorDisplay1.mapa.poligoni.Count; i++)
  83.                 {
  84.                     Poligon pol0 = mainForm.imageEditorDisplay1.mapa.poligoni[i];
  85.                     Poligon bb0 = pol0.getBoundingBox();
  86.                     int xMin0 = (int)bb0.tacke[0].x;
  87.                     int xMax0 = (int)bb0.tacke[1].x;
  88.  
  89.                     int yMin0 = (int)bb0.tacke[0].y;
  90.                     int yMax0 = (int)bb0.tacke[2].y;
  91.  
  92.                     /************/
  93.                     int korakY = (yMax0 - yMin0 > 50 ? (yMax0 - yMin0) / 50 : 1);
  94.                     int korakX = (xMax0 - xMin0 > 50 ? (xMax0 - xMin0) / 50 : 1);
  95.                     /************/
  96.                     for (int y = yMin0; y < yMax0; y+=korakY)
  97.                     {
  98.                         for (int x = xMin0; x < xMax0; x+=korakX)
  99.                         {
  100.                             /************/
  101.                             byte cbR = slika[y, x, 0];
  102.                             byte cbG = slika[y, x, 1];
  103.                             byte cbB = slika[y, x, 2];
  104.                             Color cc = Color.FromArgb(255, cbR, cbG, cbB);
  105.                          
  106.                             if (i % 2 == 0)
  107.                             {
  108.                                 skupK1.Add(cc);
  109.                             }
  110.                             else
  111.                             {
  112.                                 skupK2.Add(cc);
  113.                             }
  114.                             /************/
  115.  
  116.                             // TODO 3: napuniti skupove K1 i K2 (klasa 1 i klasa 2)
  117.                             // piksel ide u K1 ako je unutar poligona sa parnim indeksom
  118.                             // piksel ide u K2 ako je unutar poligona sa neparnim indeksom
  119.                            
  120.                         }
  121.                     }
  122.                 }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement