zoukankan      html  css  js  c++  java
  • 五种基于RGB色彩空间统计的皮肤检测算法 分类: 视频图像处理 2015-07-24 10:18 48人阅读 评论(0) 收藏

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

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

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

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

    Skin Filter1:

    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:

    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:

    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:

    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:

    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的效果感觉

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

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

  • 相关阅读:
    优云蒋君伟:自动化运维成本仍然很高
    广通软件携手华为,联合发布远程运维服务:开启智能运维模式
    优云软件叶帅:“互联网+”时代的云数据中心运维思辨(下)
    关于对象转json字符串存在Date类型转换格式问题解决方案
    JAVA过滤emoji表情包
    Java关于list集合根据集合元素对象的某个或多个属性进行排序的工具类
    Linux下备份mysql数据库以及mongodb
    Linux系统备份Tomcat下的项目
    Java关于计算某年某月有多少天的问题
    有关Java POI导出excel表格中,单元格合并之后显示不全的解决方法。
  • 原文地址:https://www.cnblogs.com/mao0504/p/4705516.html
Copyright © 2011-2022 走看看