实例介绍
【实例简介】
【实例截图】
【核心代码】
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Drawing.Imaging; using System.Linq; using System.Text; using System.Windows.Forms; using System.Threading; using Emgu.CV; using Emgu.CV.UI; using Emgu.CV.Structure; using Emgu.CV.CvEnum; namespace DigitalImage { public partial class Filter : Form { //目的图像,以及处理图像 private Image<Bgr, Byte> My_Image; private Image<Bgr, Byte> My_Image2; private Image<Bgr, Byte> My_Image3; private Image<Bgr, Byte> My_Image4; private Image<Bgr, Byte> My_Image5; private Image<Bgr, Byte> My_Image6; private Image<Bgr, Byte> My_Image7; //用于直方图均衡化的HSV模型 private Image<Hsv, Byte> My_Image05; private Image<Gray, Byte> imageL; //圆周率 private double PI = 3.1415926; private int Flag; //定义源图像的尺寸 private int Height; private int Width; //定义一个EmguCV的像素变量 private Bgr pixel, pixel2; //RGB完了该HSV了 private Hsv Pixel; //声明委托(通知父窗口关闭) public delegate void UpdateDataDelegate();//声明一个委托 public UpdateDataDelegate UpdateTextBox; //定义委托 private void MyFormClosed(object sender, EventArgs e) { UpdateTextBox(); } public Filter() { InitializeComponent(); } public Filter(string name, int flag) { InitializeComponent(); this.Text = name; Flag = flag; if (Flag == 1) { this.button2.Text = "底片效果"; this.button3.Text = "浮雕效果"; this.button4.Text = "油画效果"; this.button5.Text = "霓虹变换"; this.button6.Text = "积木效果"; this.button7.Text = "一米阳光"; } if (Flag == 2) { this.button2.Text = "图像增亮"; this.button3.Text = "图像变暗"; this.button4.Text = "直方图"; this.button5.Text = "均衡化"; this.button6.Text = "模糊处理"; this.button7.Text = "加马赛克"; } if (Flag == 3) { this.button2.Text = "旋转扭曲"; this.button3.Text = "球形收缩"; this.button4.Text = "垂直内凹"; this.button5.Text = "水平外凸"; this.button6.Text = "波浪形"; this.button7.Text = "三角形"; } } private void Filter_Load(object sender, EventArgs e) { } //打开文件 private void button1_Clck(object sender, EventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "BMP文件|*.bmp|JPG文件|*.jpg|JPEG文件|*.jpeg|所有文件|*.*"; if (openFileDialog.ShowDialog() == DialogResult.OK) { My_Image = new Image<Bgr, byte>(openFileDialog.FileName); My_Image2 = new Image<Bgr, byte>(openFileDialog.FileName); My_Image3 = new Image<Bgr, byte>(openFileDialog.FileName); My_Image4 = new Image<Bgr, byte>(openFileDialog.FileName); My_Image05 = new Image<Hsv, byte>(openFileDialog.FileName); My_Image5 = new Image<Bgr, byte>(openFileDialog.FileName); My_Image6 = new Image<Bgr, byte>(openFileDialog.FileName); My_Image7 = new Image<Bgr, byte>(openFileDialog.FileName); pictureBox1.Image = My_Image.ToBitmap(); Height = My_Image.Height; Width = My_Image.Width; } } //1.底片效果, 2.图像增亮,3.旋转扭曲 private void button2_Click(object sender, EventArgs e) { if (pictureBox2.Image != null) { pictureBox2.Image.Dispose(); pictureBox2.Image = null; } this.pictureBox2.Hide(); if (Flag == 1) { this.Negative(); this.pictureBox2.Image = My_Image2.ToBitmap(); this.pictureBox2.Show(); } if (Flag == 2) { //降低跨线程调用的安全性 System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false; Thread t1 = new Thread(new ThreadStart(Thread1)); t1.Start(); } if (Flag == 3) { this.Distort(); this.pictureBox2.Image = My_Image2.ToBitmap(); this.pictureBox2.Show(); } } //1.浮雕效果.2图像变暗,3.球形收缩 private void button3_Click(object sender, EventArgs e) { if (pictureBox2.Image != null) { pictureBox2.Image.Dispose(); pictureBox2.Image = null; } this.pictureBox2.Hide(); if (Flag == 1) { this.Sculpture(); this.pictureBox2.Image = My_Image3.ToBitmap(); this.pictureBox2.Show(); } if (Flag == 2) { //降低跨线程调用的安全性 System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false; Thread t2 = new Thread(new ThreadStart(Thread2)); t2.Start(); } if (Flag == 3) { this.GlobeContract(); this.pictureBox2.Image = My_Image3.ToBitmap(); this.pictureBox2.Show(); } } //1.油画效果.2直方图,3.垂直内凹 private void button4_Click(object sender, EventArgs e) { if (pictureBox2.Image != null) { pictureBox2.Image.Dispose(); pictureBox2.Image = null; } this.pictureBox2.Hide(); if (Flag == 1) { this.OilPainting(); this.pictureBox2.Image = My_Image4.ToBitmap(); this.pictureBox2.Show(); } if (Flag == 2) { this.CalcHistRgb(ref My_Image4); } if (Flag == 3) { this.Vertical(); Bitmap MyBitmap = My_Image4.ToBitmap(); this.Fill(ref MyBitmap); this.pictureBox2.Image = MyBitmap; this.pictureBox2.Show(); } } //1.霓虹变换.2均衡化,3.水平外凸 private void button5_Click(object sender, EventArgs e) { if (pictureBox2.Image != null) { pictureBox2.Image.Dispose(); pictureBox2.Image = null; } this.pictureBox2.Hide(); if (Flag == 1) { this.Neon(); this.pictureBox2.Image = My_Image5.ToBitmap(); this.pictureBox2.Show(); } if (Flag == 2) { this.HistogramEqualization(); this.pictureBox2.Image = My_Image05.ToBitmap(); this.pictureBox2.Show(); } if (Flag == 3) { this.Horizontal(); Bitmap MyBitmap = My_Image5.ToBitmap(); this.Fill(ref MyBitmap); this.pictureBox2.Image = MyBitmap; this.pictureBox2.Show(); } } //1.积木效果,2.平滑处理,3.波浪形 private void button6_Click(object sender, EventArgs e) { if (pictureBox2.Image != null) { pictureBox2.Image.Dispose(); pictureBox2.Image = null; } this.pictureBox2.Hide(); if (Flag == 1) { this.Toy(); this.pictureBox2.Image = My_Image6.ToBitmap(); this.pictureBox2.Show(); } if (Flag == 2) { //降低跨线程调用的安全性 System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false; Thread t3 = new Thread(new ThreadStart(Thread3)); t3.Start(); } if (Flag == 3) { this.SShape(); Bitmap MyBitmap = My_Image6.ToBitmap(); this.Fill(ref MyBitmap); this.pictureBox2.Image = MyBitmap; this.pictureBox2.Show(); } } //1.一米阳光,2.加马赛克,3.三角形 private void button7_Click(object sender, EventArgs e) { //以光照效果显示图像 if (pictureBox2.Image != null) { pictureBox2.Image.Dispose(); pictureBox2.Image = null; } this.pictureBox2.Hide(); if (Flag == 1) { this.Sunny(); this.pictureBox2.Image = My_Image7.ToBitmap(); this.pictureBox2.Show(); } if (Flag == 2) { this.Mosaic(); ; this.pictureBox2.Image = My_Image7.ToBitmap(); this.pictureBox2.Show(); } if (Flag == 3) { this.Triangle(); Bitmap MyBitmap = My_Image7.ToBitmap(); this.Fill(ref MyBitmap); this.pictureBox2.Image = MyBitmap; this.pictureBox2.Show(); } } //关闭窗体 private void button8_Click(object sender, EventArgs e) { this.Close(); } //画布填充 private void Fill( ref Bitmap bt1) { for(int i = 0; i< bt1.Width; i ) for (int j = 0; j < bt1.Height; j ) { Color pixel = bt1.GetPixel(i, j); if (pixel.R ==0 && pixel.G == 0 && pixel.B == 0) { pixel = System.Drawing.Color.DarkSlateBlue; bt1.SetPixel(i, j, pixel); } } } #region 以下是图像算法 #region 色彩 //1.2底片效果 private void Negative() { for (int x = 0; x < Width; x ) { for (int y = 0; y < Height; y ) { //取像素 pixel = My_Image2[x, y]; //修改 pixel.Blue = 255 - pixel.Blue; pixel.Green = 255 - pixel.Green; pixel.Red = 255 - pixel.Red; //更新像素值 My_Image2[x, y] = pixel; } } } //1.3浮雕效果 private void Sculpture() { for (int x = 0; x < Width - 1; x ) { for (int y = 0; y < Height - 1; y ) { //取像素 pixel = My_Image3[x, y]; pixel2 = My_Image3[x 1, y 1]; //修改 pixel.Red = Math.Abs(pixel.Red - pixel2.Red 128); pixel.Blue = Math.Abs(pixel.Blue - pixel2.Blue 128); pixel.Green = Math.Abs(pixel.Green - pixel2.Green 128); if (pixel.Red > 255) pixel.Red = 255; if (pixel.Red < 0) pixel.Red = 0; if (pixel.Blue > 255) pixel.Blue = 255; if (pixel.Red < 0) pixel.Red = 0; if (pixel.Green > 255) pixel.Green = 255; if (pixel.Red < 0) pixel.Red = 0; //更新像素值 My_Image3[x, y] = pixel; } } } //1.4油画效果 private void OilPainting() { Random rand = new Random(); for (int i = 0; i < Width - 10; i ) { for (int j = 0; j < Height - 10; j ) { int a = rand.Next(3); pixel = My_Image4[i a, j a]; My_Image4[i, j] = pixel; } } } //1.5霓虹变换 private void Neon() { //霓虹变换 //原理:来描绘图像的轮廓,勾画颜色变化的边缘,加强其过度效果,产生轮廓发光的效果。 // 主要是根据当前像素与其右方和下方像素的梯度运算,然后将结果值作为当前像素值, //即将原图像当前像素的R、G、B分量与其右方和下方像素做梯度运算(差的平方和的平方根), //然后将梯度值作为处理后像素的R、G、B的三个分量。 for (int i = 0; i < Width - 1; i ) { for (int j = 0; j < Height - 1; j ) { Bgr r1, r2, r3; r1 = My_Image5[i, j]; r2 = My_Image5[i 1, j]; r3 = My_Image5[i, j 1]; //Red像素变换算法 pixel.Red = (2 * Math.Sqrt((r1.Red - r2.Red) * (r1.Red - r2.Red) (r1.Red - r3.Red) * (r1.Red - r3.Red))); //Green像素变换算法 pixel.Green = (2 * Math.Sqrt((r1.Green - r2.Green) * (r1.Green - r2.Green) (r1.Green - r3.Green) * (r1.Green - r3.Green))); //Blue像素变换双方 pixel.Blue = (2 * Math.Sqrt((r1.Blue - r2.Blue) * (r1.Blue - r2.Blue) (r1.Blue - r3.Blue) * (r1.Blue - r3.Blue))); if (pixel.Red > 255) pixel.Red = 255; if (pixel.Red < 0) pixel.Red = 0; if (pixel.Blue > 255) pixel.Blue = 255; if (pixel.Red < 0) pixel.Red = 0; if (pixel.Green > 255) pixel.Green = 255; if (pixel.Red < 0) pixel.Red = 0; //更新像素值 My_Image5[i, j] = pixel; } } } //1.6积木效果 private void Toy() { int m, n; double iPixel, iAvg; m = 0; while (m < Width - 1) { n = 0; while (n < Height - 1) { pixel = My_Image6[m, n]; iAvg = (pixel.Red pixel.Green pixel.Blue) / 3.0; iPixel = 0; if (iAvg >= 128) iPixel = 255; else iPixel = 0; pixel2.Blue = iPixel; pixel2.Green = iPixel; pixel2.Red = iPixel; My_Image6[m, n] = pixel2; n = n 1; } m = m 1; } } //1.7一米阳光 private void Sunny() { int A = Width / 2; int B = Height / 2; //MyCenter图片中心点,发亮此值会让强光中心发生偏移 Point MyCenter = new Point(Width / 6, Height / 6); //R强光照射面的半径,即”光晕” int R = Math.Min(Width, Height); for (int i = Width - 1; i >= 1; i--) { for (int j = Height - 1; j >= 1; j--) { float MyLength = (float)Math.Sqrt(Math.Pow((i - MyCenter.X), 2) Math.Pow((j - MyCenter.Y), 2)); //如果像素位于”光晕”之内 if (MyLength < R) { //取像素 pixel = My_Image7[i, j]; //220亮度增加常量,该值越大,光亮度越强,f是浮点数 float MyPixel = 220.0f * (1.0f - MyLength / R); pixel.Red = pixel.Red (int)MyPixel; pixel.Red = Math.Max(0, Math.Min(pixel.Red, 255)); pixel.Green = pixel.Green (int)MyPixel; pixel.Green = Math.Max(0, Math.Min(pixel.Green, 255)); pixel.Blue = pixel.Blue (int)MyPixel; pixel.Blue = Math.Max(0, Math.Min(pixel.Blue, 255)); //将增亮后的像素值回写到位图 My_Image7[i, j] = pixel; } } } } #endregion #region 工具 //2.2图像加亮 private void Light() { for (int x = 0; x < Width; x ) { for (int y = 0; y < Height; y ) { //取像素 pixel = My_Image2[x, y]; //修改 pixel.Blue = 5; pixel.Green = 5; pixel.Red = 5; if (pixel.Red > 255) pixel.Red = 255; if (pixel.Red < 0) pixel.Red = 0; if (pixel.Blue > 255) pixel.Blue = 255; if (pixel.Red < 0) pixel.Red = 0; if (pixel.Green > 255) pixel.Green = 255; if (pixel.Red < 0) pixel.Red = 0; //更新像素值 My_Image2[x, y] = pixel; } } } //2.3图像变暗 private void Dark() { for (int x = 0; x < Width; x ) { for (int y = 0; y < Height; y ) { //取像素 pixel = My_Image3[x, y]; //修改 pixel.Blue -= 5; pixel.Green -= 5; pixel.Red -= 5; if (pixel.Red > 255) pixel.Red = 255; if (pixel.Red < 0) pixel.Red = 0; if (pixel.Blue > 255) pixel.Blue = 255; if (pixel.Red < 0) pixel.Red = 0; if (pixel.Green > 255) pixel.Green = 255; if (pixel.Red < 0) pixel.Red = 0; //更新像素值 My_Image3[x, y] = pixel; } } } //2.4直方图 private void CalcHistRgb( ref Image<Bgr,Byte> imageSource) { //直接用HistogranViewer的静态函数Show来查看直方图,不过不能控制行为 HistogramViewer.Show(imageSource, 256); //释放资源 imageSource.Dispose(); imageL = My_Image05[1]; //直接用HistogranViewer的静态函数Show来查看直方图,不过不能控制行为 HistogramViewer.Show(imageL, 256); //释放资源 //imageL.Dispose(); } //2.5直方图均衡化 private void HistogramEqualization() { imageL._EqualizeHist(); My_Image05[1] = imageL; //直接用HistogranViewer的静态函数Show来查看直方图,不过不能控制行为 HistogramViewer.Show(imageL, 256); //释放资源 imageL.Dispose(); } //2.6高斯平滑 private void DimGauss() { //高斯模板 int[] Gauss = { 1, 2, 1, 2, 4, 2, 1, 2, 1 }; for (int x = 1; x < Width - 1; x ) for (int y = 1; y < Height - 1; y ) { pixel2.Blue = 0; pixel2.Red = 0; pixel2.Green = 0; int Index = 0; for (int col = -1; col <= 1; col ) for (int row = -1; row <= 1; row ) { //取像素 pixel = My_Image6[x row, y col]; //修改 pixel2.Red = pixel.Red * Gauss[Index]; pixel2.Blue = pixel.Blue * Gauss[Index]; pixel2.Green = pixel.Green * Gauss[Index]; Index ; } pixel2.Red /= 16; pixel2.Green /= 16; pixel2.Blue /= 16; //溢出处理 if (pixel2.Red > 255) pixel2.Red = 255; if (pixel2.Red < 0) pixel2.Red = 0; if (pixel2.Blue > 255) pixel2.Blue = 255; if (pixel2.Red < 0) pixel2.Red = 0; if (pixel2.Green > 255) pixel2.Green = 255; if (pixel2.Red < 0) pixel2.Red = 0; //更新像素值 My_Image6[x - 1, y - 1] = pixel2; } } //2.7加马赛克 private void Mosaic() { //对图像指定的区域加马赛克 //方法是把目标区域划分成小块,把每个块的值都设成这个块的均值或中值 const int N = 11;//效果粒度,值越大码越严重 double r = 0, g = 0, b = 0; //确定变形区域 double R = Width / 3; //变形半径 double x0 = Width / 2; double y0 = Height / 2; //变形中心 for (int y = 0; y < Height; y ) { for (int x = 0; x < Width; x ) { if ((x - x0) * (x - x0) (y - y0) * (y - y0) <= R * R) //变形区域内 { if (y % N == 0) { if (x % N == 0)//整数倍时,取像素赋值 { pixel = My_Image7[x, y]; r = pixel.Red; g = pixel.Green; b = pixel.Blue; } else { My_Image7[x, y] = pixel; } } else //复制上一行 { pixel = My_Image7[x, y - 1]; My_Image7[x, y] = pixel; } } } } } #endregion #region 几何 //3.2.旋转扭曲 private void Distort() { int r = 75; int x = Width / 2; int y = Height / 2; int x1 = x - r; if (x1 < 0) r = x; else if (x1 2 * r > Width) r = Width - x; int y1 = y - r; if (y1 < 0) r = y; else if (y1 2 * r > Height) r = Height - y; x1 = x - r; y1 = y - r; int r2 = 150; //这是为了选定一个长宽都是r2的区域来进行扭曲 Image<Bgr, Byte> My_Image2_1 = new Image<Bgr,Byte>(r2, r2); Image<Bgr, Byte> My_Image2_2 = new Image<Bgr, Byte>(r2, r2); int i, j; for (i = 0; i < r2; i ) for (j = 0; j < r2; j ) { pixel = My_Image2[x1 i, y1 j]; My_Image2_1[i, j] = pixel; } double jiaodu = 75; double cos; double sin, m, n; for (i = 0; i < r2; i ) for (j = 0; j < r2; j ) { int rr = (i - r) * (i - r) (j - r) * (j - r); if (rr > r * r) My_Image2_2[i, j] = My_Image2_1[i, j]; else { double l = Math.Sqrt(rr); double jiao = jiaodu * Math.Sin(l * Math.PI / r); cos = Math.Cos(jiao / 360 * (Math.PI * 2)); sin = Math.Sin(jiao / 360 * (Math.PI * 2)); m = (i - r) * cos (j - r) * sin; n = (j - r) * cos - (i - r) * sin; int a = (int)m r; int b = (int)n r; if (a < 0) a = 0; else if (a >= r2) a = r2 - 1; if (b < 0) b = 0; else if (b >= r2) b = r2 - 1; My_Image2_2[i, j] = My_Image2_1[a, b]; } } for (i = 0; i < r2; i ) for (j = 0; j < r2; j ) { pixel = My_Image2_2[i, j]; My_Image2[x1 i, y1 j] = pixel; } } //3.3球形收缩 private void GlobeContract() { int r = 80; int x = Width / 2; int y = Height / 2; int x1 = x - r; if (x1 < 0) r = x; else if (x1 2 * r > Width) r = Width - x; int y1 = y - r; if (y1 < 0) r = y; else if (y1 2 * r > Height) r = Height - y; x1 = x - r; y1 = y - r; int r2 = 160; //这是为了选定一个长宽都是r2的区域来进行扭曲 Image<Bgr, Byte> My_Image3_1 = new Image<Bgr, Byte>(r2, r2); Image<Bgr, Byte> My_Image3_2 = new Image<Bgr, Byte>(r2, r2); int i, j; for (i = 0; i < r2; i ) for (j = 0; j < r2; j ) { pixel = My_Image3[x1 i, y1 j]; My_Image3_1[i, j] = pixel; } for (i = 0; i < r2; i ) for (j = 0; j < r2; j ) { int rr = (i - r) * (i - r) (j - r) * (j - r); if (rr > r * r) My_Image3_2[i, j] = My_Image3_1[i, j]; else { double l = Math.Sqrt(rr); double du = Math.Sin(l * PI / r); double m = (i - r) (i - r) * du / 4; double n = (j - r) (j - r) * du / 4; int a = (int)m r; int b = (int)n r; if (a < 0) a = 0; else if (a >= r2) a = r2 - 1; if (b < 0) b = 0; else if (b >= r2) b = r2 - 1; My_Image3_2[i, j] = My_Image3_1[a, b]; } } for (i = 0; i < r2; i ) for (j = 0; j < r2; j ) { pixel = My_Image3_2[i, j]; My_Image3[x1 i, y1 j] = pixel; } } //3.4垂直内凹 private void Vertical() { Image<Bgr, Byte> My_Image4_1 = new Image<Bgr, Byte>(Width, Height); for (int i = 1; i < Width; i ) { for (int j = 1; j < Height; j ) { int s = (int)(i (0.3 * Height - 0.6 * i) * Math.Sin(j * PI / Width)); //取相反点 pixel = My_Image4[j, i]; My_Image4_1[j, s] = pixel; } } //将修改后的图像放入原图中 My_Image4 = My_Image4_1; } //3.5水平外凸 private void Horizontal() { Image<Bgr, Byte> My_Image5_1 = new Image<Bgr, Byte>(Width, Height); for (int i = 0; i < Height; i ) { for (int j = 0; j < Width; j ) { int s = (int)(j (0.3 * Width - 0.6 * j) * Math.Sin(i * PI / Height)); //取相反点 pixel = My_Image5[j, i]; My_Image5_1[s, i] = pixel; } } //将修改后的图像放入原图中 My_Image5 = My_Image5_1; } //3.6 波浪形 private void SShape() { Image<Bgr, Byte> My_Image6_1 = new Image<Bgr, Byte>(Width, Height); for (int i = 0; i < Height; i ) { for (int j = 0; j < Width; j ) { int s = (int)((4 * i Height Height * Math.Sin(j * 2 * PI / Width)) / 6); //取相反点 pixel = My_Image6[i, j]; My_Image6_1[s, j] = pixel; } } //将修改后的图像放入原图中 My_Image6 = My_Image6_1; } //3.7 三角形 private void Triangle() { Image<Bgr, Byte> My_Image7_1 = new Image<Bgr, Byte>(Width, Height); for (int i = 0; i < Height; i ) { for (int j = 0; j < Width * ( i 1 )/Height; j ) { int s = j * Height / (i 1); //取相反点 pixel = My_Image7[s, i]; My_Image7_1[j, i] = pixel; } } //将修改后的图像放入原图中 My_Image7 = My_Image7_1; } #endregion #region 相关 #endregion private void Thread1() { for (int i = 0; i < 15; i ) { this.Light(); this.pictureBox2.Image = My_Image2.ToBitmap(); this.pictureBox2.Show(); } } private void Thread2() { for (int i = 0; i < 10; i ) { this.Dark(); this.pictureBox2.Image = My_Image3.ToBitmap(); this.pictureBox2.Show(); } } private void Thread3() { for (int i = 0; i < 10; i ) { this.DimGauss(); this.pictureBox2.Image = My_Image6.ToBitmap(); this.pictureBox2.Show(); } } /*附加算法,没有用到 //1.6人脸锐化 private void FaceClear() { int A = Width / 2; int B = Height / 2; //MyCenter图片中心点,发亮此值会让强光中心发生偏移 Point MyCenter = new Point(Width / 2, Height / 2); //R强光照射面的半径,即”光晕” int R = Math.Min(Width / 3, Height / 3); //拉普拉斯模板 int[] Laplacian = { -1, -1, -1, -1, 9, -1, -1, -1, -1 }; for (int x = 1; x < Width - 1; x ) for (int y = 1; y < Height - 1; y ) { float MyLength = (float)Math.Sqrt(Math.Pow((x - MyCenter.X), 2) Math.Pow((y - MyCenter.Y), 2)); //如果像素位于”光晕”之内 if (MyLength < R) { pixel2.Blue = 0; pixel2.Red = 0; pixel2.Green = 0; int Index = 0; for (int col = -1; col <= 1; col ) for (int row = -1; row <= 1; row ) { //取像素 pixel = My_Image6[x row, y col]; //修改 pixel2.Red = pixel.Red * Laplacian[Index]; pixel2.Blue = pixel.Blue * Laplacian[Index]; pixel2.Green = pixel.Green * Laplacian[Index]; Index ; } //溢出处理 if (pixel2.Red > 255) pixel2.Red = 255; if (pixel2.Red < 0) pixel2.Red = 0; if (pixel2.Blue > 255) pixel2.Blue = 255; if (pixel2.Red < 0) pixel2.Red = 0; if (pixel2.Green > 255) pixel2.Green = 255; if (pixel2.Red < 0) pixel2.Red = 0; //更新像素值 My_Image6[x - 1, y - 1] = pixel2; } } } //1.4黑白怀旧 private void BlackWhite() { int fina; for (int x = 0; x < Width; x ) { for (int y = 0; y < Height; y ) { //取像素 pixel = My_Image4[x, y]; //加权平均值法 fina = ((int)(0.7 * pixel.Red) (int)(0.2 * pixel.Green) (int)(0.1 * pixel.Blue)); pixel.Red = fina; pixel.Blue = fina; pixel.Green = fina; //更新像素值 My_Image4[x, y] = pixel; } } } */ #endregion } }
好例子网口号:伸出你的我的手 — 分享!
网友评论
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明
支持(0) 盖楼(回复)