五种基于RGB色彩空间统计的皮肤检测算法
最近一直在研究多脸谱识别以及如何分辨多个皮肤区域是否是人脸的问题
网上找了很多资料,看了很多篇文章,将其中基于RGB色彩空间识别皮肤
的统计算法做了一下总结,统计识别方法主要是简单相比与很多其它基于
机器学习的算法,本人总结了五种RGB色彩空间的统计算法源码如下:
Skin Filter1:
- public class SkinFilter1 extends AbstractBufferedImageOp {
- @Override
- public BufferedImage filter(BufferedImage src, BufferedImage dest) {
- int width = src.getWidth();
- int height = src.getHeight();
- if ( dest == null )
- dest = createCompatibleDestImage( src, null );
- int[] inPixels = new int[width*height];
- int[] outPixels = new int[width*height];
- getRGB( src, 0, 0, width, height, inPixels );
- int index = 0;
- for(int row=0; row<height; row++) {
- int ta = 0, tr = 0, tg = 0, tb = 0;
- for(int col=0; col<width; col++) {
- index = row * width + col;
- ta = (inPixels[index] >> 24) & 0xff;
- tr = (inPixels[index] >> 16) & 0xff;
- tg = (inPixels[index] >> 8) & 0xff;
- tb = inPixels[index] & 0xff;
- // detect skin method...
- double sum = tr + tg + tb;
- if (((double)tr/(double)tb > 1.185) &&
- ((double)(tr*tb)/(double)(sum*sum)>0.107) &&
- ((double)(tr*tg)/(double)(sum*sum)>0.112))
- {
- tr = tg = tb = 0; // black - skin detected!!
- } else {
- tr = tg = tb = 255; // white color means non-skin pixel
- }
- outPixels[index] = (ta << 24) | (tr << 16) | (tg << 8) | tb;
- }
- }
- setRGB( dest, 0, 0, width, height, outPixels );
- return dest;
- }
- }
, 0, width, height, inPixels );
, 0, width, height, inPixels );
, 0, width, height, inPixels );