欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C#圖像顏色聚類高效方法實(shí)例

 更新時(shí)間:2015年04月24日 11:11:02   作者:滄海一粟……  
這篇文章主要介紹了C#圖像顏色聚類高效方法,實(shí)例分析了C#實(shí)現(xiàn)圖像顏色聚類的方法,需要的朋友可以參考下

本文實(shí)例講述了C#圖像顏色聚類高效方法。分享給大家供大家參考。具體分析如下:

圖像顏色聚類的方法有很多,但是對(duì)于視頻監(jiān)控而言,現(xiàn)有方法很難滿足實(shí)時(shí)性的要求,這里介紹一種位屏蔽壓縮的方法實(shí)現(xiàn)顏色聚類,可以滿足實(shí)時(shí)性的要求。

位屏蔽法就是在3D的RGB真彩空間中近似均勻采樣的顏色壓縮方法,即將屏蔽的顏色位置設(shè)置為0,具體可以采用移位運(yùn)算來實(shí)現(xiàn),這里我們以屏蔽RGB顏色分量末6位為例:

public Bitmap PCluster(Bitmap a)
{
  try
  {
   Rectangle rect = new Rectangle(0, 0, a.Width, a.Height);
   System.Drawing.Imaging.BitmapData bmpData = a.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
   int stride = bmpData.Stride;
   unsafe
   {
     byte* pIn = (byte*)bmpData.Scan0.ToPointer();
     byte* P;
     int R, G, B;
     for (int y = 0; y < a.Height; y++)
     {
     for (int x = 0; x < a.Width; x++)
     {
       P = pIn;
       B = P[0];
       G = P[1];
       R = P[2];
       P[0] = (byte)(B & 192); //屏蔽末6位
       P[1] = (byte)(G & 192);
       P[2] = (byte)(R & 192);
       pIn += 3;
     }
     pIn += stride - a.Width * 3;
     }
   }
   a.UnlockBits(bmpData);
   return a;
  }
  catch (Exception e)
  {
   MessageBox.Show(e.Message.ToString());
   return null;
  }
}

原圖:

效果圖:

希望本文所述對(duì)大家的C#程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論