【问题标题】:C# EmguCV/OpenCV "cvThreshold" abnormal behaviour - no expected threshold resultC# EmguCV/OpenCV“cvThreshold”异常行为 - 没有预期的阈值结果
【发布时间】:2012-08-04 19:32:31
【问题描述】:

有识别图像上红色区域的任务,它需要最大的准确性。但是源图像的质量很差。我正在尝试使用 cvThreshold 最小化检测到红色区域的面具上的噪音。不幸的是,没有预期的效果 - 灰色伪影仍然存在。

//Converting from Bgr to Hsv
Image<Hsv, Byte> hsvimg = markedOrigRecImg.Convert<Hsv, Byte>();
Image<Gray, Byte>[] channels = hsvimg.Split();

Image<Gray, Byte> hue = channels[0];
Image<Gray, Byte> saturation = channels[1];
Image<Gray, Byte> value = channels[2];

Image<Gray, Byte> hueFilter = hue.InRange(new Gray(0), new Gray(30));
Image<Gray, Byte> satFilter = saturation.InRange(new Gray(100), new Gray(255));
Image<Gray, Byte> valFilter = value.InRange(new Gray(50), new Gray(255));

//Mask contains gray artifacts        
Image<Gray,Byte> mask = (hueFilter.And(satFilter)).And(valFilter);

//Gray artifacts stays even if threshold (the third param.) value is 0...
CvInvoke.cvThreshold(mask, mask, 100, 255, THRESH.CV_THRESH_BINARY);

mask.Save("D:/img.jpg");

同时在这里它工作正常 - 保存的图像是纯白色的:

#region test

Image<Gray,Byte> some = new Image<Gray, byte>(mask.Size);
some.SetValue(120);
CvInvoke.cvThreshold(some, some, 100, 255, THRESH.CV_THRESH_BINARY);
some.Save("D:/some.jpg");

#endregion

阈值前的掩码示例: http://dl.dropbox.com/u/52502108/input.jpg

阈值后的掩码示例: http://dl.dropbox.com/u/52502108/output.jpg

提前谢谢你。 康斯坦丁 B.

【问题讨论】:

  • 你可以在某处发布图片(输入和输出)吗?
  • 已上传。请参阅上面的链接。
  • 图像是相同的,其中没有任何红色。您能否更好地解释如何处理输入图像?
  • 红色识别没有问题,所以我没有上传彩色原图。当我尝试使用 cvThreshold 提高蒙版质量时,就会出现问题。我在原始图像中制作了一个红色蒙版 (mask = (hueFilter.And(satFilter)).And(valFilter)) - 它包含 4 个带有灰色伪影的白色区域(在原始图像中为红色)。 Mask 是灰度 1 通道 8 位深度图像。然后我想对蒙版应用阈值,但没有结果 - 这就是图像相同的原因。请参阅下面的阈值所需效果。

标签: c# opencv emgucv image-recognition threshold


【解决方案1】:

应用任何类型的阈值后,保存的图像上出现灰色伪影的原因是... *.JPG 标准保存格式Image&lt;TColor, TDepth&gt;!更准确地说,是它应用的 jpeg 压缩。所以阈值本身没有问题。只是一个被破坏的输出图像。不过,这令人困惑。保存此类图像(无伪影)的正确方法是,例如:Image&lt;TColor,TDepth&gt;.Bitmap.Save(your_path, ImageFormat.Bmp)

【讨论】:

    猜你喜欢
    • 2017-07-17
    • 2015-04-30
    • 2020-12-29
    • 2018-05-31
    • 2020-04-17
    • 1970-01-01
    • 2016-05-29
    • 2012-04-05
    • 2018-05-19
    相关资源
    最近更新 更多