opencvsharp踩坑DAY1--图像增强emphasize
作者:互联网
cheche出差摸鱼做的一个用opencvsharp的东西,用于快速验证,水平极差,目前功能如下
今天搞的功能是复现halcon的图像增强算子emphasize,根据文档其运作过程为
1.输入均值(低通)滤波矩阵size,输入Factor,原图灰度集in
2.滤波in得图像m
3.然后out=round((in- m) * Factor)+in
效果如下
它的增强原理是让滤波前后灰度的差值来判断灰度变化区域,假如区域内滤波变换平缓那(in- m)的绝对值会相对较小在乘以系数factor之后对原有的区域影响不大,但是在变化剧烈的区域内则会因为(in- m)对值会相对较大在乘以系数factor之后对原有的区域影响较大,而变化区域剧烈则往往体现于图形的边缘和角落,使得图像边缘和角落更为明显。
用opencvsharp实现如下
1 private void emphasize() 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( (dealing_object.Get<byte>(i, j)- 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 28 29 }
标签:Mat,--,dealing,object,Cv2,int,emphasize,factor,图像增强 来源: https://www.cnblogs.com/shtnm/p/16630165.html