private void button3_Click(object sender, EventArgs e) { if (openFileDialog1.ShowDialog() == DialogResult.OK) { MessageBox.Show(this, "Every CLUSTER will be in a specific color", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); label8.Visible = true; //System.Threading.Thread.Sleep(20); this.Update(); ReadImage r = new ReadImage(@openFileDialog1.FileName); double[][] data = r.getData; double[][] res; bool[][] mim; CLUSTER c = new CLUSTER(data, clustersNumber, exp, eps); if (algoType == 0) { res = c.ClusterMyDataByC_Mean(); } else { res = c.clusterByGK(P); } mim = c.cluster_BY_data(); //System. pictureBox2.BackgroundImage = r.IMAGE.Bitmap; UnsafeBitmap temp = new UnsafeBitmap(r.IMAGE.Width, r.IMAGE.Height); temp.LockBitmap(); for (int x = 0; x < mim[0].Length; x++) { for (int y = 0; y < mim.Length; y++) { if (mim[y][x]) { temp.SetPixel(x % temp.Width, x / temp.Width, new PixelData(COLORS[y].R, COLORS[y].G, COLORS[y].B)); break; } } } pictureBox3.BackgroundImage = temp.Bitmap; temp.UnlockBitmap(); r.IMAGE.UnlockBitmap(); } label8.Visible = false; }
private void loadImage() { map = new UnsafeBitmap(new System.Drawing.Bitmap(@path)); map.LockBitmap(); PixelData pi; data = new double[map.Width * map.Height][]; for (int y = 0; y < map.Height; y++) { for (int x = 0; x < map.Width; x++) { pi = map.GetPixel(x, y); data[y * map.Width + x] = new double[5]; data[y * map.Width + x][0] = pi.red; data[y * map.Width + x][1] = pi.green; data[y * map.Width + x][2] = pi.blue; data[y * map.Width + x][3] = x; data[y * map.Width + x][4] = y; } } }
private void button2_Click(object sender, EventArgs e) { ReadImage r = new ReadImage(@"G:\HandWriting\logo_4.bmp"); double[][] data = r.getData; double[][] res; bool[][] mim; CLUSTER c = new CLUSTER(data, 6, 2, 0.0001); res = c.ClusterMyDataByC_Mean(); mim = c.cluster_BY_data(); // pictureBox1.BackgroundImage = r.IMAGE.Bitmap; UnsafeBitmap temp = new UnsafeBitmap(r.IMAGE.Width, r.IMAGE.Height); PixelData[] colors = new PixelData[6]; colors[0] = new PixelData(Color.Coral.R, Color.Coral.G, Color.Coral.B); colors[1] = new PixelData(Color.Peru.R, Color.Peru.G, Color.Peru.B); colors[2] = new PixelData(Color.Goldenrod.R, Color.Goldenrod.G, Color.Goldenrod.B); colors[3] = new PixelData(Color.DarkKhaki.R, Color.DarkKhaki.G, Color.DarkKhaki.B); colors[4] = new PixelData(Color.Yellow.R, Color.Yellow.G, Color.Yellow.B); colors[5] = new PixelData(Color.WhiteSmoke.R, Color.WhiteSmoke.G, Color.WhiteSmoke.B); temp.LockBitmap(); for (int x = 0; x < mim[0].Length; x++) { for (int y = 0; y < mim.Length; y++) { if (mim[y][x]) { temp.SetPixel(x % temp.Width, x / temp.Width, colors[y]); break; } } } // pictureBox2.BackgroundImage = temp.Bitmap; temp.UnlockBitmap(); r.IMAGE.UnlockBitmap(); }