五种基于RGB色彩空间统计的皮肤检测算法

简介: <p style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;">最近一直在研究多脸谱识别以及如何分辨多个皮肤区域是否是人脸的问题<br></p><p style="color: rgb(51, 51, 51); font-family: Arial; font-size: 1

最近一直在研究多脸谱识别以及如何分辨多个皮肤区域是否是人脸的问题

网上找了很多资料,看了很多篇文章,将其中基于RGB色彩空间识别皮肤

的统计算法做了一下总结,统计识别方法主要是简单相比与很多其它基于

机器学习的算法,本人总结了五种RGB色彩空间的统计算法源码如下:

Skin Filter1:

[java]  view plain copy
  1. public class SkinFilter1 extends AbstractBufferedImageOp {  
  2.   
  3.     @Override  
  4.     public BufferedImage filter(BufferedImage src, BufferedImage dest) {  
  5.         int width = src.getWidth();  
  6.         int height = src.getHeight();  
  7.   
  8.         if ( dest == null )  
  9.             dest = createCompatibleDestImage( src, null );  
  10.   
  11.         int[] inPixels = new int[width*height];  
  12.         int[] outPixels = new int[width*height];  
  13.         getRGB( src, 00, width, height, inPixels );  
  14.         int index = 0;  
  15.         for(int row=0; row<height; row++) {  
  16.             int ta = 0, tr = 0, tg = 0, tb = 0;  
  17.             for(int col=0; col<width; col++) {  
  18.                 index = row * width + col;  
  19.                 ta = (inPixels[index] >> 24) & 0xff;  
  20.                 tr = (inPixels[index] >> 16) & 0xff;  
  21.                 tg = (inPixels[index] >> 8) & 0xff;  
  22.                 tb = inPixels[index] & 0xff;  
  23.                   
  24.                 // detect skin method...  
  25.                 double sum = tr + tg + tb;  
  26.                 if (((double)tr/(double)tb > 1.185) &&   
  27.                     ((double)(tr*tb)/(double)(sum*sum)>0.107) &&  
  28.                     ((double)(tr*tg)/(double)(sum*sum)>0.112))  
  29.                 {  
  30.                     tr = tg = tb = 0// black - skin detected!!  
  31.                 } else {  
  32.                     tr = tg = tb = 255// white color means non-skin pixel  
  33.                 }  
  34.                 outPixels[index] = (ta << 24) | (tr << 16) | (tg << 8) | tb;  
  35.             }  
  36.         }  
  37.         setRGB( dest, 00, width, height, outPixels );  
  38.         return dest;  
  39.     }  
  40. }  
Skin Filter2:

[java]  view plain copy
  1. public class SkinFilter2 extends AbstractBufferedImageOp {  
  2.   
  3.     @Override  
  4.     public BufferedImage filter(BufferedImage src, BufferedImage dest) {  
  5.         int width = src.getWidth();  
  6.         int height = src.getHeight();  
  7.   
  8.         if ( dest == null )  
  9.             dest = createCompatibleDestImage( src, null );  
  10.   
  11.         int[] inPixels = new int[width*height];  
  12.         int[] outPixels = new int[width*height];  
  13.         getRGB( src, 00, width, height, inPixels );  
  14.         int index = 0;  
  15.         for(int row=0; row<height; row++) {  
  16.             int ta = 0, tr = 0, tg = 0, tb = 0;  
  17.             for(int col=0; col<width; col++) {  
  18.                 index = row * width + col;  
  19.                 ta = (inPixels[index] >> 24) & 0xff;  
  20.                 tr = (inPixels[index] >> 16) & 0xff;  
  21.                 tg = (inPixels[index] >> 8) & 0xff;  
  22.                 tb = inPixels[index] & 0xff;  
  23.                 double sum = tr + tg + tb;  
  24.                   
  25.                   
  26.                 if(((double)3*tb*tr*tr/(double)(sum*sum*sum)>0.1276)&&  
  27.                     ((double)(tr*tb+tg*tg)/(double)(tg*tb)>2.14)&&  
  28.                     ((double)(sum)/(double)(3*tr)+(double)(tr-tg)/(double)(sum)<2.7775))  
  29.                 {  
  30.                     tr = tg = tb = 0;  
  31.                 } else {  
  32.                     tr = tg = tb = 255;  
  33.                 }  
  34.                 outPixels[index] = (ta << 24) | (tr << 16) | (tg << 8) | tb;  
  35.             }  
  36.         }  
  37.         setRGB( dest, 00, width, height, outPixels );  
  38.         return dest;  
  39.     }  
  40. }  
Skin Filter3:

[java]  view plain copy
  1. public class SkinFilter3 extends AbstractBufferedImageOp {  
  2.   
  3.     @Override  
  4.     public BufferedImage filter(BufferedImage src, BufferedImage dest) {  
  5.         int width = src.getWidth();  
  6.         int height = src.getHeight();  
  7.   
  8.         if ( dest == null )  
  9.             dest = createCompatibleDestImage( src, null );  
  10.   
  11.         int[] inPixels = new int[width*height];  
  12.         int[] outPixels = new int[width*height];  
  13.         getRGB( src, 00, width, height, inPixels );  
  14.         int index = 0;  
  15.         for(int row=0; row<height; row++) {  
  16.             int ta = 0, tr = 0, tg = 0, tb = 0;  
  17.             for(int col=0; col<width; col++) {  
  18.                 index = row * width + col;  
  19.                 ta = (inPixels[index] >> 24) & 0xff;  
  20.                 tr = (inPixels[index] >> 16) & 0xff;  
  21.                 tg = (inPixels[index] >> 8) & 0xff;  
  22.                 tb = inPixels[index] & 0xff;  
  23.                   
  24.                 // detect skin method...  
  25.                 double sum = tr + tg + tb;  
  26.                 if (((double)tg / (double)tg - (double)tr / (double)tb <= -0.0905) &&  
  27.                     ((double)(sum) / (double)(3 * tr) + (double)(tr - tg) / (double)(sum) <= 0.9498))  
  28.                 {  
  29.                     tr = tg = tb = 0;  
  30.                 } else {  
  31.                     tr = tg = tb = 255;  
  32.                 }  
  33.                 outPixels[index] = (ta << 24) | (tr << 16) | (tg << 8) | tb;  
  34.             }  
  35.         }  
  36.         setRGB( dest, 00, width, height, outPixels );  
  37.         return dest;  
  38.     }  
  39. }  
Skin Filter4:

[java]  view plain copy
  1. import java.awt.image.BufferedImage;  
  2. /** 
  3.  * this skin detection is absolutely good skin classification, 
  4.  * i love this one very much 
  5.  *  
  6.  * this one should be always primary skin detection  
  7.  * from all five filters 
  8.  *  
  9.  * @author zhigang 
  10.  * 
  11.  */  
  12. public class SkinFilter4 extends AbstractBufferedImageOp {  
  13.   
  14.     @Override  
  15.     public BufferedImage filter(BufferedImage src, BufferedImage dest) {  
  16.         int width = src.getWidth();  
  17.         int height = src.getHeight();  
  18.   
  19.         if ( dest == null )  
  20.             dest = createCompatibleDestImage( src, null );  
  21.   
  22.         int[] inPixels = new int[width*height];  
  23.         int[] outPixels = new int[width*height];  
  24.         getRGB( src, 00, width, height, inPixels );  
  25.         int index = 0;  
  26.         for(int row=0; row<height; row++) {  
  27.             int ta = 0, tr = 0, tg = 0, tb = 0;  
  28.             for(int col=0; col<width; col++) {  
  29.                 index = row * width + col;  
  30.                 ta = (inPixels[index] >> 24) & 0xff;  
  31.                 tr = (inPixels[index] >> 16) & 0xff;  
  32.                 tg = (inPixels[index] >> 8) & 0xff;  
  33.                 tb = inPixels[index] & 0xff;  
  34.                   
  35.                 // detect skin method...  
  36.                 double sum = tr + tg + tb;  
  37.                 if (((double)tb/(double)tg<1.249) &&  
  38.                     ((double)sum/(double)(3*tr)>0.696) &&  
  39.                     (0.3333-(double)tb/(double)sum>0.014) &&  
  40.                     ((double)tg/(double)(3*sum)<0.108))  
  41.                 {  
  42.                     tr = tg = tb = 0;  
  43.                 } else {  
  44.                     tr = tg = tb = 255;  
  45.                 }  
  46.                 outPixels[index] = (ta << 24) | (tr << 16) | (tg << 8) | tb;  
  47.             }  
  48.         }  
  49.         setRGB(dest, 00, width, height, outPixels);  
  50.         return dest;  
  51.     }  
  52. }  
Skin Filter5:

[java]  view plain copy
  1. import java.awt.image.BufferedImage;  
  2. /** 
  3.  * this is very good skin detection 
  4.  * get real skin segmentation correctly.... 
  5.  * ohh... cool 
  6.  *  
  7.  * @author zhigang 
  8.  * 
  9.  */  
  10. public class SkinFilter5 extends AbstractBufferedImageOp {  
  11.   
  12.     @Override  
  13.     public BufferedImage filter(BufferedImage src, BufferedImage dest) {  
  14.         int width = src.getWidth();  
  15.         int height = src.getHeight();  
  16.   
  17.         if ( dest == null )  
  18.             dest = createCompatibleDestImage( src, null );  
  19.   
  20.         int[] inPixels = new int[width*height];  
  21.         int[] outPixels = new int[width*height];  
  22.         getRGB( src, 00, width, height, inPixels );  
  23.         int index = 0;  
  24.         for(int row=0; row<height; row++) {  
  25.             int ta = 0, tr = 0, tg = 0, tb = 0;  
  26.             for(int col=0; col<width; col++) {  
  27.                 index = row * width + col;  
  28.                 ta = (inPixels[index] >> 24) & 0xff;  
  29.                 tr = (inPixels[index] >> 16) & 0xff;  
  30.                 tg = (inPixels[index] >> 8) & 0xff;  
  31.                 tb = inPixels[index] & 0xff;  
  32.                   
  33.                 // detect skin method...  
  34.                 double sum = tr + tg + tb;  
  35.                 if (((double)tg/(double)tb - (double)tr/(double)tg<=-0.0905)&&  
  36.                 ((double)(tg*sum)/(double)(tb*(tr-tg))>3.4857)&&  
  37.                 ((double)(sum*sum*sum)/(double)(3*tg*tr*tr)<=7.397)&&  
  38.                 ((double)sum/(double)(9*tr)-0.333 > -0.0976))  
  39.                 {  
  40.                     tr = tg = tb = 0;  
  41.                 } else {  
  42.                     tr = tg = tb = 255;  
  43.                 }  
  44.                 outPixels[index] = (ta << 24) | (tr << 16) | (tg << 8) | tb;  
  45.             }  
  46.         }  
  47.         setRGB( dest, 00, width, height, outPixels );  
  48.         return dest;  
  49.     }  
  50. }  
总结一下:

似乎Filter3的效果与Filter1的效果不是很好,Filter5, Filter4的效果感觉

还是很好的,基本上可以符合实际要求。

相关文章
|
2月前
|
监控 安全 算法
137_安全强化:输入过滤与水印 - 实现输出水印的检测算法与LLM安全防护最佳实践
随着大语言模型(LLM)在各行业的广泛应用,安全问题日益凸显。从提示注入攻击到恶意输出生成,从知识产权保护到内容溯源,LLM安全已成为部署和应用过程中不可忽视的关键环节。在2025年的LLM技术生态中,输入过滤和输出水印已成为两大核心安全技术,它们共同构建了LLM服务的安全防护体系。
|
3月前
|
传感器 资源调度 算法
DDMA-MIMO雷达多子带相干累积目标检测算法——论文阅读
本文提出一种多子带相干累积(MSCA)算法,通过引入空带和子带相干处理,解决DDMA-MIMO雷达的多普勒模糊与能量分散问题。该方法在低信噪比下显著提升检测性能,实测验证可有效恢复目标速度,适用于车载雷达高精度感知。
533 4
DDMA-MIMO雷达多子带相干累积目标检测算法——论文阅读
|
2月前
|
开发框架 算法 .NET
基于ADMM无穷范数检测算法的MIMO通信系统信号检测MATLAB仿真,对比ML,MMSE,ZF以及LAMA
简介:本文介绍基于ADMM的MIMO信号检测算法,结合无穷范数优化与交替方向乘子法,降低计算复杂度并提升检测性能。涵盖MATLAB 2024b实现效果图、核心代码及详细注释,并对比ML、MMSE、ZF、OCD_MMSE与LAMA等算法。重点分析LAMA基于消息传递的低复杂度优势,适用于大规模MIMO系统,为通信系统检测提供理论支持与实践方案。(238字)
|
6月前
|
机器学习/深度学习 运维 监控
实时异常检测实战:Flink+PAI 算法模型服务化架构设计
本文深入探讨了基于 Apache Flink 与阿里云 PAI 构建的实时异常检测系统。内容涵盖技术演进、架构设计、核心模块实现及金融、工业等多领域实战案例,解析流处理、模型服务化、状态管理等关键技术,并提供性能优化与高可用方案,助力企业打造高效智能的实时异常检测平台。
494 1
|
10月前
|
机器学习/深度学习 算法 数据安全/隐私保护
基于GRU网络的MQAM调制信号检测算法matlab仿真,对比LSTM
本研究基于MATLAB 2022a,使用GRU网络对QAM调制信号进行检测。QAM是一种高效调制技术,广泛应用于现代通信系统。传统方法在复杂环境下性能下降,而GRU通过门控机制有效提取时间序列特征,实现16QAM、32QAM、64QAM、128QAM的准确检测。仿真结果显示,GRU在低SNR下表现优异,且训练速度快,参数少。核心程序包括模型预测、误检率和漏检率计算,并绘制准确率图。
298 65
基于GRU网络的MQAM调制信号检测算法matlab仿真,对比LSTM
|
5月前
|
存储 监控 算法
基于跳表数据结构的企业局域网监控异常连接实时检测 C++ 算法研究
跳表(Skip List)是一种基于概率的数据结构,适用于企业局域网监控中海量连接记录的高效处理。其通过多层索引机制实现快速查找、插入和删除操作,时间复杂度为 $O(\log n)$,优于链表和平衡树。跳表在异常连接识别、黑名单管理和历史记录溯源等场景中表现出色,具备实现简单、支持范围查询等优势,是企业网络监控中动态数据管理的理想选择。
175 0
|
6月前
|
机器学习/深度学习 监控 算法
面向办公室屏幕监控系统的改进型四叉树屏幕变化检测算法研究
本文提出一种改进型四叉树数据结构模型,用于优化办公室屏幕监控系统。通过动态阈值调节、变化优先级索引及增量更新策略,显著降低计算复杂度并提升实时响应能力。实验表明,该算法在典型企业环境中将屏幕变化检测效率提升40%以上,同时减少资源消耗。其应用场景涵盖安全审计、工作效能分析及远程协作优化等,未来可结合深度学习实现更智能化的功能。
126 0
|
9月前
|
存储 监控 算法
基于 PHP 语言的滑动窗口频率统计算法在公司局域网监控电脑日志分析中的应用研究
在当代企业网络架构中,公司局域网监控电脑系统需实时处理海量终端设备产生的连接日志。每台设备平均每分钟生成 3 至 5 条网络请求记录,这对监控系统的数据处理能力提出了极高要求。传统关系型数据库在应对这种高频写入场景时,性能往往难以令人满意。故而,引入特定的内存数据结构与优化算法成为必然选择。
252 3
|
9月前
|
机器学习/深度学习 存储 算法
基于MobileNet深度学习网络的活体人脸识别检测算法matlab仿真
本内容主要介绍一种基于MobileNet深度学习网络的活体人脸识别检测技术及MQAM调制类型识别方法。完整程序运行效果无水印,需使用Matlab2022a版本。核心代码包含详细中文注释与操作视频。理论概述中提到,传统人脸识别易受非活体攻击影响,而MobileNet通过轻量化的深度可分离卷积结构,在保证准确性的同时提升检测效率。活体人脸与非活体在纹理和光照上存在显著差异,MobileNet可有效提取人脸高级特征,为无线通信领域提供先进的调制类型识别方案。
|
9月前
|
JavaScript 算法 前端开发
JS数组操作方法全景图,全网最全构建完整知识网络!js数组操作方法全集(实现筛选转换、随机排序洗牌算法、复杂数据处理统计等情景详解,附大量源码和易错点解析)
这些方法提供了对数组的全面操作,包括搜索、遍历、转换和聚合等。通过分为原地操作方法、非原地操作方法和其他方法便于您理解和记忆,并熟悉他们各自的使用方法与使用范围。详细的案例与进阶使用,方便您理解数组操作的底层原理。链式调用的几个案例,让您玩转数组操作。 只有锻炼思维才能可持续地解决问题,只有思维才是真正值得学习和分享的核心要素。如果这篇博客能给您带来一点帮助,麻烦您点个赞支持一下,还可以收藏起来以备不时之需,有疑问和错误欢迎在评论区指出~

热门文章

最新文章