WEB开发网
开发学院软件开发C语言 c#图像处理基础 阅读

c#图像处理基础

 2010-09-30 21:04:54 来源:WEB开发网   
核心提示: 图片看不清楚?请点击这里查看原图(大图),6.其他颜色处理1:///<summary>2:///逆反处理3:///</summary>4:///<paramname="sender"></param>5:///<param

c#图像处理基础

图片看不清楚?请点击这里查看原图(大图)。

6.其他颜色处理

   1: /// <summary>
   2:         /// 逆反处理
   3:         /// </summary>
   4:         /// <param name="sender"></param>
   5:         /// <param name="e"></param>
   6:         void ReverseMenuClick(object sender, EventArgs e)
   7:         {
   8:             Bitmap bmp=new Bitmap(pictureBox1.Image);
   9:             Bitmap newbmp=new Bitmap(pictureBox1.Image);
  10:             Color c=new Color();
  11:             Color NewC;
  12:             
  13:             for (int i=0;i<bmp.Width ;i++ )
  14:             {
  15:                 for (int j=0; j<bmp.Height; j++) {
  16:                     c=bmp.GetPixel(i,j);
  17:                     NewC=Color.FromArgb(255-c.R,255-c.G,255-c.B);
  18:                     newbmp.SetPixel(i,j,NewC);
  19:                 }
  20:             }
  21:             
  22:             // 刷新显示
  23:             pictureBox2.Refresh();
  24:             pictureBox2.Image=newbmp;
  25:         }
  26:         
  27:         /// <summary>
  28:         /// 平滑处理 采用3x3窗口的中止代替该像素值
  29:         /// 注:不处理边缘
  30:         /// </summary>
  31:         /// <param name="sender"></param>
  32:         /// <param name="e"></param>
  33:         void SmoothMenuClick(object sender, EventArgs e)
  34:         {
  35:             Bitmap bmp=new Bitmap(pictureBox1.Image);
  36:             Bitmap newbmp=new Bitmap(pictureBox1.Image);
  37:             Color c=new Color();
  38:             Color NewC;
  39:             Byte r,g,b;
  40:             int r2,g2,b2;
  41:             
  42:             for (int i=1;i<bmp.Width-1 ;i++ )
  43:             {
  44:                 for (int j=1; j<bmp.Height-1; j++) {
  45:                     r2=0;g2=0;b2=0;
  46:                     for (int k1=-1; k1<=1; k1++) {
  47:                         for (int k2=-1; k2<=1; k2++) {
  48:                             c=bmp.GetPixel(i+k1,j+k2);
  49:                             r=c.R;
  50:                             g=c.G;
  51:                             b=c.B;
  52:                             
  53:                             r2=r2+r;
  54:                             g2=g2+g;
  55:                             b2=b2+b;
  56:                         }
  57:                     }
  58:                     
  59:                     r2=(Byte)(r2/9);
  60:                     g2=(Byte)(g2/9);
  61:                     b2=(Byte)(b2/9);
  62:                     NewC=Color.FromArgb(r2,g2,b2);
  63:                     newbmp.SetPixel(i,j,NewC);
  64:                 }
  65:             }
  66:             
  67:             // 刷新显示
  68:             pictureBox2.Refresh();
  69:             pictureBox2.Image=newbmp;
  70:         }
  71:         
  72:         /// <summary>
  73:         /// 首先计算源图像的像素(i, j)点的分量值与同行的下一个像素
  74:         /// (i+1, j)以及相同列的下一个像素(i, j+1)的分量的梯度,
  75:         /// 即差的平方和的平方根,然后将梯度值作为新的像素重新放回(i, j)
  76:         /// </summary>
  77:         void NihongMenuClick(object sender, EventArgs e)
  78:         {
  79:             Bitmap bmp=new Bitmap(pictureBox1.Image);
  80:             Bitmap newbmp=new Bitmap(pictureBox1.Image);
  81:             Color c1=new Color();
  82:             Color NewC;
  83:             int r1,r2,r3,g1,g2,g3,b1,b2,b3,rr,gg,bb;
  84:             
  85:             for (int i=0;i<bmp.Width;i++ )
  86:             {
  87:                 for (int j=0; j<bmp.Height; j++) {
  88:                     c1 = bmp.GetPixel(i, j);
  89:                     r1 = c1.R;
  90:                     g1 = c1.G;
  91:                     b1 = c1.B;
  92:                     if (i+1==bmp.Width) {
  93:                         c1 = bmp.GetPixel(i , j);
  94:                     }
  95:                     else
  96:                     {
  97:                         c1 = bmp.GetPixel(i + 1, j);
  98:                     }
  99:                     r2 = c1.R;
 100:                     g2 = c1.G;
 101:                     b2 = c1.B;
 102:                     if (j+1==bmp.Height) {
 103:                         c1 = bmp.GetPixel(i , j);
 104:                     }
 105:                     else
 106:                     {
 107:                         c1 = bmp.GetPixel(i, j+1);
 108:                     }
 109:                     r3 = c1.R;
 110:                     g3 = c1.G;
 111:                     b3 = c1.B;
 112:                     rr = (int)(255-2 * Math.Sqrt((r1 - r2) * (r1 - r2) + (r1 - r3) * (r1 - r3)));
 113:                     gg = (int)(255-2 * Math.Sqrt((g1 - g2) * (g1 - g2) + (g1 - g3) * (g1 - g3)));
 114:                     bb = (int)(255-2 * Math.Sqrt((b1 - b2) * (b1 - b2) + (b1 - b3) * (b1 - b3)));
 115:                     NewC=Color.FromArgb((Byte)rr,(Byte)gg,(Byte)bb);
 116:                     newbmp.SetPixel(i,j,NewC);
 117:                 }
 118:             }
 119:             
 120:             // 刷新显示
 121:             pictureBox2.Refresh();
 122:             pictureBox2.Image=newbmp;
 123:         }

文章来源:http://www.cnblogs.com/feisky/

上一页  1 2 3 4 5 

Tags:图像处理 基础

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接