彩色图像的分割处理程序设计+Hough算法(13)
时间:2016-12-16 21:10 来源:毕业论文 作者:毕业论文 点击:次
图4.3 “彩色图像K-均值聚类分割”结果 以下为“K-均值聚类”处理代码如下: private void button1_Click(object sender, EventArgs e) { if (curBitmap != null) { segColor segmentationC = new segColor(); if (segmentationC.ShowDialog() == DialogResult.OK) { Rectangle rect = new Rectangle(0, 0, curBitmap.Width, curBitmap.Height); System.Drawing.Imaging.BitmapData bmpData = curBitmap.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, curBitmap.PixelFormat); IntPtr ptr = bmpData.Scan0; int bytes = curBitmap.Width * curBitmap.Height; byte[] rgbValues = new byte[bytes * 3]; System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValues, 0, bytes * 3); byte numbers = segmentationC.GetNum; int[] kNum = new int[numbers]; int[] kAver = new int[numbers * 3]; int[] kOldAver = new int[numbers * 3]; int[] kSum = new int[numbers * 3]; double[] kTemp = new double[numbers]; byte[] segmentMap = new byte[bytes * 3]; //初始化聚类均值 for (int i = 0; i < numbers; i++) { kAver[i * 3 + 2] = kOldAver[i * 3 + 2] = Convert.ToInt16(i * 255 / (numbers - 1)); (责任编辑:qin) |