出差摸鱼做的一个用opencvsharp的东西,用于快速验证,水平极差,目前功能如下
今天搞的功能是复现halcon的图像增强算子illuminate,根据文档其运作过程为
1.输入均值(低通)滤波矩阵size,输入Factor,原图灰度集in
2.滤波in得图像m
3.然后out= round ( (val - m) * Factor + in )
4.其中val在halcon帮助中描述为For byte-images val equals 127, for int2-images and uint2-images val equals the median value. 而这个byte-images、int2-images、uint2-images区分则是其图像类型,参考大佬http://www.skcircle.com/?id=1547,在opencvsharp中则分别对应了遍历图像Mat.Get<byte>(x, y)、Mat.Get<int>(x, y)、Mat.Get<uint>(x, y)的值,而127也是0-255的中只所以选择该数值作为val。在本文中用到的图像类型默认是byte-images。
5.其中Factor与滤波器尺寸成正相关关系halcon说明中30x30到200x200的范围有以下几种组合
Height Width Factor
---------------------
40 40 0.55
100 100 0.7
150 150 0.8
6.综合上文,得知在低通滤波后图像将灰度中值比较,将其间差乘以因子Factor再加上原灰度值。让局部的灰度向灰度中值靠拢以达到增强图像的高频区域(边缘和拐角),使图像看起来更清晰的效果。原文:Very dark parts of the image are “illuminated” more strongly, very light ones are “darkened”.
halcon效果如图
opencvsharp实现效果如下
1 private void illuminate() 2 { 3 int w, h; 4 double factor; 5 Cv2.CvtColor(dealing_object, dealing_object, ColorConversionCodes.BGR2GRAY); 6 Mat mean = new Mat(); 7 w = int.Parse(InputBox("滤波器宽", "", "")); 8 h = int.Parse(InputBox("滤波器高", "", "")); 9 factor = double.Parse(InputBox("系数", "", "")); 10 Cv2.Blur(dealing_object, mean, new OpenCvSharp.Size(w, h)); 11 12 Mat output = new Mat(dealing_object.Size(), dealing_object.Type()); 13 for (int i = 0; i < dealing_object.Height; i++) 14 { 15 for (int j = 0; j < dealing_object.Width; j++) 16 { 17 int v = (int)Math.Round((172- mean.Get<byte>(i, j)) * factor) + dealing_object.Get<byte>(i, j); 18 v = v > 255 ? 255 : v; 19 v = v < 0 ? 0 : v; 20 output.Set(i, j, v); 21 22 } 23 } 24 Cv2.ImShow("in", dealing_object); 25 Cv2.ImShow("out", output); 26 27 }
标签:illuminate,Mat,--,dealing,object,int,灰度,images,图像增强 From: https://www.cnblogs.com/shtnm/p/16635288.html