//在背景为img1的图中,设置3块区域为黄色
//设置img1背景
Image<Bgr, Byte> img1 = new Image<Bgr, Byte>(320, 240, new
Bgr(255, 0, 0));
//yellow(0,255,255)
Byte b1 = 255;
Bgr yellow = new Bgr(0, 255, 255);
//方式1:遍历像素位置将[20-60][20-60]的区域设置成黄色
for (int i = 20; i < 60; i++)
{
for (int j = 20; j < 60; j++)
{
img1.Data[i, j, 0] = 0;
img1.Data[i, j, 1] = b1;
img1.Data[i, j, 2] = b1;
}
}
//方式2:利用遍历数组的方式,将[120-160][20-60]的区域设置成黄色
for (int i = 120; i < 160; i++)
{
for (int j = 20; j < 60; j++)
{
img1[i, j] = yellow;
}
}
////方式3:利用img1.Data数组的方式,将[20-60][100-140]的区域设置撑黄色
byte[, ,] data = img1.Data;
for (int i = 20; i < 60; i++)
{
for (int j = 100; j < 140; j++)
{
//Avoid using c# property inside a loop can have a huge
performance boost
data[i, j, 0] = 0;
data[i, j, 1] = b1;
data[i, j, 2] = b1;
}
}
//显示结果
pictureBox1.Image = img1.ToBitmap();
已知获得的RGB像素值为3维数组,将像素分别存入R、G、B 3个通道 Emgu Image方式读取的图像
最新推荐文章于 2022-12-27 17:43:12 发布