【发布时间】:2017-07-06 21:48:47
【问题描述】:
您好,我需要将图像转换为黑白和 2 位深度。
我尝试了以下操作,它生成了一个 8 位的图像。没有看到任何生成 2 位图像的选项。
Emgu.CV.Image<Gray, Single> image = new Emgu.CV.Image<Gray, Single>("test.jpg");
有人可以建议吗?
【问题讨论】:
您好,我需要将图像转换为黑白和 2 位深度。
我尝试了以下操作,它生成了一个 8 位的图像。没有看到任何生成 2 位图像的选项。
Emgu.CV.Image<Gray, Single> image = new Emgu.CV.Image<Gray, Single>("test.jpg");
有人可以建议吗?
【问题讨论】:
在 emgucv 中你有以下图像深度
Byte、SByte、Single(浮点)、Double、UInt16、Int16、Int32(int) (来自emgucv)
您没有 2 位深度。 但是你可以制作一个看起来像这样的 2 位图像的图像:
var theImage = new Image<Gray, byte>(@"d:\temp\lena.jpg");
for (int i = theImage.Rows - 1; i >= 0; i--)
{
for (int j = theImage.Cols - 1; j >= 0; j--)
{
if(theImage.Data[i,j,0]>byte.MaxValue/2)
{
theImage.Data[i, j, 0] = byte.MaxValue;
}
else
{
theImage.Data[i, j, 0] = 0;
}
}
}
【讨论】: