像素交换

Emgu.CV(三)-LMLPHPEmgu.CV(三)-LMLPHP

private void btn_Exchange_Click(object sender, EventArgs e)
{
if (imageBox1.Image != null)
{
var image = (Image<Bgr, Byte>)imageBox1.Image;
ExChangePixelValue(image);
imageBox1.Image = image;
}
}
public void ExChangePixelValue(Image<Bgr, Byte> image)
{
//这两个值视图片大小而定
for (int i = 0; i < 500; i++)
{
for (int j = 0; j < 1000; j++)
{
Bgr tmp = image[i, j];
image[i, j] = image[i + 500, j + 500];
image[i + 500, j + 500] = tmp;
}
}
}

  

图片自加

Emgu.CV(三)-LMLPHP

private void btn_Add_Click(object sender, EventArgs e)
{
var image= new Image<Bgr, byte>(@"D:\1.jpg");
//图片自加
imageBox2.Image = image.Add(image);
}

  

图片自减

Emgu.CV(三)-LMLPHP

private void btn_Sub_Click(object sender, EventArgs e)
{
var image = new Image<Bgr, byte>(_img);
//图片自减
var rect = new Rectangle(new Point(0, 0), new Size(image.Width / 2, image.Height));
using (var mask = new Image<Gray, Byte>(image.Size))
{
mask.SetZero();//设置所有值为0
mask.ROI = rect;
mask.SetValue(255);//设置ROI的值为255
mask.ROI = Rectangle.Empty;//去掉ROI
//res(I)=img1(I)-img2(I) if mask(I)!=0
var resImage = image.Sub(image, mask);
mask._Not();//反转mask的值(255->0, 0->255)
image.Copy(resImage, mask);//在mask(I)!= 0的条件下,把image1的值拷贝到resImage中
imageBox2.Image = resImage;
}
}

  

05-08 07:59