C# 为什么ImageStatistics.Gray为空?
我正在使用一个org.net,我想在一个文本框中显示标准偏差的值。以下代码不起作用:C# 为什么ImageStatistics.Gray为空?,c#,null,histogram,aforge,C#,Null,Histogram,Aforge,我正在使用一个org.net,我想在一个文本框中显示标准偏差的值。以下代码不起作用: AForge.Imaging.ImageStatistics stat = new AForge.Imaging.ImageStatistics(btm_1); AForge.Math.Histogram gray = stat.Gray; this.textB_1.Text = gray.StdDev.ToString(); 它失败,出现以下错误: 对象引用未设置为对象的实例 gray和stat.gray都
AForge.Imaging.ImageStatistics stat = new AForge.Imaging.ImageStatistics(btm_1);
AForge.Math.Histogram gray = stat.Gray;
this.textB_1.Text = gray.StdDev.ToString();
它失败,出现以下错误:
对象引用未设置为对象的实例
gray
和stat.gray
都为空。您有灰度图像吗?gray属性的属性显示:
注意:该属性仅对灰度图像有效(请参见属性)
我猜您的图像不是灰度图像,
Gray
属性返回null。它最好抛出一个invalidoOperationException
,因为它可以让您深入了解错误的原因,并且会很快失败。这不是标准的划分。这是标准差。我肯定有灰度图像。我用阈值对它进行二值化,我还使用了一个RGE的Canny边缘检测器。它工作得很好,这就是为什么我惊讶于我有直方图的问题。