毕业论文

打赏
当前位置: 毕业论文 > 计算机论文 >

彩色图像的分割处理程序设计+Hough算法(13)

时间:2016-12-16 21:10来源:毕业论文
图4.3 彩色图像K-均值聚类分割结果 以下为K-均值聚类处理代码如下: private void button1_Click(object sender, EventArgs e) { if (curBitmap != null) { segColor segmentationC = ne


图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)); 彩色图像的分割处理程序设计+Hough算法(13):http://www.751com.cn/jisuanji/lunwen_1067.html
------分隔线----------------------------
推荐内容