Win8 Metro(C#)数字图像处理--2.35图像肤色检测算法
生活随笔
收集整理的這篇文章主要介紹了
Win8 Metro(C#)数字图像处理--2.35图像肤色检测算法
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
原文:Win8 Metro(C#)數字圖像處理--2.35圖像膚色檢測算法
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎
[函數名稱]
膚色檢測函數SkinDetectProcess(WriteableBitmap?src)
[算法說明]
??這個算法是一篇學術論文算法的實現,論文名字為“基于韌臉檢測和顏色分析的紅眼自動消除”(作者金秋明,王朔中),主要是采集并統計膚色像素,得到膚色像素在RGB顏色空間中的分布范圍,以此作為像素是否為膚色像素的判斷標準及約束條件。具體內容大家可以在網絡中搜索,由統計結果得到的膚色范圍如下公式2-(45),2-(46)所示:
<strong><span style="font-size:14px;">[函數代碼]</span></strong>/// <summary>/// Skin detection./// </summary>/// <param name="src">The source image.</param>/// <returns></returns>public static WriteableBitmap SkinDetectProcess(WriteableBitmap src)36膚色檢測 {if (src != null){int w = src.PixelWidth;int h = src.PixelHeight;WriteableBitmap srcImage = new WriteableBitmap(w, h);byte[] temp = src.PixelBuffer.ToArray();byte[] tempMask = (byte[])temp.Clone();int R, G, B, S;double r, g, b;for (int i = 0; i < temp.Length; i += 4){B = tempMask[i];G = tempMask[i + 1];R = tempMask[i + 2];S = R + G + B;r = (double)R / (double)(R + G + B + 1.0);g = (double)G / (double)(R + G + B + 1.0);b = (double)B / (double)(R + G + B + 1.0);if (S != 0){if ((r > (double)(95.0 / (double)S)) && (r < 1 - (double)(90.0 / (double)S)) && (g > (double)(50.0 / (double)S)) && ((r - g) > (double)(30.0 / (double)S)) && (r - g < 0.2)){temp[i] = (byte)B;temp[i+1] = (byte)G;temp[i+2] = (byte)R;}else{temp[i] = 0;temp[i + 1] = 0;temp[i + 2] = 0;}}else{temp[i] = 0;temp[i + 1] = 0;temp[i + 2] = 0;}}Stream sTemp = srcImage.PixelBuffer.AsStream();sTemp.Seek(0, SeekOrigin.Begin);sTemp.Write(temp, 0, w * 4 * h);return srcImage;}else{return null;}}
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎
總結
以上是生活随笔為你收集整理的Win8 Metro(C#)数字图像处理--2.35图像肤色检测算法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 确保企业的大数据投资达到预期的5种方法
- 下一篇: 特斯拉对手再秀“肌肉”,Lucid Mo