学习图像处理知识---EmguCV3.4图像--阈值处理

在图像处理,二值化图像很重要的,尤其在机器视觉中,找MARK,找零件中心点,必须使用,减少数据处理量。

1.CvInvoke 类中

public static double Threshold(
	IInputArray src,//输入必须为单通道图像
	IOutputArray dst,//输出图像
	double threshold,//阀值
	double maxValue,//最大值
	ThresholdType thresholdType//阀值变换的类型。
)

变换的类型,不同图像转换后不同:

2.自适应阈值

public static void AdaptiveThreshold(
	IInputArray src,//输入必须为单通道图像
	IOutputArray dst,//输出同输入尺寸单通道图片
	double maxValue,//最大值
	AdaptiveThresholdType adaptiveType,//自适应阈值的类型
	ThresholdType thresholdType,//阀值变换的类型,同上
	int blockSize,//像数领域大小,如果为3就是3*3区域
	double param1 )//均值或高斯加权平均值所需要减去的一个常数,相当干预值

实例练习:

         Emgu.CV.Image<Bgr, Byte> YUAN = new Image<Bgr, Byte>((Bitmap)pictureBox1.Image);
            Mat a1 = YUAN.Convert<Gray, Byte>().Mat;//变成灰图
            Mat a2 = new Mat(a1.Size, Emgu.CV.CvEnum.DepthType.Cv8U, 1);//定义跟a1一致的图像
            CvInvoke.Threshold(a1, a2, (double)numericUpDown1.Value, 255, Emgu.CV.CvEnum.ThresholdType.Binary);
            pictureBox2.Image = a2.Bitmap;





CvInvoke.AdaptiveThreshold(a1,a2,255,Emgu.CV.CvEnum.AdaptiveThresholdType.MeanC,Emgu.CV.CvEnum.ThresholdType.Binary, 3, (double)numericUpDown1.Value);


 
 
 
 
 
 
 

猜你喜欢

转载自blog.csdn.net/tuto7534/article/details/80286320