五种基于RGB色彩空间统计的皮肤检测算法 分类: 视频图像处理 ...

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

网上找了很多资料,看了很多篇文章,将其中基于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的效果感觉

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

版权声明:本文为博主原创文章,未经博主允许不得转载。

转载于:https://www.cnblogs.com/mao0504/p/4705516.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值