Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Dictionary<Color, int> colorHistogram = new Dictionary<Color, int>();
- /************/
- List<Color> elementi = new List<Color>();
- /************/
- for (int y = yMin; y < yMax; y++){
- ........................................................
- Color cc = Color.FromArgb(cbR, cbG, cbB);
- /************/
- elementi.Add(cc);
- /************/
- if (colorHistogram.ContainsKey(cc)) {
- ...............................................
- KMeans kmeans = new KMeans(); // inicijalizacija
- /************/
- int brojGrupa = Convert.ToInt32(tbBrojGrupa.Text);
- kmeans.elementi = elementi;
- // TODO 1: inicijalizovati podatke koje ce K-means da klasterizuje i pokrenuti algoritam
- kmeans.podeliUGRupe(brojGrupa, 0.01);
- /************/
- // iscrtavanje podataka
- for (int i = 0; i < brojGrupa; i++)
- {
- ..............................................
- for (int y = 0; y < h; y++)
- {
- for (int x = 0; x < w; x++)
- {
- byte cbR = slika[y, x, 0];
- byte cbG = slika[y, x, 1];
- byte cbB = slika[y, x, 2];
- Color cc = Color.FromArgb(255, cbR, cbG, cbB);
- /************/
- double minRastojanje = kmeans.grupe[0].rastojanje(cc);
- int indexOfMin = 0;
- for (int i = 0; i < kmeans.grupe.Count; i++)
- {
- if (kmeans.grupe[i].rastojanje(cc) < minRastojanje)
- {
- minRastojanje = kmeans.grupe[i].rastojanje(cc);
- indexOfMin = i;
- }
- }
- nslika[y, x, 0] = kmeans.grupe[indexOfMin].centar.R;
- nslika[y, x, 1] = kmeans.grupe[indexOfMin].centar.G;
- nslika[y, x, 2] = kmeans.grupe[indexOfMin].centar.B;
- /************/
- //kmeans.grupe
- // TODO 2: za svaki piksel na slici odrediti kojem klasteru pripada
- }
- }
- ***********************************************
- private void btnBayesKlasifikacija_Click(object sender, EventArgs e)
- {
- if (mainForm.imageEditorDisplay1.mapa.poligoni.Count > 1)
- {
- byte[, ,] slika = ImageUtil.bitmapToColorMatrix(orginalImage);
- List<Color> skupK1 = new List<Color>();
- List<Color> skupK2 = new List<Color>();
- for (int i = 0; i < mainForm.imageEditorDisplay1.mapa.poligoni.Count; i++)
- {
- Poligon pol0 = mainForm.imageEditorDisplay1.mapa.poligoni[i];
- Poligon bb0 = pol0.getBoundingBox();
- int xMin0 = (int)bb0.tacke[0].x;
- int xMax0 = (int)bb0.tacke[1].x;
- int yMin0 = (int)bb0.tacke[0].y;
- int yMax0 = (int)bb0.tacke[2].y;
- /************/
- int korakY = (yMax0 - yMin0 > 50 ? (yMax0 - yMin0) / 50 : 1);
- int korakX = (xMax0 - xMin0 > 50 ? (xMax0 - xMin0) / 50 : 1);
- /************/
- for (int y = yMin0; y < yMax0; y+=korakY)
- {
- for (int x = xMin0; x < xMax0; x+=korakX)
- {
- /************/
- byte cbR = slika[y, x, 0];
- byte cbG = slika[y, x, 1];
- byte cbB = slika[y, x, 2];
- Color cc = Color.FromArgb(255, cbR, cbG, cbB);
- if (i % 2 == 0)
- {
- skupK1.Add(cc);
- }
- else
- {
- skupK2.Add(cc);
- }
- /************/
- // TODO 3: napuniti skupove K1 i K2 (klasa 1 i klasa 2)
- // piksel ide u K1 ako je unutar poligona sa parnim indeksom
- // piksel ide u K2 ako je unutar poligona sa neparnim indeksom
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement