一、項目命名 SCADA:數據採集與監控系統 SCADA(Supervisory Control And Data Acquisition),即數據採集與監視控制系統。 SCADA.Common SCADA.Main SCADA.UI SCADA.Communication SCADA.HMI SC ...
出差摸魚做的一個用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 }