有一个识别图像上红色区域的任务,它需要最大的准确性。但是源图像的质量很差。我正在尝试使用 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.
最佳答案
在应用任何类型的阈值后,在保存的图像上出现灰色伪影的原因是... *.JPG Image<TColor, TDepth>
的标准保存格式| !更准确地说,它应用了 jpeg 压缩。所以阈值本身没有问题。只是一个损坏的输出图像。虽然这很令人困惑。保存此类图像(无伪影)的正确方法是,例如:Image<TColor,TDepth>.Bitmap.Save(your_path, ImageFormat.Bmp)
关于C# EmguCV/OpenCV "cvThreshold"异常行为 - 没有预期的阈值结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11851832/