2011-04-10 70 views
0

我正在使用AForge.net,我想在文本框中显示标准偏差的值。下面的代码是不工作:为什么ImageStatistics.Gray为空?

AForge.Imaging.ImageStatistics stat = new AForge.Imaging.ImageStatistics(btm_1); 
AForge.Math.Histogram gray = stat.Gray; 
this.textB_1.Text = gray.StdDev.ToString(); 

它失败,出现以下错误:

Object reference not set to an instance of an object.

两个graystat.Gray为空。

+1

这不是标准*分*。这是标准*偏差*。 – 2011-04-10 16:07:25

+0

对不起,我的错误 – kukula 2011-04-10 20:57:55

回答

1

您是否有灰度图像?

1

official documentationGray物业说:

Note:The property is valid only for grayscale images (see IsGrayscale property).

我猜,你的形象不是一个灰度图像,并Gray属性返回null。最好是抛出一个InvalidOperationException,因为它可以给出一些洞察错误的原因,并且它会快速失败。

+0

当然我有灰度图像。我用阈值对它进行二进制化,并且还使用Aforge的Canny边缘检测器。它工作正常,这就是为什么我很惊讶,我有直方图的问题。 – kukula 2011-04-10 21:04:15